public ActionResult Update(Shift shift) { ApiResult <Shift> apiResult; if (ModelState.IsValid) { if (shift.Id > 0) { apiResult = TryExecute(() => { _shiftRepository.Update(shift); _unitOfWork.Commit(); return(shift); }, "Shift updated sucessfully"); } else { apiResult = TryExecute(() => { _shiftRepository.Create(shift); _unitOfWork.Commit(); return(shift); }, "Shift created sucessfully"); } } else { apiResult = ApiResultFromModelErrors <Shift>(); } return(Json(apiResult, JsonRequestBehavior.AllowGet)); }
public async Task <IActionResult> Create(Shift shift) { if (ModelState.IsValid) { await shiftRepository.Create(shift); return(RedirectToAction("index")); } PopulateVenuesDropDownList(shift.VenueID); return(View()); }
public Shift CreateShiftToday(ShiftType type) { DateTime time = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 8, 0, 0); //This shift time can be moved into a database or configuration class Shift shift = new Shift() { StartTime = time, EndTime = time.AddHours(5), //This shift time can be moved into a database or configuration class TypeOfShift = type, AssignedEngineer = null }; if (IsShiftCreated(shift)) { return(null); } int rowsReturned = _shiftRepository.Create(shift); return(shift); }
public IActionResult Post([FromBody] Shift model) { if (ModelState.IsValid) { _repository.Create(model); return(Ok(model)); } else { return(new ResponseResult(Response) { StatusCode = (int)StatusCodes.Status400BadRequest, ResponseObject = ModelState.ToJson() }.ToJsonResult()); } }
public IActionResult Save([FromBody] Shift shift) { if (shift is null) { return(BadRequest("Shift is null.")); } if (!ModelState.IsValid) { return(BadRequest()); } if (shift.ShiftId == 0) { _repository.Create(shift); return(new JsonResult(new { create = true, shift })); } else { _repository.Update(shift); return(new JsonResult(new { update = true, shift })); } }
public bool Create(Shift model) { return(rep.Create(model)); }
public void Execute(ShiftCreateCommand command) { var shift = new Shift(command.ShiftTitle); shiftRepository.Create(shift); }