コード例 #1
0
        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));
            }
        }
コード例 #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));
            }
        }