public IActionResult Create(AnnualLeaveRequestCreateViewModel newAnnualLeaveRequestViewModel) { if (ModelState.IsValid) { var newAnnualLeaveRequest = new AnnualLeaveRequestOverviewModel() { Year = newAnnualLeaveRequestViewModel.StartDate.Year, PaidLeaveType = newAnnualLeaveRequestViewModel.PaidLeaveType, LeaveType = newAnnualLeaveRequestViewModel.LeaveType, StartDate = newAnnualLeaveRequestViewModel.StartDate, ReturnDate = newAnnualLeaveRequestViewModel.ReturnDate, Notes = newAnnualLeaveRequestViewModel.Notes, }; newAnnualLeaveRequest = _annualLeaveRequestLogic.Create(newAnnualLeaveRequest); if (IsValidAnnualLeaveRequest(newAnnualLeaveRequest)) { return(RedirectToAction("Overview", new { selectedYear = newAnnualLeaveRequest.Year })); } else { var createAnnualLeaveRequest = _annualLeaveRequestLogic.GetCreateViewModelForCreate(errorMessage: newAnnualLeaveRequest?.ErrorMessage ?? string.Empty); return(View(createAnnualLeaveRequest)); } } else { var createAnnualLeaveRequest = _annualLeaveRequestLogic.GetCreateViewModelForCreate(); return(View(createAnnualLeaveRequest)); } }
public IActionResult Create(AnnualLeaveRequestCRUDModel createAnnualLeaveRequestCRUDModel) { try { var annualLeaveRequestCreated = _annualLeaveRequestLogic.Create(createAnnualLeaveRequestCRUDModel); if (annualLeaveRequestCreated != null && annualLeaveRequestCreated.Year == createAnnualLeaveRequestCRUDModel.Year && string.IsNullOrEmpty(annualLeaveRequestCreated.ErrorMessage)) { return(CreatedAtAction(nameof(Create), new { id = annualLeaveRequestCreated.AnnualLeaveRequestID }, annualLeaveRequestCreated)); } else { if (annualLeaveRequestCreated == null || annualLeaveRequestCreated.Year != createAnnualLeaveRequestCRUDModel.Year) { return(UnprocessableEntity("Annual Leave Request was not created")); } else if (!string.IsNullOrEmpty(annualLeaveRequestCreated.ErrorMessage)) { return(UnprocessableEntity($"Annual Leave Request was not created. Error Messages: {annualLeaveRequestCreated.ErrorMessage}")); } else { return(UnprocessableEntity("Annual leave request was not created")); } } } catch (Exception) { return(StatusCode(StatusCodes.Status500InternalServerError, "Error creating the annual leave request")); } }