Esempio n. 1
0
        public static WorkflowTaskRespObj LoadWorkflowTasks(WorkflowTaskSearchObj regObj, string username)
        {
            var response = new WorkflowTaskRespObj
            {
                Status = new APIResponseStatus
                {
                    IsSuccessful = false,
                    Message      = new APIResponseMessage(),
                },
            };

            try
            {
                var apiResponse = new APIHelper(APIEndpoints.LOAD_WORKFLOW_TASKS_ENDPOINT, username, Method.POST).ProcessAPI <WorkflowTaskSearchObj, WorkflowTaskRespObj>(regObj, out var msg);
                if (msg.Code == 0 && string.IsNullOrEmpty(msg.TechMessage) && string.IsNullOrEmpty(msg.Message))
                {
                    return(apiResponse);
                }
                response.Status.Message.FriendlyMessage  = msg.Message;
                response.Status.Message.TechnicalMessage = msg.TechMessage;
                return(response);
            }
            catch (Exception ex)
            {
                UtilTools.LogE(ex.StackTrace, ex.Source, ex.GetBaseException().Message);
                response.Status.Message.FriendlyMessage  = "Error Occurred! Please try again later";
                response.Status.Message.TechnicalMessage = "Error: " + ex.GetBaseException().Message;
                return(response);
            }
        }
Esempio n. 2
0
        public ActionResult AddWorkflowDetail(int WorkflowTaskId)
        {
            try
            {
                ViewBag.Error        = "";
                ViewBag.SessionError = "";

                #region Client Product productItem Session Check

                var userClientSession = (AppSession)Session["_UserClientSession_"];
                if (userClientSession == null || userClientSession.ClientId < 1 || userClientSession.ProductId < 1 || userClientSession.ProductItemId < 1)
                {
                    return(RedirectToAction("Index", "Dashboard"));
                }

                #endregion

                #region current user check

                var userData = MvcApplication.GetUserData(User.Identity.Name) ?? new UserData();
                if (userData.UserId < 1)
                {
                    ViewBag.SessionError = "Your session has expired! Please re-login";
                    return(View(new RegWorkflowDetailObj()));
                }

                #endregion

                #region current Id check

                if (WorkflowTaskId < 1)
                {
                    ViewBag.Error = "Invalid selection";
                    return(View(new RegWorkflowDetailObj()));
                }

                #endregion

                #region get current workflow task from service

                var searchObj = new WorkflowTaskSearchObj
                {
                    AdminUserId    = userData.UserId,
                    WorkflowTaskId = 0,
                    Status         = -1000
                };
                var retVal           = WorkflowTaskServices.LoadWorkflowTasks(searchObj, userData.Username);
                var WorkflowTaskList = retVal.WorkflowTasks.ToList();

                var assigneeflowTask = WorkflowTaskList.Find(m => m.WorkflowTaskId == WorkflowTaskId);
                if (assigneeflowTask == null || assigneeflowTask.WorkflowTaskId < 1)
                {
                    ViewBag.Error = "Error Occurred! Unable to process selected item";
                    return(View(new RegWorkflowDetailObj()));
                }
                Session["_CurrentSelWorkflowTask_"] = assigneeflowTask;

                #endregion

                #region extract app users name


                var searchObj2 = new UserSearchObj
                {
                    AdminUserId = userData.UserId,
                    Status      = -2,
                    StopDate    = "",
                    StartDate   = "",
                    UserId      = 0,
                };

                var retValForUsers = new PortalUserManager().LoadUsers(searchObj2, userData.Username);
                var userList       = retValForUsers.Users.ToList();
                Session["_UserList_"] = userList;

                #endregion

                #region get requisitions and extract beneficiaryId and general remark for this Task

                var searchObjForReq = new ExpenseRequisitionSearchObj
                {
                    AdminUserId          = userData.UserId,
                    ExpenseRequisitionId = 0,
                    Status = -1000
                };
                var retValForReq = ExpenseLookupServices.LoadExpenseRequisitions(searchObjForReq, userData.Username);
                if (retValForReq?.Status == null)
                {
                    ViewBag.Error = "Error Occurred! Please try again later";
                    return(View(new RegWorkflowDetailObj()));
                }
                Session["_ExpenseRequisitionList_"] = retValForReq.ExpenseRequisitions.ToList();
                var currentReq = retValForReq.ExpenseRequisitions.FirstOrDefault(m => m.ExpenseRequisitionId == assigneeflowTask.ExpenseRequisitionId);
                if (currentReq == null)
                {
                    ViewBag.Error = "Error Occurred! Unable to process selected item";
                    return(View(new RegWorkflowDetailObj()));
                }
                var BeneficiaryId = currentReq.ExpenseRequisitionItems.FirstOrDefault().BeneficiaryId;

                #endregion

                #region get beneficiary from service and extract benficiary name using beneficiary id from requisitions

                var searchObjForBene = new BeneficiarySearchObj
                {
                    AdminUserId   = userData.UserId,
                    BeneficiaryId = 0,
                    Status        = -1000
                };
                var retValForBene = BeneficiaryServices.LoadBeneficiaries(searchObjForBene, userData.Username);

                if (retValForBene.Beneficiaries.Count < 1)
                {
                    ViewBag.Error = "Error Occurred! Unable to process selected item";
                    return(View(new RegWorkflowDetailObj()));
                }
                var beneficiaryName = retValForBene.Beneficiaries.FirstOrDefault(m => m.BeneficiaryId == BeneficiaryId);
                Session["_BeneficiaryList_"] = retValForBene.Beneficiaries.ToList();

                #endregion

                return(View(new RegWorkflowDetailObj
                {
                    GeeneralRemark = currentReq.GeneralRemark,
                    BeneficiaryName = beneficiaryName.FirstName + " " + beneficiaryName.LastName
                }));
            }
            catch (Exception ex)
            {
                ViewBag.Error = "Error Occurred! Please try again later";
                UtilTools.LogE(ex.StackTrace, ex.Source, ex.Message);
                return(View(new RegWorkflowDetailObj()));
            }
        }
        public ActionResult Index(int?clientId, int?productId)
        {
            try
            {
                ViewBag.Error = "";

                #region Client Product productItem Session Check

                var userClientSession = (AppSession)Session["_UserClientSession_"];
                if (userClientSession == null || userClientSession.ClientId < 1 || userClientSession.ProductId < 1 || userClientSession.ProductItemId < 1)
                {
                    return(RedirectToAction("Index", "Dashboard"));
                }
                var ClientId      = clientId ?? userClientSession.ClientId;
                var ProductId     = productId ?? userClientSession.ProductId;
                var ProductItemId = userClientSession.ProductItemId;

                #endregion

                #region Current user session check

                var userData = MvcApplication.GetUserData(User.Identity.Name);
                if (userData == null || userData.UserId < 1)
                {
                    ViewBag.Error = "Session Has Expired! Please Re-Login";
                    return(View(new List <WorkflowTaskObj>()));
                }


                #endregion

                #region get the pending and updated tasks from workflow task endpoint


                var searchObj = new WorkflowTaskSearchObj
                {
                    AdminUserId    = userData.UserId,
                    WorkflowTaskId = 0,
                    Status         = -2
                };
                var retVal = WorkflowTaskServices.LoadWorkflowTasks(searchObj, userData.Username);

                #endregion

                #region get some requisition properties from endpoint or session

                if (Session["_AExpenseRequisitionList_"] is List <ExpenseRequisitionObj> ExpenseRequisitionList && ExpenseRequisitionList.Any())
                {
                    Session["_AExpenseRequisitionList_"] = ExpenseRequisitionList.Where(s => s.ClientId == ClientId && s.ProductId == ProductId).ToList();
                }
                else
                {
                    var searchObjReq = new ExpenseRequisitionSearchObj
                    {
                        AdminUserId          = userData.UserId,
                        ExpenseRequisitionId = 0,
                        Status = -1000
                    };
                    var searchObjForReqs = ExpenseLookupServices.LoadExpenseRequisitions(searchObjReq, userData.Username).ExpenseRequisitions.Where(s => s.ClientId == ClientId && s.ProductId == ProductId);
                    var reqitems         = searchObjForReqs.OrderBy(m => m.ExpenseRequisitionId).ToList();
                    Session["_AExpenseRequisitionList_"] = reqitems.ToList();
                }

                #endregion

                #region response validations

                if (retVal?.Status == null)
                {
                    ViewBag.Error = " WorkflowTask list is empty!";
                    return(View(new List <WorkflowTaskObj>()));
                }

                if (!retVal.Status.IsSuccessful)
                {
                    ViewBag.Error = string.IsNullOrEmpty(retVal.Status.Message.FriendlyMessage)
                        ? "  WorkflowTask list is empty!"
                        : retVal.Status.Message.FriendlyMessage;
                    return(View(new List <WorkflowTaskObj>()));
                }
                if (retVal.WorkflowTasks == null || !retVal.WorkflowTasks.Any())
                {
                    ViewBag.Error = " WorkflowTask list is empty!";
                    return(View(new List <WorkflowTaskObj>()));
                }

                #endregion

                #region filtering task list

                var WorkflowTasks         = retVal.WorkflowTasks.OrderBy(m => m.WorkflowTaskId).Where(m => m.Status == (int)TaskStatus.Pending || m.Status == (int)TaskStatus.Viewed);
                var taskBasedOnClientProd = WorkflowTasks.Where(m => m.ClientId == ClientId && m.ProductId == ProductId);
                var taskBasedOnAssignee   = taskBasedOnClientProd.Where(x => x.AssigneeId == userData.UserId).ToList();

                #endregion

                return(View(taskBasedOnAssignee));
            }
            catch (Exception ex)
            {
                ViewBag.Error = ex.Message;
                UtilTools.LogE(ex.StackTrace, ex.Source, ex.Message);
                return(View(new List <WorkflowTaskObj>()));
            }
        }