public Contact AddContact(Contact contact) { if (contact == null) { throw new ArgumentNullException("contact"); } contact.Id = _nextId++; _contacts.Add(contact); return contact; }
public ActionResult Delete(int id, Contact deleted) { using (var session = AddressBook.RavenStore.OpenSession()) { var contact = session.Load<Contact>(id); session.Delete(contact); session.SaveChanges(); } return RedirectToAction("Index"); }
public ActionResult Create(Contact contact) { if (!ModelState.IsValid) return View(); using (var session = AddressBook.RavenStore.OpenSession()) { session.Store(contact); session.SaveChanges(); } return RedirectToRoute("list"); }
public bool UpdateContact(Contact contact) { if (contact == null) { throw new ArgumentNullException("contact"); } int index = _contacts.FindIndex(c => c.Id == contact.Id); if (index == -1) { return false; } _contacts.RemoveAt(index); _contacts.Add(contact); return true; }
public ActionResult Create(Contact contact) { if (ModelState.IsValid) { User user = db.Users.Where(u => u.UserName == User.Identity.Name).First(); contact.UserId = user.Id; contact.EncryptPII(); db.Contacts.Add(contact); db.SaveChanges(); return RedirectToAction("Index"); } //ViewBag.UserId = new SelectList(db.Users, "Id", "Email", contact.UserId); contact.Notes = HttpContext.Server.HtmlDecode(contact.Notes); return View(contact); }
public ActionResult Edit(int id, Contact updated) { if (ModelState.IsValid) using (var session = AddressBook.RavenStore.OpenSession()) { var contact = session.Load<Contact>(id); contact.FirstName = updated.FirstName; contact.LastName = updated.LastName; contact.PhoneNumber = updated.PhoneNumber; contact.Email = updated.Email; session.Store(contact); session.SaveChanges(); } return RedirectToAction("Index"); }
public ActionResult Edit(Contact contact) { if (ModelState.IsValid) { contact.EncryptPII(); db.Entry(contact).State = EntityState.Modified; db.SaveChanges(); return RedirectToAction("Index"); } //ViewBag.UserId = new SelectList(db.Users, "Id", "Email", contact.UserId); contact.Notes = HttpContext.Server.HtmlDecode(contact.Notes); return View(contact); }