public bool CreateShift(ShiftCreate model) { var entity = new ShiftTable() { Shift = model.Shift }; using (var ctx = new ApplicationDbContext()) { ctx.Shifts.Add(entity); return(ctx.SaveChanges() == 1); } }
public ActionResult Create(ShiftCreate model) { if (!ModelState.IsValid) { return(View(model)); } if (service.CreateShift(model)) { TempData["SaveShiftResult"] = $"Shift {model.Shift} was created."; return(RedirectToAction("Index")); } ModelState.AddModelError("", "Could not create new Shift"); return(View(model)); }
public bool CreateShift(ShiftCreate model) { using (var ctx = new ApplicationDbContext()) { var entity = new Shift() { OwnerId = _userId, ShiftId = model.ShiftId, ShiftName = model.ShiftName, Date = model.Date, Notes = model.Notes }; ctx.Shifts.Add(entity); return(ctx.SaveChanges() == 1); } }
public ActionResult Create(ShiftCreate model) { if (!ModelState.IsValid) { return(View(model)); } var service = CreateShiftService(); if (service.CreateShift(model)) { TempData["SaveResult"] = $"You have successfully created {model.ShiftName}."; return(RedirectToAction("Index")); } ; ModelState.AddModelError("", "Unfortunately this shift was unable to be created."); return(View(model)); }