public AnnualLeaveRequestOverviewModel Update(AnnualLeaveRequestOverviewModel model)
        {
            using (IDbConnection connection = Connection)
            {
                string query = @"exec procUpdateAnnualLeaveRequest 
                                        @AnnualLeaveRequestID,                 
                                        @PaidLeaveType, 
                                        @LeaveType, 
                                        @StartDate, 
                                        @ReturnDate,  
                                        @Notes";

                try
                {
                    connection.Query <int>(query, model);

                    model.ErrorMessage = string.Empty;
                }
                catch (Exception ex)
                {
                    model.ErrorMessage = ex.Message;
                }
            }

            return(model);
        }
Exemplo n.º 2
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));
            }
        }
Exemplo n.º 3
0
        public AnnualLeaveRequestCRUDModel Update(AnnualLeaveRequestCRUDModel model)
        {
            var annnualLeaveRequestOverviewModel = new AnnualLeaveRequestOverviewModel()
            {
                AnnualLeaveRequestID = model.AnnualLeaveRequestID,
                Year          = model.Year,
                PaidLeaveType = model.PaidLeaveType,
                LeaveType     = model.LeaveType,
                StartDate     = model.StartDate,
                ReturnDate    = model.ReturnDate,
                Notes         = model.Notes,
            };

            var updateAnnnualLeaveRequestOverviewModel = _annualLeaveRequestDataAccess.Update(annnualLeaveRequestOverviewModel);

            return(new AnnualLeaveRequestCRUDModel()
            {
                AnnualLeaveRequestID = updateAnnnualLeaveRequestOverviewModel.AnnualLeaveRequestID,
                Year = updateAnnnualLeaveRequestOverviewModel.Year,
                PaidLeaveType = updateAnnnualLeaveRequestOverviewModel.PaidLeaveType,
                LeaveType = updateAnnnualLeaveRequestOverviewModel.LeaveType,
                StartDate = updateAnnnualLeaveRequestOverviewModel.StartDate,
                ReturnDate = updateAnnnualLeaveRequestOverviewModel.ReturnDate,
                Notes = updateAnnnualLeaveRequestOverviewModel.Notes,
                ErrorMessage = updateAnnnualLeaveRequestOverviewModel.ErrorMessage,
            });
        }
        public void Delete(AnnualLeaveRequestOverviewModel model)
        {
            using (IDbConnection connection = Connection)
            {
                string query = "exec procDeleteAnnualLeaveRequest @AnnualLeaveRequestID";

                connection.Query <int>(query, model);
            }
        }
        public async Task <AnnualLeaveRequestOverviewModel> UpdateAnnualLeaveRequest(AnnualLeaveRequestOverviewModel annualLeaveRequest)
        {
            var response = await _httpClient.PutAsJsonAsync(CONTROLLER_NAME, annualLeaveRequest);

            if (!response.IsSuccessStatusCode)
            {
                string errorResponse = await response.Content.ReadAsStringAsync();

                throw new ApplicationException(errorResponse);
            }

            return(await response.Content.ReadFromJsonAsync <AnnualLeaveRequestOverviewModel>());
        }
Exemplo n.º 6
0
        public void Delete(AnnualLeaveRequestOverviewModel model)
        {
            var annualLeaveRequest = new Models.AnnualLeaveRequest()
            {
                AnnualLeaveRequestId    = model.AnnualLeaveRequestID,
                PaidLeaveType           = model.PaidLeaveType,
                LeaveType               = model.LeaveType,
                StartDate               = model.StartDate,
                ReturnDate              = model.ReturnDate,
                NumberOfDays            = model.NumberOfDays,
                NumberOfAnnualLeaveDays = model.NumberOfAnnualLeaveDays,
                NumberOfPublicLeaveDays = model.NumberOfPublicLeaveDays,
                DateCreated             = model.DateCreated,
                Notes = model.Notes,
                Year  = model.Year,
            };

            _annualLeaveRequestEFDataAccess.Delete(annualLeaveRequest);
        }
Exemplo n.º 7
0
        public AnnualLeaveRequestOverviewModel Update(AnnualLeaveRequestOverviewModel model)
        {
            var annualLeaveRequest = new Models.AnnualLeaveRequest()
            {
                AnnualLeaveRequestId    = model.AnnualLeaveRequestID,
                PaidLeaveType           = model.PaidLeaveType,
                LeaveType               = model.LeaveType,
                StartDate               = model.StartDate,
                ReturnDate              = model.ReturnDate,
                NumberOfDays            = model.NumberOfDays,
                NumberOfAnnualLeaveDays = model.NumberOfAnnualLeaveDays,
                NumberOfPublicLeaveDays = model.NumberOfPublicLeaveDays,
                DateCreated             = model.DateCreated,
                Notes = model.Notes,
                Year  = model.Year,
            };

            var updateAnnualLeaveRequest = _annualLeaveRequestEFDataAccess.Update(annualLeaveRequest);

            return(_mapper.Map <AnnualLeaveRequestOverviewModel>(updateAnnualLeaveRequest));
        }
Exemplo n.º 8
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));
            }
        }
 public AnnualLeaveRequestOverviewModel Update(AnnualLeaveRequestOverviewModel model)
 {
     return(_annualLeaveRequestDataAccess.Update(model));
 }
 public void Delete(AnnualLeaveRequestOverviewModel model)
 {
     _annualLeaveRequestDataAccess.Delete(model);
 }
Exemplo n.º 11
0
 private bool IsValidAnnualLeaveRequest(AnnualLeaveRequestOverviewModel annualLeaveRequest) => annualLeaveRequest != null &&
 string.IsNullOrEmpty(annualLeaveRequest.ErrorMessage);