Sei sulla pagina 1di 6

BLL

using Intepro.DataAccess;
using System.Data;
using System.Data.SqlClient;

declaration (prop)

public void Add()


{
dl.Open();
dl.SetSql("INSERT INTO __ VALUES()");
dl.AddParam();
dl.Execute();
dl.Close();
}

public List<BLL> FastList()


{
List<BLL> list = new List<BLL>();
dl.Open();
dl.SetSql("SELECT * FROM __");
SqlDataReader dr = dl.GetReader();
while(dr.Read() == true)
{
BLL b = new BLL();
b.ID = (long)dr[0]
b.Lastname = dr[1].ToString();

List.Add(b);
}
dr.Close();
dl.Close();
Return List;
}
Controller

using Intepro.BusinessLogic;
using System.Data.SqlClient;

public ActionResult Index()


{
return view("LandingPage");
}

public ActionResult Register();


{
return view("Register");
}

[HttpPost]
public ActionResult AddNew(FormCollection form)
{
BLL bll = new BLL();
bll.ID = long.Parse(form["ID"]);
bll.Lastname = form("Lastname");
bll.Add();

return RedirectToAction("Index");
}

public ActionResult List()


{
BLL bll = new BLL();
return View(b.FastList);
}
LandingPage

<div>
<h2>Web-App</h2>
<hr />
Don't have a record yet? Register
<a href="~/Participant/Register">
here
</a>
<br />
List of records
<a href="~/Participant/List">click here</a>
</div>
List

<div>
<table>
<thead>
<tr>
<th>Participant I.D.</th>
<th>Surname</th>
<th>Given Name</th>
</tr>
</thead>
<tbody>
@{
@*for (int i = 0; i < Model.Count(); i++)
{
<tr>
<td>@Model[i].ID</td>
<td>@Model[i].Lastname</td>
<td>@Model[i].Firstname</td>
</tr>
}*@
foreach (Intepro.BusinessLogic.ParticipantBLL p in Model)
{
<tr>
<td>@p.ID</td>
<td>@p.Lastname</td>
<td>@p.Firstname</td>
</tr>
}
}
</tbody>
</table>
</div>
Register

<div>
<h2>Participant Registration</h2>
<hr />
<form action="~/Participant/AddNew" method="post">
I.D. No.
<input type="number" name="ID" value="" />
<br />
Last name
<input type="text" name="Lastname" value="" />
<br />
First name
<input type="text" name="Firstname" value="" />
<br />
<button type="submit">
Register
</button>
</form>
<a href="~/Participant/DefaultAction">Go Back</a>
</div>
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Participant", action = "Index", id =
UrlParameter.Optional }
);
}

Potrebbero piacerti anche