// This is the Select methd to selects a single Cliente item with the id // USAGE: <asp:FormView SelectMethod="GetItem"> public CRUD_CLIENTE.Models.Cliente GetItem([FriendlyUrlSegmentsAttribute(0)]int? Codigo) { if (Codigo == null) { return null; } using (var context = new CRUD_CLIENTEContext()) { return context.Cliente.Find(Codigo); } }
// This is the Delete methd to delete the selected Cliente item // USAGE: <asp:FormView DeleteMethod="DeleteItem"> public void DeleteItem(int Codigo) { using (var context = new CRUD_CLIENTEContext()) { var item = context.Cliente.Find(Codigo); if (item != null) { context.Cliente.Remove(item); context.SaveChanges(); } } Response.Redirect("../Default"); }
// This is the Insert method to insert the entered Cliente item // USAGE: <asp:FormView InsertMethod="InsertItem"> public void InsertItem() { using (var context = new CRUD_CLIENTEContext()) { var item = new Cliente(); TryUpdateModel(item); if (ModelState.IsValid) { // Save changes context.Cliente.Add(item); context.SaveChanges(); Response.Redirect("Default"); } } }
// This is the Update methd to update the selected Cliente item // USAGE: <asp:FormView UpdateMethod="UpdateItem"> public void UpdateItem(int Codigo) { using (var context = new CRUD_CLIENTEContext()) { var item = context.Cliente.Find(Codigo); if (item == null) { // The item wasn't found ModelState.AddModelError("", String.Format("Item with id {0} was not found", Codigo)); return; } TryUpdateModel(item); if (ModelState.IsValid) { // Save changes here context.SaveChanges(); Response.Redirect("../Default"); } } }
// Model binding method to get List of Cliente entries // USAGE: <asp:ListView SelectMethod="GetData"> public IQueryable<Cliente> GetData() { var context = new CRUD_CLIENTEContext(); return context.Cliente; }