public bool UpdateShift(ShiftEdit model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx.Shifts.SingleOrDefault(e => e.ShiftId == model.ShiftId); entity.Shift = model.Shift; return(ctx.SaveChanges() == 1); } }
//GET: Shift/Edit/{id} public ActionResult Edit(int id) { ShiftDetail detail = service.GetShiftById(id); ShiftEdit model = new ShiftEdit { ShiftId = detail.ShiftId, Shift = detail.Shift //Should I add employee here? }; return(View(model)); }
// GET: Edit // Shift/Edit/{id} public ActionResult Edit(int id) { var service = CreateShiftService(); var detail = service.GetShiftById(id); var model = new ShiftEdit { ShiftId = detail.ShiftId, ShiftName = detail.ShiftName, Date = detail.Date, Notes = detail.Notes }; return(View(model)); }
public bool UpdateShift(ShiftEdit model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx .Shifts .FirstOrDefault(e => e.ShiftId == model.ShiftId && e.OwnerId == _userId); entity.ShiftName = model.ShiftName; entity.Date = model.Date; entity.Notes = model.Notes; return(ctx.SaveChanges() == 1); } }
public ActionResult Edit(int id, ShiftEdit model) { if (!ModelState.IsValid) { return(View(model)); } if (model.ShiftId != id) { ModelState.AddModelError("", "ID does not match."); return(View(model)); } if (service.UpdateShift(model)) { TempData["SaveShiftResult"] = $"Shift {service.GetShiftById(id).Shift} was updated."; return(RedirectToAction("Index")); } ModelState.AddModelError("", "Shift could not be updated."); return(View()); }
public ActionResult Edit(int id, ShiftEdit model) { if (!ModelState.IsValid) { return(View(model)); } if (model.ShiftId != id) { ModelState.AddModelError("", "The Id's do not match."); return(View(model)); } var service = CreateShiftService(); if (service.UpdateShift(model)) { TempData["SaveResult"] = $"{model.ShiftName} has been updated."; return(RedirectToAction("Index")); } ModelState.AddModelError("", "This Shift was NOT updated successfully."); return(View()); }