Exemplo n.º 1
0
        public PartialViewResult ApproveReq(int id, string status)
        {
            var reqDto = new ReqApproveRejectDTO
            {
                RequisitionId = id,
                Status        = status
            };

            if (User.IsInRole(Role.DepartmentHead) && !HasDelegate || IsDelegate)
            {
                return(PartialView("_ApproveReq", reqDto));
            }

            return(PartialView("_hasDelegate"));
        }
Exemplo n.º 2
0
        public ActionResult ApproveReq(ReqApproveRejectDTO reqApprovalDto)
        {
            var req = _requisitionRepo.GetById(reqApprovalDto.RequisitionId);

            if (req == null || req.Status != RequisitionStatus.Pending)
            {
                return(PartialView("_unauthoriseAccess"));
            }

            var deptCode = Request.Cookies["Employee"]?["DeptCode"];
            var empNum   = Convert.ToInt32(Request.Cookies["Employee"]?["EmpNum"]);

            //must be pending for approval and reject
            if (User.IsInRole(Role.DepartmentHead) && !HasDelegate || IsDelegate)
            {
                //if (user is head and there is no delegate) or (user is currently delegate)
                if (deptCode != _departmentRepo.GetDepartmentByEmpNum(req.RequisitionEmpNum).DeptCode)
                {
                    //if user is trying to approve for other department
                    return(PartialView("_unauthoriseAccess"));
                }

                if (empNum == req.RequisitionEmpNum)
                {
                    //if user is trying to self approve
                    return(PartialView("_unauthoriseAccess"));
                }

                if (ModelState.IsValid)
                {
                    req.Status          = reqApprovalDto.Status;
                    req.ApprovalRemarks = reqApprovalDto.ApprovalRemarks;
                    req.ApprovalEmpNum  = empNum;
                    req.ApprovalDate    = DateTime.Today;


                    if (reqApprovalDto.Status == Approved)
                    {
                        foreach (var requisitionDetail in req.RequisitionDetails)
                        {
                            var stationery = _stationeryRepo.GetById(requisitionDetail.ItemNum);
                            stationery.AvailableQty = stationery.AvailableQty - requisitionDetail.Quantity;
                            _stationeryRepo.Update(stationery);
                        }
                    }

                    _requisitionRepo.Update(req);

                    //Send email
                    var toEmail = req.RequisitionEmployee.EmailAddress;
                    var email   = new LUSSISEmail.Builder().From(User.Identity.Name)
                                  .To(toEmail).ForRequisitionApproval(req).Build();
                    new Thread(delegate() { EmailHelper.SendEmail(email); }).Start();

                    return(RedirectToAction("Pending"));
                }

                return(PartialView("_ApproveReq", reqApprovalDto));
            }

            return(PartialView("_hasDelegate"));
        }