public bool EditSessionType(SessionTypeEdit model) { using (var db = new ApplicationDbContext()) { var entity = db.SessionTypes.FirstOrDefault(s => s.SessionTypeID == model.SessionTypeID); entity.Name = model.Name; entity.PricePerHour = model.PricePerHour; return(db.SaveChanges() == 1); } }
//Edit by Id public ActionResult Edit(int id) { var service = new SessionTypeService(); var detail = service.GetSessionTypeByID(id); var model = new SessionTypeEdit { SessionTypeID = detail.SessionTypeID, Name = detail.Name, PricePerHour = detail.PricePerHour }; var sessionService = new SessionTypeService(); var sessionTypeList = sessionService.GetSessionTypes(); ViewBag.SessionTypeID = new SelectList(sessionTypeList, "SessionTypeID", "Name", model.SessionTypeID); return(View(model)); }
public ActionResult Edit(SessionTypeEdit model) { var sessionService = new SessionTypeService(); var sessionTypeList = sessionService.GetSessionTypes(); ViewBag.SessionTypeID = new SelectList(sessionTypeList, "SessionTypeID", "Name", model.SessionTypeID); if (!ModelState.IsValid) { return(View(model)); } var service = new SessionTypeService(); if (service.EditSessionType(model)) { return(RedirectToAction("Index")); } ModelState.AddModelError("", "Session type could not be updated."); return(View(model)); }