Ejemplo n.º 1
0
        public static BeneficiaryRegRespObj AddBeneficiary(RegBeneficiaryObj regObj, string username)
        {
            var response = new BeneficiaryRegRespObj
            {
                Status = new APIResponseStatus
                {
                    IsSuccessful = false,
                    Message      = new APIResponseMessage(),
                },
            };

            try
            {
                var apiResponse = new APIHelper(APIEndpoints.ADD_BENEFICIARY_ENDPOINT, username, Method.POST).ProcessAPI <RegBeneficiaryObj, BeneficiaryRegRespObj>(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);
            }
        }
        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" }));
            }
        }