Ejemplo n.º 1
0
        public ActionResult Approve(FormCollection collection)
        {
            var user = (ViewUser)Session["user"];

            try
            {
                var id       = Convert.ToInt64(collection["RequisitionId"]);
                var actionId = Convert.ToInt32(collection["ApprovarActionId"]);
                var remarks  = collection["Remarks"];
                var approval = new ApprovalDetails
                {
                    ApprovalActionId = actionId,
                    ApproverUserId   = user.UserId,
                    Remarks          = remarks,

                    GeneralRequisitionId = id
                };
                GeneralRequisitionModel model = _iProductManager.GetGeneralRequisitionById(id);
                var approvalLevel             = _iCommonManager.GetAllApprovalPath().ToList()
                                                .FindAll(n => n.UserId == model.RequisitionByUserId)
                                                .Find(n => n.ApprovalLevel.Equals(model.CurrentApprovalLevel + 1));

                var nextApprovalLevel = 0;
                var nextApproverUser  = 0;
                if (approvalLevel != null)
                {
                    nextApprovalLevel = approvalLevel.ApprovalLevel;
                    nextApproverUser  = approvalLevel.ApproverUserId;
                }
                if (approvalLevel == null)
                {
                    model.IsFinalApproved = "Y";
                }
                if (actionId != 1)
                {
                    model.IsCancelled = "Y";
                }
                bool result = _iProductManager.ApproveGeneralRequisition(model, nextApproverUser, nextApprovalLevel, approval);

                ICollection <ViewGeneralRequisitionModel> requisitions = _iProductManager.GetAllGeneralRequisitions()
                                                                         .ToList().FindAll(n => n.CurrentApproverUserId == user.UserId);
                return(PartialView("_ViewGeneralRequisitionListPartialPage", requisitions));
            }
            catch (Exception exception)
            {
                Log.WriteErrorLog(exception);
                ICollection <ViewGeneralRequisitionModel> requisitions = _iProductManager.GetAllGeneralRequisitions()
                                                                         .ToList().FindAll(n => n.CurrentApproverUserId == user.UserId);
                return(PartialView("_ViewGeneralRequisitionListPartialPage", requisitions));
            }
        }