public virtual void Delete(TEntity entityToDelete) { if (context.Entry(entityToDelete).State == EntityState.Detached) { dbSet.Attach(entityToDelete); } dbSet.Remove(entityToDelete); }
public ActionResult UpdateSave(Contact contact) { using (PhoneBookContext db = new PhoneBookContext()) { db.Contacts.Attach(contact); db.Entry(contact) .Property(c => c.PhoneNumber).IsModified = true; db.Entry(contact) .Property(c => c.Name).IsModified = true; db.SaveChanges(); } return(Redirect("/Dist/Index")); }
public IHttpActionResult PutPerson([FromUri] int id, [FromBody] Person person) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != person.Id) { return(BadRequest()); } db.Entry(person).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!PersonExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public async Task <TEntity> Update(TEntity entity) { PhoneBookContext.Entry(entity).State = EntityState.Modified; await PhoneBookContext.SaveChangesAsync(); return(entity); }
public async Task <IHttpActionResult> PutPeople(int id, People people) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != people.ID) { return(BadRequest()); } db.Entry(people).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PeopleExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public async Task <IActionResult> PutUser(int id, User user) { if (id != user.Id) { return(BadRequest()); } _context.Entry(user).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!UserExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <ActionResult <Contact> > Put(int id, [FromBody] Contact contact) { if (!ModelState.IsValid) { return(BadRequest()); } if (id != contact.ContactId) { return(BadRequest()); } _context.Entry(contact).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ContactExists(id)) { return(NotFound()); } else { throw; } } return(Ok(contact)); }
public bool Update(Person person) { try { var obj = GetOneById(person.Id); obj.FirstName = person.FirstName; obj.LastName = person.LastName; obj.Phone = person.Phone; obj.Email = person.Email; obj.Updated = DateTime.Now; _phoneBookContext.Entry(obj).State = Microsoft.EntityFrameworkCore.EntityState.Modified; _phoneBookContext.SaveChanges(); return(true); } catch (Exception ex) { return(false); } }
public void Add(Person person) { using (PhoneBookContext context = new PhoneBookContext()) { var addedObject = context.Entry(person); addedObject.State = EntityState.Added; context.SaveChanges(); } }
public void Delete(Person person) { using (PhoneBookContext context = new PhoneBookContext()) { var deletedObject = context.Entry(person); deletedObject.State = EntityState.Deleted; context.SaveChanges(); } }
public void Update(Person person) { using (PhoneBookContext context = new PhoneBookContext()) { var updatedObject = context.Entry(person); updatedObject.State = EntityState.Modified; context.SaveChanges(); } }
public ActionResult Edit([Bind(Include = "ContactID,FirstName,LastName,Address,Email")] Contact contact) { if (ModelState.IsValid) { db.Entry(contact).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(contact)); }
public ActionResult Edit([Bind(Include = "CuntryId,CountryName,IsActive")] Country country) { if (ModelState.IsValid) { db.Entry(country).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(country)); }
public ActionResult Edit([Bind(Include = "ID,FirstName,LastName,PhoneNumber,Email,AddressOne,AddressTwo,PinCode,IsActive,CountryId,StateId,CityId")] People people) { if (ModelState.IsValid) { db.Entry(people).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(people)); }
public ActionResult Edit([Bind(Include = "CityId,CityName,IsActive,StateId")] City city) { if (ModelState.IsValid) { db.Entry(city).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.StateId = new SelectList(db.States, "StateId", "StateName", city.StateId); return(View(city)); }
public ActionResult Edit([Bind(Include = "StateId,StateName,IsActive,CountryId")] State state) { if (ModelState.IsValid) { db.Entry(state).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.CountryId = new SelectList(db.Countries, "CountryId", "CountryName", state.CountryId); return(View(state)); }
public ActionResult Edit([Bind(Include = "PhoneNumberID,ContactID,PhoneTypeID,Number")] PhoneNumber phoneNumber) { if (ModelState.IsValid) { db.Entry(phoneNumber).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.ContactID = new SelectList(db.Contacts, "ContactID", "FullName", phoneNumber.ContactID); ViewBag.PhoneTypeID = new SelectList(db.PhoneTypes, "PhoneTypeID", "Type", phoneNumber.PhoneTypeID); return(View(phoneNumber)); }
public void UpdateContact(Contact contactForUpdate) { var currentContact = _context.Contacts .Where(c => c.ContactId == contactForUpdate.ContactId) .Include(c => c.ContactPhones) .AsNoTracking() .SingleOrDefault(); _context.Entry(contactForUpdate).State = EntityState.Modified; foreach (var contactPhone in contactForUpdate.ContactPhones) { bool contactPhoneExists = currentContact.ContactPhones.Any(c => c.ContactPhoneId == contactPhone.ContactPhoneId); if (!contactPhoneExists) { return; } _context.Entry(contactPhone).State = EntityState.Modified; } }
public ActionResult Edit([Bind(Include = "ID,FirstName,LastName,PhoneNumber,Email,AddressOne,AddressTwo,PinCode,IsActive,CountryId,StateId,CityId")] People people) { if (ModelState.IsValid) { db.Entry(people).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.CityId = new SelectList(db.Cities, "CityId", "CityName", people.CityId); ViewBag.CountryId = new SelectList(db.Countries, "CountryId", "CountryName", people.CountryId); ViewBag.StateId = new SelectList(db.States, "StateId", "StateName", people.StateId); return(View(people)); }
public void Update(PhoneNumber item) { phoneNumber = GetById(item.Id); if (phoneNumber != null) { phoneNumber.Number = item.Number; } else { throw new ArgumentNullException("Please choose phone number to update"); } using (var context = new PhoneBookContext()) { context.PhoneNumbers.Attach(phoneNumber); context.Entry(phoneNumber).State = EntityState.Modified; context.SaveChanges(); } }
public void Update(Contact item) { contact = GetById(item.Id); if (contact != null) { contact.Firstname = item.Firstname; contact.LastName = item.LastName; } else { throw new ArgumentNullException("Please choose contact to update"); } using (var context = new PhoneBookContext()) { context.Contacts.Attach(contact); context.Entry(contact).State = EntityState.Modified; context.SaveChanges(); } }
public void Update(User item) { user = GetById(item.Id); if (user != null) { user.UserName = item.UserName; user.Password = item.Password; user.FirstName = item.FirstName; user.LastName = item.LastName; } else { throw new ArgumentNullException("Please choose user to update"); } using (var context = new PhoneBookContext()) { context.Users.Attach(user); context.Entry(user).State = EntityState.Modified; context.SaveChanges(); } }