// GET: PersonViewModel/Delete/5 public ActionResult Delete(int id) { PhoneBookDbEntities db = new PhoneBookDbEntities(); var contacts = db.Contacts.Where(x => x.PersonId == id); foreach (var i in contacts) { Contact c = new Contact() { ContactId = i.ContactId }; db.Entry(c).State = System.Data.Entity.EntityState.Deleted; } db.SaveChanges(); //var person = db.Person.Where(x => x.PersonId == id).First(); Person p = new Person() { PersonId = id }; db.Entry(p).State = System.Data.Entity.EntityState.Deleted; db.SaveChanges(); return(View()); }
public ActionResult Delete(int id, PersonViewModel collection) { try { PhoneBookDbEntities db = new PhoneBookDbEntities(); var contacts = db.Contacts.Where(x => x.PersonId == id); //Condition to check the Id of specific person to edit only his/her details foreach (var i in contacts) { Contact c = new Contact() { ContactId = i.ContactId }; db.Entry(c).State = System.Data.Entity.EntityState.Deleted; } db.SaveChanges(); //var person = db.Person.Where(x => x.PersonId == id).First(); Person p = new Person() { PersonId = id }; db.Entry(p).State = System.Data.Entity.EntityState.Deleted; db.SaveChanges(); //return Content("delete"); return(RedirectToAction("Index")); } catch { return(View()); } }
public ActionResult Delete(int id, FormCollection collection) { try { // TODO: Add delete logic here PhoneBookDbEntities db = new PhoneBookDbEntities(); var contacts = db.Contacts.Where(x => x.PersonId == id); foreach (var i in contacts) { Contact c = new Contact() { ContactId = i.ContactId }; db.Entry(c).State = System.Data.Entity.EntityState.Deleted; } db.SaveChanges(); //var person = db.Person.Where(x => x.PersonId == id).First(); Person p = new Person() { PersonId = id }; db.Entry(p).State = System.Data.Entity.EntityState.Deleted; db.SaveChanges(); return(RedirectToAction("Index")); } catch { return(View()); } }
public ActionResult Edit(int id, PersonViewModel Modelperson) { try { // TODO: Add update logic here Person person = new Person(); person.FirstName = Modelperson.FirstName; person.MiddleName = Modelperson.MiddleName; person.LastName = Modelperson.LastName; person.AddedOn = DateTime.Now; person.AddedBy = User.Identity.GetUserId(); person.UpdateOn = DateTime.Now; person.DateOfBirth = Modelperson.DateOfBirth; person.HomeAddress = Modelperson.HomeAddress; person.HomeCity = Modelperson.HomeCity; person.FaceBookAccountId = Modelperson.FaceBookAccountId; person.LinkedInId = Modelperson.LinkedInId; person.TwitterId = Modelperson.TwitterId; person.EmailId = Modelperson.EmailId; person.ImagePath = Modelperson.ImagePath; db.Entry(person).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } catch { return(View()); } }
public ActionResult Edit(int id, PersonViewModel p) { PhoneBookDbEntities db = new PhoneBookDbEntities(); if (ModelState.IsValid) { Person a = db.People.Find(id); a.PersonId = p.PersonId; a.FirstName = p.FirstName; a.MiddleName = p.MiddleName; a.LastName = p.LastName; a.DateOfBirth = p.DateOfBirth; a.AddedOn = p.AddedOn; a.AddedBy = p.AddedBy; a.HomeAddress = p.HomeAddress; a.HomeCity = p.HomeCity; a.FaceBookAccountId = p.FaceBookAccountId; a.TwitterId = p.TwitterId; a.UpdateOn = DateTime.Now.Date; a.ImagePath = p.ImagePath; a.LinkedInId = p.LinkedInId; a.EmailId = p.EmailId; db.Entry(a).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index", new { id = User.Identity.GetUserId() })); } ViewBag.AddedBy = new SelectList(db.AspNetUsers, "Id", "Email", p.AddedBy); return(View(p)); //catch //{ // return View(); //} }
public ActionResult Edit(int id, Person obj) { try { // TODO: Add update logic here using (entity) { entity.Entry(obj).State = System.Data.Entity.EntityState.Modified; entity.SaveChanges(); } return(RedirectToAction("Index")); } catch { return(View()); } }
public ActionResult Edit([Bind(Include = "Id,Email,EmailConfirmed,PasswordHash,SecurityStamp,PhoneNumber,PhoneNumberConfirmed,TwoFactorEnabled,LockoutEndDateUtc,LockoutEnabled,AccessFailedCount,UserName")] AspNetUser aspNetUser) { if (ModelState.IsValid) { db.Entry(aspNetUser).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(aspNetUser)); }
public ActionResult Edit([Bind(Include = "PersonId,FirstName,MiddleName,LastName,DateOfBirth,AddedOn,AddedBy,HomeAddress,HomeCity,FaceBookAccountId,LinkedInId,UpdateOn,ImagePath,TwitterId,EmailId")] Person person) { if (ModelState.IsValid) { db.Entry(person).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.AddedBy = new SelectList(db.AspNetUsers, "Id", "Email", person.AddedBy); return(View(person)); }
public ActionResult Edit([Bind(Include = "ContactId,ContactNumber,Type,PersonId")] Contact contact) { if (ModelState.IsValid) { db.Entry(contact).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.PersonId = new SelectList(db.People, "PersonId", "FirstName", contact.PersonId); return(View(contact)); }
public ActionResult Edit(int id, ContactsViewModel cont) { // TODO: Add update logic here PhoneBookDbEntities db = new PhoneBookDbEntities(); if (ModelState.IsValid) { Contact c = db.Contacts.Find(id); c.ContactId = cont.ContactId; c.ContactNumber = cont.ContactNumber; c.Type = cont.Type; c.PersonId = cont.PersonId; db.Entry(c).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index", new { id = c.PersonId })); } // ViewBag.AddedBy = new SelectList(db.AspNetUsers, "Id", "Email", cont.AddedBy); return(View(cont)); }
public ActionResult Delete(int id, FormCollection collection) { try { // TODO: Add delete logic here PhoneBookDbEntities db = new PhoneBookDbEntities(); var contacts = db.Contacts.Where(x => x.ContactId == id); db.Entry(contacts).State = System.Data.Entity.EntityState.Deleted; db.SaveChanges(); return(RedirectToAction("Index")); } catch { return(View()); } }