public void addPersonForm_InsertItem() { var item = new PhysPerson(); TryUpdateModel(item); if (ModelState.IsValid) { using (ContragentContext db = new ContragentContext()) { item.CreateDate = new DateTimeOffset(DateTime.Now); db.PhysPeople.Add(item); db.SaveChanges(); } } }
public void delete_phys_person([QueryString("physPersonId")] int physPersonId) { using (ContragentContext db = new ContragentContext()) { var item = new PhysPerson { ID = physPersonId }; db.Entry(item).State = EntityState.Deleted; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { ModelState.AddModelError("", String.Format("Item with id {0} no longer exists in the database.", physPersonId)); } } }
public void physpeople_UpdateItem([QueryString("physPersonID")] int personID) { using (ContragentContext db = new ContragentContext()) { PhysPerson item = null; item = db.PhysPeople.Find(personID); if (item == null) { ModelState.AddModelError("", String.Format("Item with id {0} was not found", personID)); return; } item.UpdateDate = new DateTimeOffset(DateTime.Now); TryUpdateModel(item); if (ModelState.IsValid) { db.SaveChanges(); } } Response.Redirect("~/PeopleList"); }