public ActionResult Save(Reader reader) { if (!ModelState.IsValid) { var viewModel = new ReaderFormModel { Reader = reader, MembershipTypes = _context.MembershipTypes.ToList() }; return(View("ReaderForm", viewModel)); } if (reader.Id == 0) { _context.Readers.Add(reader); } else { var readerInDb = _context.Readers.Single(r => r.Id == reader.Id); readerInDb.Name = reader.Name; readerInDb.Birth = reader.Birth; readerInDb.MembershipTypeId = reader.MembershipTypeId; readerInDb.IsSubcribe = reader.IsSubcribe; } _context.SaveChanges(); return(RedirectToAction("Index", "Readers")); }
//-------READERFORM------------------ public ActionResult ReaderForm() { var membershipTypes = _context.MembershipTypes.ToList(); var viewModel = new ReaderFormModel { MembershipTypes = membershipTypes }; return(View("ReaderForm", viewModel)); }
//------EDIT-------------- public ActionResult Edit(int id) { var reader = _context.Readers.SingleOrDefault(r => r.Id == id); if (reader == null) { return(HttpNotFound()); } var viewModel = new ReaderFormModel { Reader = reader, MembershipTypes = _context.MembershipTypes.ToList() }; return(View("ReaderForm", viewModel)); }