public async Task <ActionResult> ApproveRequest(int id)
        {
            try
            {
                var user = await _userManager.GetUserAsync(User);

                var vacationRequest = await _requestrepo.FindById(id);

                var employeeid     = vacationRequest.RequestingEmployeeId;
                var vacationtypeId = vacationRequest.VacationTypeId;
                var allocation     = await _allocationrepo.GetVacationAllocationsByEmployeeAndType(employeeid, vacationtypeId);

                int daysRequested = (int)(vacationRequest.EndDate - vacationRequest.StartDate).TotalDays;
                // allocation.NumberOfDays = allocation.NumberOfDays - daysRequested; Alternative Way
                allocation.NumberOfDays -= daysRequested;

                vacationRequest.Approved     = true;
                vacationRequest.ApprovedById = user.Id;
                vacationRequest.DateActioned = DateTime.Now;

                await _requestrepo.Update(vacationRequest);

                await _allocationrepo.Update(allocation);

                return(RedirectToAction(nameof(Index), "Home"));
            }
            catch (Exception ex)
            {
                return(RedirectToAction(nameof(Index), "Home"));
            }
        }
Пример #2
0
        public async Task <ActionResult> Edit(EditVacationAllocationVM model)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(View(model));
                }
                var record = await _allocationrepo.FindById(model.Id);

                record.NumberOfDays = model.NumberOfDays;
                var isSucces = await _allocationrepo.Update(record);

                if (!isSucces)
                {
                    ModelState.AddModelError("", "Error while saving...");
                    return(View(model));
                }
                return(RedirectToAction(nameof(Details), new { id = model.EmployeeId }));
            }
            catch
            {
                return(View());
            }
        }