示例#1
0
        public ActionResult CancelRequest(int id)
        {
            try
            {
                var request    = _repo.FindById(id.ToString());
                var allocation = _leaveAllocationRepo.GetLeaveAllocationsByEmployeeIdandLeaveType(request.RequestingEmployeeId, request.LeaveTypeId, DateTime.Now.Year).FirstOrDefault();

                var numberOfDays = (int)(request.EndDate.Date - request.StartDate.Date).TotalDays;
                var approver     = _userManager.GetUserAsync(User).Result;
                request.Approved         = false;
                request.ApprovedBy       = approver;
                request.ApprovedById     = approver.Id;
                request.DateActioned     = DateTime.UtcNow;
                allocation.NumberofDays += numberOfDays;

                var op1 = _repo.Delete(_mapper.Map <LeaveRequest>(request));
                var op2 = _leaveAllocationRepo.Update(allocation);

                if (!op1 || !op2)
                {
                    var errormodel = GetCreateLeaveRequestVM();
                    ModelState.AddModelError("", "Error during save.");
                }
                return(RedirectToAction(nameof(MyLeave)));
            }
            catch
            {
                ModelState.AddModelError("", "An error occured.");
                return(RedirectToAction(nameof(MyLeave)));
            }
        }
        // GET: LeaveRequestController/Delete/5
        public async Task <ActionResult> Delete(int id)
        {
            var leaveRequest = await _leaveRequestRepo.FindById(id);

            if (leaveRequest == null)
            {
                return(NotFound());
            }
            var isSuccess = await _leaveRequestRepo.Delete(leaveRequest);

            if (!isSuccess)
            {
                return(BadRequest());
            }
            return(RedirectToAction(nameof(Index)));
        }
        public ActionResult CancelRequest(int id)
        {
            try
            {
                // TODO: Add delete logic here
                var leaveRequest = _leaveRequestRepo.FindById(id);

                if (leaveRequest == null)
                {
                    return(NotFound());
                }

                var isSuccess = _leaveRequestRepo.Delete(leaveRequest);
                if (!isSuccess)
                {
                    return(BadRequest());
                }

                return(RedirectToAction("UserLeaveRequests"));
            }
            catch
            {
                return(View());
            }
        }
        public async Task <IActionResult> CancelRequest(int id)
        {
            string employeeId = _userManager.GetUserId(User);

            var leaveRequest = await _leaveRequestRepo.FindById(id);

            if (leaveRequest.Approved == true)
            {
                var startDayOfLeave            = leaveRequest.StartDate;
                var endDayOfLeave              = leaveRequest.EndDate;
                int totalNumberOfDays          = (int)(endDayOfLeave - startDayOfLeave).TotalDays;
                int leaveRequestId             = leaveRequest.LeaveTypeId;
                var leaveAllocationForEmployee = await _leaveAllocationRepo.GetLeaveAllocationsByEmployeeAndType(employeeId, leaveRequestId);

                leaveAllocationForEmployee.NumberOfDays += totalNumberOfDays;
                var updatedAllocationForUser = _leaveAllocationRepo.Update(leaveAllocationForEmployee);
            }

            var requestDeleted = await _leaveRequestRepo.Delete(leaveRequest);

            if (!requestDeleted)
            {
                ModelState.AddModelError("", "Something Went wrong when cancelling request");
                return(RedirectToAction(nameof(EmployeeIndex)));
            }

            return(RedirectToAction(nameof(EmployeeIndex)));
        }
        public ActionResult CancelRequest(int id)
        {
            var leaverequest = _LeaveRequestRepo.FindByID(id);

            _LeaveRequestRepo.Delete(leaverequest);

            return(RedirectToAction("MyLeave"));
        }
        public async Task <IActionResult> DeleteConfirmed(long id)
        {
            //var leaveRequest = await _context.LeaveRequests.FindAsync(id);
            //_context.LeaveRequests.Remove(leaveRequest);
            //await _context.SaveChangesAsync();
            var leaveRequest = leaveRequestRepository.GetDeleteList(id);
            await leaveRequestRepository.Delete(leaveRequest);

            return(RedirectToAction(nameof(Index)));
        }
示例#7
0
        public IActionResult DeleteLeaverequest(long id)
        {
            LeaveRequest a = LeaveRequest_repo.Find(id);

            if (a == null)
            {
                return(NotFound());
            }
            LeaveRequest_repo.Delete(a);
            return(Ok());
        }
示例#8
0
 public bool Delete(int id)
 {
     if (string.IsNullOrWhiteSpace(id.ToString()))
     {
         return(false);
     }
     else
     {
         return(iLeaveRequestRepository.Delete(id));
     }
 }
示例#9
0
        public async Task <ActionResult> MakeAdmin(string id)
        {
            var employee = _userManager.FindByIdAsync(id).Result;

            var result = await _userManager.RemoveFromRoleAsync(employee, "Employee");

            if (result.Succeeded)
            {
                var response = await _userManager.AddToRoleAsync(employee, "Administrator");

                if (response.Succeeded)
                {
                    var allocation = await _allocationRepo.GetLeaveAllocationsByEmployee(employee.Id);

                    var requests = await _requestRepo.GetLeaveRequestByEmployee(employee.Id);

                    if (allocation != null)
                    {
                        foreach (var item in allocation)
                        {
                            await _allocationRepo.Delete(item);
                        }
                    }

                    if (requests != null)
                    {
                        foreach (var item in requests)
                        {
                            await _requestRepo.Delete(item);
                        }
                    }
                }
                else
                {
                    ModelState.AddModelError("", "Failed to assign Administrator role");
                    return(RedirectToAction("Details", "LeaveAllocation", new { id = employee.Id }));
                }
            }
            else
            {
                ModelState.AddModelError("", "Failed to remove Employee role");
                return(RedirectToAction("Details", "LeaveAllocation", new { id = employee.Id }));
            }



            return(RedirectToAction("ListEmployees", "LeaveAllocation"));
        }
示例#10
0
        // GET: LeaveTypesController/Delete/5
        public async Task <ActionResult> Delete(int id)
        {
            if (!await _repo.isExists(id))
            {
                return(NotFound());
            }

            var leavetype = await _repo.FindById(id);

            if (leavetype == null)
            {
                return(NotFound());
            }

            var isSuccess = await _repo.Delete(leavetype);

            if (!isSuccess)
            {
                return(BadRequest());
            }

            var allocation = await _AlloRepo.FindAll();

            if (allocation != null)
            {
                var AlloToDetete = allocation.ToList().Where(Q => Q.LeaveTypeId == id);

                foreach (var item in AlloToDetete)
                {
                    await _AlloRepo.Delete(item);
                }
            }


            var request = await _requestRepo.FindAll();

            if (allocation != null)
            {
                var requestToDetete = request.ToList().Where(Q => Q.LeaveTypeId == id);

                foreach (var item in requestToDetete)
                {
                    await _requestRepo.Delete(item);
                }
            }

            return(RedirectToAction(nameof(Index)));
        }
示例#11
0
        public OutputBase DeleteLeaveRequest(DeleteLeaveRequestInput input)
        {
            var request = _leaveRequestRepository.Get(input.LeaveRequestId);

            if (request.EmployeeId != GetCurrentUserId() &&
                !IsGranted(AppPermissions.Pages_Leave_LeaveRequest_DeleteAny))
            {
                return(new OutputBase {
                    Message = "You cannot delete a request that is not yours", Success = false
                });
            }
            _leaveRequestRepository.Delete(request);
            return(new OutputBase {
                Message = "Request deleted", Success = true
            });
        }
示例#12
0
        // GET: LeaveRequestController/Delete/5
        public async Task <ActionResult> Delete(int id)
        {
            var leavetype = await _leaveRequestRepo.FindById(id);

            if (leavetype == null)
            {
                return(NotFound("Rất tiếc! yêu cầu nghỉ phép không tìm thấy"));
            }
            var isSuccess = await _leaveRequestRepo.Delete(leavetype);


            if (!isSuccess)
            {
                return(BadRequest());
            }

            return(RedirectToAction(nameof(Index)));
        }
示例#13
0
        public async Task <ActionResult> CancelRequest(int id)
        {
            var leaveType = await _requestRepo.FindById(id);

            if (leaveType is null)
            {
                return(NotFound());
            }

            var isSuccess = await _requestRepo.Delete(leaveType);

            if (!isSuccess)
            {
                return(BadRequest());
            }

            return(RedirectToAction("MyLeave"));
        }
示例#14
0
 public bool Delete(int id)
 {
     return(iLeaveRequestRepository.Delete(id));
 }
 public void Delete(LeaveRequest entity)
 {
     _leaveRequestRepository.Delete(entity);
 }