public JsonResult ProcessEditBeneficiaryRequest(BeneficiaryObj model)
        {
            try
            {
                #region Current User Session Check

                var userData = MvcApplication.GetUserData(User.Identity.Name) ?? new UserData();

                if (userData.UserId < 1)
                {
                    return(Json(new { IsSuccessful = false, Error = "Your session has expired", IsAuthenticated = false }));
                }

                #endregion

                #region Model Validations

                var selBeneficiary = Session["_CurrentSelBeneficiary_"] as BeneficiaryObj;
                if (selBeneficiary == null || selBeneficiary.BeneficiaryId < 1)
                {
                    return(Json(new { IsSuccessful = false, Error = "Your session has expired", IsAuthenticated = false }));
                }

                if (model.ClientId < 1)
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "Client required " }));
                }
                if (model.BeneficiaryId < 1)
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "BeneficiaryId required" }));
                }

                var previousBeneficiaryList = (List <BeneficiaryObj>)Session["_BeneficiaryList_"];
                if (previousBeneficiaryList != null)
                {
                    if (previousBeneficiaryList.Count(x => x.CompanyName.ToLower().Trim().ToStandardHash() == model.CompanyName.ToLower().Trim().ToStandardHash() &&
                                                      x.ProductId == model.ProductId &&
                                                      x.FirstName == model.FirstName &&
                                                      x.LastName == model.LastName &&
                                                      x.ClientId == model.ClientId &&
                                                      x.ProductItemId == model.ProductItemId &&
                                                      x.BeneficiaryId != model.BeneficiaryId) > 0)
                    {
                        return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "Beneficiary Already Exist!" }));
                    }
                }

                #endregion

                #region Build Object
                var passObj = new EditBeneficiaryObj()
                {
                    ClientId        = model.ClientId,
                    ProductId       = model.ProductId,
                    AdminUserId     = userData.UserId,
                    Status          = model.StatusVal ? 1 : 0,
                    ProductItemId   = model.ProductItemId,
                    MiddleName      = model.MiddleName,
                    FirstName       = model.FirstName,
                    LastName        = model.LastName,
                    CompanyName     = model.CompanyName,
                    BeneficiaryCode = "23flave23",
                    BeneficiaryType = model.BeneficiaryType,
                    DepartmentId    = model.DepartmentId,
                    Email           = model.Email,
                    MobileNumber    = model.MobileNumber,
                    BeneficiaryId   = model.BeneficiaryId,
                };
                #endregion

                #region Response Validations

                if (!GenericVal.Validate(model, out var msg))
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = $"Validation Error Occurred! Detail: {msg}" }));
                }


                var response = BeneficiaryServices.UpdateBeneficiary(passObj, userData.Username);
                if (response?.Status == null)
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "Error Occurred! Please try again later" }));
                }

                if (!response.Status.IsSuccessful)
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = string.IsNullOrEmpty(response.Status.Message.TechnicalMessage) ? "Process Failed! Unable to add course of study" : response.Status.Message.TechnicalMessage }));
                }


                #endregion

                Session["_CurrentSelBeneficiary_"] = null;

                #region Request and Response Validation

                var searchObj = new BeneficiarySearchObj
                {
                    AdminUserId   = userData.UserId,
                    BeneficiaryId = 0,
                    Status        = -2
                };

                ViewBag.ClientId      = model.ClientId;
                ViewBag.ProductId     = model.ProductId;
                ViewBag.ProductItemId = model.ProductItemId;

                var retVal = BeneficiaryServices.LoadBeneficiaries(searchObj, userData.Username);
                if (retVal?.Status != null && retVal.Beneficiaries != null)
                {
                    var Beneficiarys = retVal.Beneficiaries.OrderBy(m => m.BeneficiaryId).ToList();
                    Session["_BeneficiaryList_"] = Beneficiarys;
                }

                #endregion

                return(Json(new { IsAuthenticated = true, IsSuccessful = true, IsReload = false, Error = "" }));
            }
            catch (Exception ex)
            {
                UtilTools.LogE(ex.StackTrace, ex.Source, ex.Message);
                return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "Process Error Occurred! Please try again later" }));
            }
        }
        public JsonResult ProcessAddBeneficiaryRequest(RegBeneficiaryObj model)
        {
            try
            {
                #region Current User Session Check
                var userData = MvcApplication.GetUserData(User.Identity.Name) ?? new UserData();
                if (userData.UserId < 1)
                {
                    return(Json(new { IsSuccessful = false, Error = "Your session has expired", IsAuthenticated = false }));
                }
                #endregion

                #region Model Validations
                if (model == null)
                {
                    return(Json(new { IsSuccessful = false, Error = "Your session has expired", IsAuthenticated = false }));
                }

                if (model.ClientId < 1)
                {
                    return(Json(new { isauthenticated = true, issuccessful = false, isreload = false, error = "client required " }));
                }

                if (model.ProductItemId < 1)
                {
                    return(Json(new { isauthenticated = true, issuccessful = false, isreload = false, error = "Product Item required " }));
                }

                if (model.ProductId < 1)
                {
                    return(Json(new { isauthenticated = true, issuccessful = false, isreload = false, error = "Product required " }));
                }
                if (string.IsNullOrEmpty(model.FirstName) || model.FirstName.Length < 0 || string.IsNullOrEmpty(model.FirstName) || model.FirstName.Length < 0)
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = " First Name and Last Name required" }));
                }

                if (string.IsNullOrEmpty(model.Email) || model.Email.Length < 2)
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "Email is required" }));
                }
                #endregion

                #region Check If Item Exists from Session

                var previousBeneficiaryList = (List <BeneficiaryObj>)Session["_BeneficiaryList_"];
                if (previousBeneficiaryList != null)
                {
                    if (previousBeneficiaryList.Count(x => x.CompanyName.ToLower().Trim().ToStandardHash() == model.CompanyName.ToLower().Trim().ToStandardHash() &&
                                                      x.ProductId == model.ProductId &&
                                                      x.FirstName == model.FirstName &&
                                                      x.LastName == model.LastName &&
                                                      x.ClientId == model.ClientId &&
                                                      x.ProductItemId == model.ProductItemId) > 0)
                    {
                        return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "Beneficiary Already Exist!" }));
                    }
                }

                #endregion

                #region Build Object Request

                var requestObj = new RegBeneficiaryObj
                {
                    ClientId        = model.ClientId,
                    ProductId       = model.ProductId,
                    AdminUserId     = userData.UserId,
                    Status          = 1,
                    ProductItemId   = model.ProductItemId,
                    MiddleName      = model.MiddleName,
                    FirstName       = model.FirstName,
                    LastName        = model.LastName,
                    CompanyName     = model.CompanyName,
                    BeneficiaryCode = "23flave23",
                    BeneficiaryType = model.BeneficiaryType,
                    DepartmentId    = model.DepartmentId,
                    Email           = model.Email,
                    MobileNumber    = model.MobileNumber,
                };
                #endregion

                #region Request Response and Validations

                var response = BeneficiaryServices.AddBeneficiary(requestObj, userData.Username);
                if (response?.Status == null)
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "Error Occurred! Please try again later" }));
                }

                if (!response.Status.IsSuccessful)
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = string.IsNullOrEmpty(response.Status.Message.TechnicalMessage) ? "Process Failed! Unable to add nomination Source" : response.Status.Message.TechnicalMessage }));
                }


                var searchObj = new BeneficiarySearchObj
                {
                    AdminUserId   = userData.UserId,
                    BeneficiaryId = 0,
                    Status        = -2
                };

                var retVal = BeneficiaryServices.LoadBeneficiaries(searchObj, userData.Username);
                if (retVal?.Status != null && retVal.Beneficiaries != null)
                {
                    var Beneficiarys = retVal.Beneficiaries.OrderBy(m => m.BeneficiaryId).ToList();
                    Session["_BeneficiaryList_"] = Beneficiarys;
                }

                #endregion

                return(Json(new { IsAuthenticated = true, IsSuccessful = true, IsReload = false, Error = "" }));
            }
            catch (Exception ex)
            {
                UtilTools.LogE(ex.StackTrace, ex.Source, ex.Message);
                return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "Process Error Occurred! Please try again later" }));
            }
        }
        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 <BeneficiaryObj>()));
                }

                #endregion

                #region Check if Benficiary List is  null else return to view

                if (Session["_BeneficiaryList_"] is List <BeneficiaryObj> Beneficiary && Beneficiary.Any())
                {
                    var clientProdbeneficiaryList = Beneficiary.Where(m => m.ClientId == ClientId && m.ProductId == ProductId && m.ProductItemId == ProductItemId).ToList();
                    return(View(clientProdbeneficiaryList));
                }

                #endregion

                #region Request Response and validation Checks

                var searchObj = new BeneficiarySearchObj
                {
                    AdminUserId   = userData.UserId,
                    BeneficiaryId = 0,
                    Status        = -2
                };
                var retVal = BeneficiaryServices.LoadBeneficiaries(searchObj, userData.Username);
                if (retVal?.Status == null)
                {
                    ViewBag.Error = " Beneficiary list is empty!";
                    return(View(new List <BeneficiaryObj>()));
                }

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

                #endregion

                #region Send Client Product ProductItem To View
                var clientBeneficiaries = retVal.Beneficiaries.OrderBy(m => m.BeneficiaryId)
                                          .Where(m => m.ClientId == ClientId && m.ProductId == ProductId)
                                          .ToList();

                Session["_BeneficiaryList_"] = clientBeneficiaries;

                var clientBeneList = clientBeneficiaries.Where(m => m.ClientId == ClientId && m.ProductId == ProductId).ToList();

                #endregion

                return(View(clientBeneList));
            }
            catch (Exception ex)
            {
                ViewBag.Error = ex.Message;
                UtilTools.LogE(ex.StackTrace, ex.Source, ex.Message);
                return(View(new List <BeneficiaryObj>()));
            }
        }
예제 #4
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()));
            }
        }