Example #1
0
        public ActionResult <AnnualLeaveRequestCRUDModel> Update(AnnualLeaveRequestCRUDModel updateAnnualLeaveRequestCRUDModel)
        {
            try
            {
                var annualLeaveRequestUpdated = _annualLeaveRequestLogic.Update(updateAnnualLeaveRequestCRUDModel);

                if (annualLeaveRequestUpdated != null && annualLeaveRequestUpdated.Year == updateAnnualLeaveRequestCRUDModel.Year &&
                    string.IsNullOrEmpty(annualLeaveRequestUpdated.ErrorMessage))
                {
                    return(Ok(annualLeaveRequestUpdated));
                }
                else
                {
                    if (annualLeaveRequestUpdated == null || annualLeaveRequestUpdated.Year != updateAnnualLeaveRequestCRUDModel.Year)
                    {
                        return(UnprocessableEntity("Annual Leave Request was not updated"));
                    }
                    else if (!string.IsNullOrEmpty(annualLeaveRequestUpdated.ErrorMessage))
                    {
                        return(UnprocessableEntity($"Annual Leave Request was not updated.  Error Messages: {annualLeaveRequestUpdated.ErrorMessage}"));
                    }
                    else
                    {
                        return(UnprocessableEntity("Annual leave request was not updated"));
                    }
                }
            }
            catch (Exception)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError,
                                  "Error updating the annual leave request"));
            }
        }
Example #2
0
        public IActionResult Edit(AnnualLeaveRequestCreateViewModel editAnnualLeaveRequestViewModel)
        {
            if (ModelState.IsValid)
            {
                var editAnnualLeaveRequest = new AnnualLeaveRequestOverviewModel()
                {
                    AnnualLeaveRequestID = editAnnualLeaveRequestViewModel.AnnualLeaveRequestID,
                    Year          = editAnnualLeaveRequestViewModel.StartDate.Year,
                    PaidLeaveType = editAnnualLeaveRequestViewModel.PaidLeaveType,
                    LeaveType     = editAnnualLeaveRequestViewModel.LeaveType,
                    StartDate     = editAnnualLeaveRequestViewModel.StartDate,
                    ReturnDate    = editAnnualLeaveRequestViewModel.ReturnDate,
                    Notes         = editAnnualLeaveRequestViewModel.Notes,
                };

                editAnnualLeaveRequest = _annualLeaveRequestLogic.Update(editAnnualLeaveRequest);

                if (IsValidAnnualLeaveRequest(editAnnualLeaveRequest))
                {
                    return(RedirectToAction("Overview", new { selectedYear = editAnnualLeaveRequest.Year }));
                }
                else
                {
                    string errorMessage = editAnnualLeaveRequest?.ErrorMessage ?? string.Empty;

                    var editAnnualLeaveRequestViewModelInError = _annualLeaveRequestLogic.GetCreateViewModelForEdit(editAnnualLeaveRequestViewModel.AnnualLeaveRequestID, errorMessage: errorMessage);

                    return(View(editAnnualLeaveRequestViewModelInError));
                }
            }
            else
            {
                var editAnnualLeaveRequestViewModelInError = _annualLeaveRequestLogic.GetCreateViewModelForEdit(editAnnualLeaveRequestViewModel.AnnualLeaveRequestID);

                return(View(editAnnualLeaveRequestViewModelInError));
            }
        }