Exemple #1
0
        // POST: api/ForgotPasswordDetails
        public async Task <HttpResponseMessage> Post([FromBody] ForgotPasswordDetails value)
        {
            try
            {
                ForgotPasswordDetailsRef FgDetailsRef = new ForgotPasswordDetailsRef();
                ForgotPasswordClass      fgClass      = new ForgotPasswordClass();
                var    authorization = Request.Headers.Authorization;
                string UserName      = string.Empty;
                if (authorization == null || authorization.Scheme != "Bearer")
                {
                    return(Request.CreateResponse <ForgotPasswordDetailsRef>(HttpStatusCode.BadRequest, FgDetailsRef));
                }

                if (string.IsNullOrEmpty(authorization.Parameter))
                {
                    return(Request.CreateResponse <ForgotPasswordDetailsRef>(HttpStatusCode.BadRequest, FgDetailsRef));
                }
                var  token   = authorization.Parameter;
                bool strbool = CommonUseFunctionClass.ValidateToken(token, out UserName);
                if (strbool == true)
                {
                    FgDetailsRef = await fgClass.GetFogotPasswordDetails(value.Email, value.Password, value.ConfirmPassword, value.reCaptcha);

                    if (FgDetailsRef != null)
                    {
                        return(Request.CreateResponse <ForgotPasswordDetailsRef>(HttpStatusCode.OK, FgDetailsRef));
                    }
                    else
                    {
                        FgDetailsRef.Status = "Failure";
                        return(Request.CreateResponse <ForgotPasswordDetailsRef>(HttpStatusCode.BadRequest, FgDetailsRef));
                    }
                }
                else
                {
                    FgDetailsRef.Status = "Failure";
                    FgDetailsRef.ErrorMessage.Add("Token Is Not valid");
                    return(Request.CreateResponse <ForgotPasswordDetailsRef>(HttpStatusCode.BadRequest, FgDetailsRef));
                }
            }
            catch (Exception xp)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, xp.Message));
            }
            finally
            {
            }
            return(null);
        }
Exemple #2
0
        //  private const string Secret = "db3OIsj+BXE9NZDy0t8W3TcNekrF+2d/1sFnWG4HnV8TZY30iTOdtVWJG8abWvB1GlOgJuQZdcF2Luqm/hccMw==";
        //public static string GenerateToken(string username, int expireMinutes = 20)
        //{
        //    var symmetricKey = Convert.FromBase64String(Secret);
        //    var tokenHandler = new JwtSecurityTokenHandler();

        //    var now = DateTime.UtcNow;
        //    var tokenDescriptor = new SecurityTokenDescriptor
        //    {
        //        Subject = new ClaimsIdentity(new[]
        //                {
        //                new Claim(ClaimTypes.Name, username)
        //            }),

        //        Expires = now.AddMinutes(Convert.ToInt32(expireMinutes)),

        //        SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(symmetricKey), SecurityAlgorithms.HmacSha256Signature)
        //    };

        //    var stoken = tokenHandler.CreateToken(tokenDescriptor);
        //    var token = tokenHandler.WriteToken(stoken);

        //    return token;
        //}

        //public bool CheckUser(string username, int password)
        //{
        //    try
        //    {
        //        LoginDetailsRef loginRef = new LoginDetailsRef();
        //        LogInDetailsClass logincls = new LogInDetailsClass();
        //        loginRef = logincls.GetLogInDetailsPage(username, password);
        //        if (loginRef.LogInData.UserName.Trim() != string.Empty || loginRef.LogInData.Password.Value != 0 || string.IsNullOrWhiteSpace(Convert.ToString(loginRef.LogInData.Password).Trim()))
        //        {
        //            return true;
        //        }
        //        else
        //        {
        //            return false;
        //        }
        //    }
        //    catch (Exception xp)
        //    {

        //    }
        //    finally
        //    {

        //    }
        //    return false;
        //}



        #endregion



        // POST: api/LogInDetails
        //public void Post([FromBody]string value)
        //{

        //}

        #region Token Validation Method

        //private static bool ValidateToken(string token, out string username)
        //{
        //    username = null;
        //    var simplePrinciple = GetPrincipal(token);
        //    var identity = simplePrinciple.Identity as ClaimsIdentity;

        //    if (identity == null)
        //        return false;

        //    if (!identity.IsAuthenticated)
        //        return false;

        //    var usernameClaim = identity.FindFirst(ClaimTypes.Name);
        //    username = usernameClaim?.Value;

        //    if (string.IsNullOrEmpty(username))
        //        return false;

        //    // More validate to check whether username exists in system

        //    return true;
        //}

        //protected Task<IPrincipal> AuthenticateJwtToken(string token)
        //{
        //    string username;
        //    if (ValidateToken(token, out username))
        //    {
        //        // based on username to get more information from database in order to build local identity
        //        var claims = new List<Claim>
        //    {
        //        new Claim(ClaimTypes.Name, username)
        //        // Add more claims if needed: Roles, ...
        //    };
        //        var identity = new ClaimsIdentity(claims, "Jwt");
        //        IPrincipal user = new ClaimsPrincipal(identity);
        //        return Task.FromResult(user);
        //    }
        //    return Task.FromResult<IPrincipal>(null);
        //}

        //public static ClaimsPrincipal GetPrincipal(string token)
        //{
        //    try
        //    {
        //        var tokenHandler = new JwtSecurityTokenHandler();
        //        var jwtToken = tokenHandler.ReadToken(token) as JwtSecurityToken;

        //        if (jwtToken == null)
        //            return null;

        //        var symmetricKey = Convert.FromBase64String(Secret);

        //        var validationParameters = new TokenValidationParameters()
        //        {
        //            RequireExpirationTime = true,
        //            ValidateIssuer = false,
        //            ValidateAudience = false,
        //            IssuerSigningKey = new SymmetricSecurityKey(symmetricKey)
        //        };

        //        SecurityToken securityToken;
        //        var principal = tokenHandler.ValidateToken(token, validationParameters, out securityToken);

        //        return principal;
        //    }
        //    catch (Exception xp)
        //    {
        //        //should write log
        //        return null;
        //    }
        //}

        #endregion

        // PUT: api/LogInDetails/5
        public HttpResponseMessage Put(int id, [FromBody] string value)
        {
            LoginDetailsRef loginref = new LoginDetailsRef();

            try
            {
                var    authorization = Request.Headers.Authorization;
                string UserName      = string.Empty;
                if (authorization == null || authorization.Scheme != "Bearer")
                {
                    return(Request.CreateResponse <LoginDetailsRef>(HttpStatusCode.BadRequest, loginref));
                }

                if (string.IsNullOrEmpty(authorization.Parameter))
                {
                    // context.ErrorResult = new AuthenticationFailureResult("Missing Jwt Token", request);
                    return(Request.CreateResponse <LoginDetailsRef>(HttpStatusCode.BadRequest, loginref));
                }

                var token = authorization.Parameter;

                bool strbool = CommonUseFunctionClass.ValidateToken(token, out UserName);

                if (strbool == true)
                {
                    loginref.Status = "Success";
                    return(Request.CreateResponse <LoginDetailsRef>(HttpStatusCode.OK, loginref));
                }
                else
                {
                    loginref.Status = "Failure";
                    return(Request.CreateResponse <LoginDetailsRef>(HttpStatusCode.BadRequest, loginref));
                }
            }
            catch (Exception xp)
            {
                loginref.Status = "Failure";
                return(Request.CreateResponse <LoginDetailsRef>(HttpStatusCode.BadRequest, loginref));
            }
            finally
            {
            }
            return(null);
        }
        public async System.Threading.Tasks.Task <ActionResult> TravelCover(int?cid, int?PcId)
        {
            string apikey = null;

            if (Session["ApiKey"] != null)
            {
                apikey = Session["ApiKey"].ToString();
            }
            else
            {
                return(RedirectToAction("AgentLogin", "Login"));
            }
            var                    Policyincllist = Session["Policyinclustions"] as List <SessionModel>;
            TravelCover            TravelCover    = new TravelCover();
            CommonUseFunctionClass cmn            = new CommonUseFunctionClass();

            TravelCover.NewSections = new List <string>();
            if (Session["Policyinclustions"] != null)
            {
                List <SessionModel> PolicyInclustions = new List <SessionModel>();
                TravelCover.PolicyInclusions = new List <SessionModel>();
                TravelCover.PolicyInclusions = Policyincllist;
                TravelCover.NewSections      = cmn.NewSectionHome(TravelCover.PolicyInclusions);
                if (Policyincllist != null)
                {
                    if (Policyincllist.Exists(p => p.name == "Travel"))
                    {
                        if (Session["unId"] == null && Session["profileId"] == null)
                        {
                            Session["unId"]      = Policyincllist.Where(p => p.name == "Travel").Select(p => p.UnitId).First();
                            Session["profileId"] = Policyincllist.Where(p => p.name == "Travel").Select(p => p.ProfileId).First();
                        }
                    }
                    else
                    {
                        return(RedirectToAction("DisclosureDetails", "Disclosure", new { cid = cid, PcId = PcId }));
                    }
                }
            }
            else
            {
                RedirectToAction("PolicyInclustions", "Customer", new { cid = cid });
            }
            NewPolicyDetailsClass Tmodel = new NewPolicyDetailsClass();

            if (cid != null && cid.HasValue && cid > 0)
            {
                ViewBag.cid            = cid;
                TravelCover.CustomerId = cid.Value;
            }
            List <SelectListItem> ExcTcList = new List <SelectListItem>();

            ExcTcList = Tmodel.excessRate();
            var db = new MasterDataEntities();

            TravelCover.PolicyInclusion = new List <usp_GetUnit_Result>();
            ViewEditPolicyDetails unitdetails = new ViewEditPolicyDetails();
            var policyinclusions = db.usp_GetUnit(null, PcId, null).ToList();

            TravelCover.TravellerscoveredObj      = new TravellersToBeCovered();
            TravelCover.TravellerscoveredObj.EiId = 61429;
            TravelCover.DataofbirthObj            = new DataOfBirthsTC();
            TravelCover.DataofbirthObj.EiId       = 61431;
            TravelCover.NumbertravelersObj        = new NumberOfTravelers();
            TravelCover.NumbertravelersObj.EiId   = 61433;
            TravelCover.YourtripObj                = new YourTrips();
            TravelCover.YourtripObj.EiId           = 61437;
            TravelCover.WintersportObj             = new WinterSports();
            TravelCover.WintersportObj.EiId        = 61441;
            TravelCover.ExcessObj                  = new ExcessesTC();
            TravelCover.ExcessObj.EiId             = 61443;
            TravelCover.ExcessObj.ExcessList       = ExcTcList;
            TravelCover.TravellerscoveredGObj      = new TravellersToBeCoveredG();
            TravelCover.TravellerscoveredGObj.EiId = 61463;
            TravelCover.DataofbirthGObj            = new DataOfBirthsTCG();
            TravelCover.DataofbirthGObj.EiId       = 61465;
            string     policyid        = null;
            bool       policyinclusion = policyinclusions.Exists(p => p.Name == "Travel");
            HttpClient hclient         = new HttpClient();
            string     url             = System.Configuration.ConfigurationManager.AppSettings["APIURL"];

            hclient.BaseAddress = new Uri(url);
            hclient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            int unid      = 0;
            int profileid = 0;

            if (Session["unId"] != null && Session["profileId"] != null)
            {
                unid      = Convert.ToInt32(Session["unId"]);
                profileid = Convert.ToInt32(Session["profileId"]);
            }
            if (PcId != null && PcId.HasValue)
            {
                TravelCover.ExistingPolicyInclustions = policyinclusions;
                TravelCover.PolicyInclusion           = policyinclusions;
                TravelCover.NewSections = cmn.NewSectionP(policyinclusions);
                if (Session["unId"] != null && Session["profileId"] != null)
                {
                    unid      = Convert.ToInt32(Session["unId"]);
                    profileid = Convert.ToInt32(Session["profileId"]);
                }
                else
                {
                    return(RedirectToAction("DisclosureDetails", "Disclosure", new { cid = cid, PcId = PcId }));
                }
                //int sectionId = policyinclusions.Where(p => p.Name == "Home Contents" && p.UnitNumber == unid).Select(p => p.UnId).FirstOrDefault();
                //int? profileunid = policyinclusions.Where(p => p.Name == "Home Contents" && p.ProfileUnId == profileid).Select(p => p.ProfileUnId).FirstOrDefault();
                HttpResponseMessage getunit = await hclient.GetAsync("UnitDetails?ApiKey=" + apikey + "&Action=Existing&SectionName=&SectionUnId=" + unid + "&ProfileUnId=" + profileid);

                var EmpResponse = getunit.Content.ReadAsStringAsync().Result;
                if (EmpResponse != null)
                {
                    unitdetails = JsonConvert.DeserializeObject <ViewEditPolicyDetails>(EmpResponse);
                }
            }
            else
            {
                if (PcId == null && Session["unId"] == null && Session["profileId"] == null)
                {
                    HttpResponseMessage Res = await hclient.GetAsync("UnitDetails?ApiKey=" + apikey + "&Action=New&SectionName=Travel&SectionUnId=&ProfileUnId=");

                    var EmpResponse = Res.Content.ReadAsStringAsync().Result;
                    if (EmpResponse != null)
                    {
                        unitdetails = JsonConvert.DeserializeObject <ViewEditPolicyDetails>(EmpResponse);
                        if (unitdetails.ErrorMessage != null && unitdetails.ErrorMessage.Count() > 0)
                        {
                            bool exists = TravelCover.PolicyInclusions.Exists(p => p.name == "Travel");
                            if (exists == true)
                            {
                                List <SessionModel> values = new List <SessionModel>();
                                values = (List <SessionModel>)Session["Policyinclustions"];
                                for (int k = 0; k < values.Count(); k++)
                                {
                                    if (values[k].name == "Travel" && values[k].UnitId == null && values[k].ProfileId == null)
                                    {
                                        values.RemoveAt(k);
                                    }
                                }
                                Session["Policyinclustions"] = values;
                            }
                            var errormessage = "First please provide cover for Home Buildings.";
                            if (unitdetails.ErrorMessage.Contains(errormessage))
                            {
                                TempData["Error"] = errormessage;
                                return(RedirectToAction("HomeDescription", "RuralLifeStyle", new { cid = cid, PcId = PcId }));
                            }
                        }
                        if (unitdetails != null && unitdetails.SectionData != null)
                        {
                            Session["unId"]      = unitdetails.SectionData.UnId;
                            Session["profileId"] = unitdetails.SectionData.ProfileUnId;
                            if (Policyincllist != null && Policyincllist.Exists(p => p.name == "Travel"))
                            {
                                var policyhomelist = Policyincllist.FindAll(p => p.name == "Travel").ToList();
                                if (policyhomelist != null && policyhomelist.Count() > 0)
                                {
                                    if (Policyincllist.FindAll(p => p.name == "Travel").Exists(p => p.UnitId == null))
                                    {
                                        Policyincllist.FindAll(p => p.name == "Travel").Where(p => p.UnitId == null).First().UnitId = unitdetails.SectionData.UnId;
                                    }
                                    if (Policyincllist.FindAll(p => p.name == "Travel").Exists(p => p.ProfileId == null))
                                    {
                                        Policyincllist.FindAll(p => p.name == "Travel").Where(p => p.ProfileId == null).First().ProfileId = unitdetails.SectionData.ProfileUnId;
                                    }
                                }
                                else
                                {
                                    Policyincllist.FindAll(p => p.name == "Travel").First().UnitId    = unitdetails.SectionData.UnId;
                                    Policyincllist.FindAll(p => p.name == "Travel").First().ProfileId = unitdetails.SectionData.ProfileUnId;
                                }
                                TravelCover.PolicyInclusions = Policyincllist;
                                Session["Policyinclustions"] = Policyincllist;
                            }
                        }
                    }
                }
                else if (PcId == null && Session["unId"] != null && Session["profileId"] != null)
                {
                    HttpResponseMessage getunit = await hclient.GetAsync("UnitDetails?ApiKey=" + apikey + "&Action=Existing&SectionName=&SectionUnId=" + unid + "&ProfileUnId=" + profileid);

                    var EmpResponse = getunit.Content.ReadAsStringAsync().Result;
                    if (EmpResponse != null)
                    {
                        unitdetails = JsonConvert.DeserializeObject <ViewEditPolicyDetails>(EmpResponse);
                        if (unitdetails != null && unitdetails.SectionData != null)
                        {
                            Session["unId"]      = unitdetails.SectionData.UnId;
                            Session["profileId"] = unitdetails.SectionData.ProfileUnId;
                        }
                    }
                }
            }
            if (unitdetails != null)
            {
                if (unitdetails.SectionData != null && unitdetails.SectionData.ValueData != null)
                {
                    if (unitdetails.SectionData.ValueData.Exists(p => p.Element.ElId == TravelCover.DataofbirthObj.EiId))
                    {
                        string val = unitdetails.SectionData.ValueData.Where(p => p.Element.ElId == TravelCover.DataofbirthObj.EiId).Select(p => p.Value).FirstOrDefault();
                        TravelCover.DataofbirthObj.Dataofbirth = val;
                    }
                    if (unitdetails.SectionData.ValueData.Exists(p => p.Element.ElId == TravelCover.ExcessObj.EiId))
                    {
                        string val = unitdetails.SectionData.ValueData.Where(p => p.Element.ElId == TravelCover.ExcessObj.EiId).Select(p => p.Value).FirstOrDefault();
                        TravelCover.ExcessObj.Excess = val;
                    }
                    if (unitdetails.SectionData.ValueData.Exists(p => p.Element.ElId == TravelCover.TravellerscoveredObj.EiId))
                    {
                        string val = unitdetails.SectionData.ValueData.Where(p => p.Element.ElId == TravelCover.TravellerscoveredObj.EiId).Select(p => p.Value).FirstOrDefault();
                        if (val != null && !string.IsNullOrEmpty(val))
                        {
                            TravelCover.TravellerscoveredObj.Travellerscovered = val;
                        }
                        if (unitdetails.SectionData.ValueData.Select(p => p.Element.ElId == TravelCover.TravellerscoveredObj.EiId).Count() > 1)
                        {
                            List <ValueDatas> elmnts  = new List <ValueDatas>();
                            var TravellerscoveredList = unitdetails.SectionData.ValueData.Where(p => p.Element.ElId == TravelCover.TravellerscoveredObj.EiId).Select(p => p.Element.ItId).ToList();
                            for (int i = 0; i < TravellerscoveredList.Count(); i++)
                            {
                                ValueDatas vds = new ValueDatas();
                                vds.Element      = new Elements();
                                vds.Element.ElId = 61429;
                                vds.Element.ItId = TravellerscoveredList[i];
                                vds.Value        = unitdetails.SectionData.ValueData.Where(p => p.Element.ElId == TravelCover.TravellerscoveredObj.EiId && p.Element.ItId == TravellerscoveredList[i]).Select(p => p.Value).FirstOrDefault();
                                elmnts.Add(vds);
                            }
                            TravelCover.TravellerscoveredObjList = elmnts;
                        }
                    }
                    if (unitdetails.SectionData.ValueData.Exists(p => p.Element.ElId == TravelCover.DataofbirthObj.EiId))
                    {
                        string val = unitdetails.SectionData.ValueData.Where(p => p.Element.ElId == TravelCover.DataofbirthObj.EiId).Select(p => p.Value).FirstOrDefault();
                        if (val != null && !string.IsNullOrEmpty(val))
                        {
                            TravelCover.DataofbirthObj.Dataofbirth = val;
                        }
                        if (unitdetails.SectionData.ValueData.Select(p => p.Element.ElId == TravelCover.DataofbirthObj.EiId).Count() > 1)
                        {
                            List <ValueDatas> elmnts = new List <ValueDatas>();
                            var DataofbirthList      = unitdetails.SectionData.ValueData.Where(p => p.Element.ElId == TravelCover.DataofbirthObj.EiId).Select(p => p.Element.ItId).ToList();
                            for (int i = 0; i < DataofbirthList.Count(); i++)
                            {
                                ValueDatas vds = new ValueDatas();
                                vds.Element      = new Elements();
                                vds.Element.ElId = 61431;
                                vds.Element.ItId = DataofbirthList[i];
                                vds.Value        = unitdetails.SectionData.ValueData.Where(p => p.Element.ElId == TravelCover.DataofbirthObj.EiId && p.Element.ItId == DataofbirthList[i]).Select(p => p.Value).FirstOrDefault();
                                elmnts.Add(vds);
                            }
                            TravelCover.DataofbirthObjList = elmnts;
                        }
                    }
                    if (unitdetails.SectionData.ValueData.Exists(p => p.Element.ElId == TravelCover.TravellerscoveredGObj.EiId))
                    {
                        string val = unitdetails.SectionData.ValueData.Where(p => p.Element.ElId == TravelCover.TravellerscoveredGObj.EiId).Select(p => p.Value).FirstOrDefault();
                        if (val != null && !string.IsNullOrEmpty(val))
                        {
                            TravelCover.TravellerscoveredGObj.Travellerscovered = val;
                        }
                        if (unitdetails.SectionData.ValueData.Select(p => p.Element.ElId == TravelCover.TravellerscoveredGObj.EiId).Count() > 1)
                        {
                            List <ValueDatas> elmnts   = new List <ValueDatas>();
                            var TravellerscoveredGList = unitdetails.SectionData.ValueData.Where(p => p.Element.ElId == TravelCover.TravellerscoveredGObj.EiId).Select(p => p.Element.ItId).ToList();
                            for (int i = 0; i < TravellerscoveredGList.Count(); i++)
                            {
                                ValueDatas vds = new ValueDatas();
                                vds.Element      = new Elements();
                                vds.Element.ElId = 61463;
                                vds.Element.ItId = TravellerscoveredGList[i];
                                vds.Value        = unitdetails.SectionData.ValueData.Where(p => p.Element.ElId == TravelCover.TravellerscoveredGObj.EiId && p.Element.ItId == TravellerscoveredGList[i]).Select(p => p.Value).FirstOrDefault();
                                elmnts.Add(vds);
                            }
                            TravelCover.TravellerscoveredGObjList = elmnts;
                        }
                    }
                    if (unitdetails.SectionData.ValueData.Exists(p => p.Element.ElId == TravelCover.DataofbirthGObj.EiId))
                    {
                        string val = unitdetails.SectionData.ValueData.Where(p => p.Element.ElId == TravelCover.DataofbirthGObj.EiId).Select(p => p.Value).FirstOrDefault();
                        if (val != null && !string.IsNullOrEmpty(val))
                        {
                            TravelCover.DataofbirthGObj.Dataofbirth = val;
                        }
                        if (unitdetails.SectionData.ValueData.Select(p => p.Element.ElId == TravelCover.DataofbirthGObj.EiId).Count() > 1)
                        {
                            List <ValueDatas> elmnts = new List <ValueDatas>();
                            var DataofbirthGList     = unitdetails.SectionData.ValueData.Where(p => p.Element.ElId == TravelCover.DataofbirthGObj.EiId).Select(p => p.Element.ItId).ToList();
                            for (int i = 0; i < DataofbirthGList.Count(); i++)
                            {
                                ValueDatas vds = new ValueDatas();
                                vds.Element      = new Elements();
                                vds.Element.ElId = 61465;
                                vds.Element.ItId = DataofbirthGList[i];
                                vds.Value        = unitdetails.SectionData.ValueData.Where(p => p.Element.ElId == TravelCover.DataofbirthGObj.EiId && p.Element.ItId == DataofbirthGList[i]).Select(p => p.Value).FirstOrDefault();
                                elmnts.Add(vds);
                            }
                            TravelCover.DataofbirthGObjList = elmnts;
                        }
                    }
                    if (unitdetails.SectionData.ValueData.Exists(p => p.Element.ElId == TravelCover.TravellerscoveredObj.EiId))
                    {
                        string val = unitdetails.SectionData.ValueData.Where(p => p.Element.ElId == TravelCover.TravellerscoveredObj.EiId).Select(p => p.Value).FirstOrDefault();
                        TravelCover.TravellerscoveredObj.Travellerscovered = val;
                    }
                    if (unitdetails.SectionData.ValueData.Exists(p => p.Element.ElId == TravelCover.WintersportObj.EiId))
                    {
                        string val = unitdetails.SectionData.ValueData.Where(p => p.Element.ElId == TravelCover.WintersportObj.EiId).Select(p => p.Value).FirstOrDefault();
                        TravelCover.WintersportObj.Wintersport = val;
                    }
                    if (unitdetails.SectionData.ValueData.Exists(p => p.Element.ElId == TravelCover.YourtripObj.EiId))
                    {
                        string val = unitdetails.SectionData.ValueData.Where(p => p.Element.ElId == TravelCover.YourtripObj.EiId).Select(p => p.Value).FirstOrDefault();
                        TravelCover.YourtripObj.Yourtrip = val;
                    }
                }
            }

            if (unitdetails != null && unitdetails.ReferralList != null)
            {
                TravelCover.ReferralList = unitdetails.ReferralList;
                TravelCover.ReferralList.Replace("&nbsp;&nbsp;&nbsp;&nbsp", "");
                TravelCover.Referels = new List <string>();
                string[] delim = { "<br/>" };

                string[] spltd = TravelCover.ReferralList.Split(delim, StringSplitOptions.None);
                if (spltd != null && spltd.Count() > 0)
                {
                    for (int i = 0; i < spltd.Count(); i++)
                    {
                        TravelCover.Referels.Add(spltd[i].Replace("&nbsp;&nbsp;&nbsp;&nbsp", " "));
                    }
                }
            }
            if (cid != null)
            {
                TravelCover.CustomerId = cid.Value;
            }
            if (PcId != null && PcId > 0)
            {
                TravelCover.PcId = PcId;
            }
            Session["Controller"] = "Travel";
            Session["ActionName"] = "TravelCover";
            return(View(TravelCover));
        }
        public async System.Threading.Tasks.Task <ActionResult> Valuables(int?cid, int?PcId)
        {
            string                 apikey      = null;
            ValuablesHC            ValuablesHC = new ValuablesHC();
            CommonUseFunctionClass cmn         = new CommonUseFunctionClass();

            ValuablesHC.NewSections = new List <string>();
            if (Session["ApiKey"] != null)
            {
                apikey = Session["ApiKey"].ToString();
            }
            else
            {
                return(RedirectToAction("AgentLogin", "Login"));
            }
            var Policyincllist = Session["Policyinclustions"] as List <SessionModel>;

            if (Session["Policyinclustions"] != null)
            {
                ValuablesHC.PolicyInclusions = new List <SessionModel>();
                ValuablesHC.PolicyInclusions = Policyincllist;
                if (Policyincllist != null)
                {
                    //var Policyincllist = Session["Policyinclustions"] as List<SessionModel>;
                    // var Suburb = new List<KeyValuePair<string, string>>();
                    // List<SelectListItem> listItems = new List<SelectListItem>();
                    ValuablesHC.NewSections = cmn.NewSectionHome(ValuablesHC.PolicyInclusions);
                    if (Policyincllist != null)
                    {
                        if (Policyincllist.Exists(p => p.name == "Valuables"))
                        {
                        }
                        else if (Policyincllist.Exists(p => p.name == "Farm Property"))
                        {
                            return(RedirectToAction("FarmContents", "Farm", new { cid = cid }));
                        }
                        else if (Policyincllist.Exists(p => p.name == "Liability"))
                        {
                            return(RedirectToAction("LiabilityCover", "Liabilities", new { cid = cid }));
                        }
                        else if (Policyincllist.Exists(p => p.name == "Motor" || p.name == "Motors"))
                        {
                            return(RedirectToAction("VehicleDescription", "MotorCover", new { cid = cid }));
                        }
                        else if (Policyincllist.Exists(p => p.name == "Boat"))
                        {
                            return(RedirectToAction("BoatDetails", "Boat", new { cid = cid }));
                        }

                        else if (Policyincllist.Exists(p => p.name == "Pet" || p.name == "Pets"))
                        {
                            return(RedirectToAction("PetsCover", "Pets", new { cid = cid }));
                        }
                        else if (Policyincllist.Exists(p => p.name == "Travel"))
                        {
                            return(RedirectToAction("TravelCover", "Travel", new { cid = cid }));
                        }

                        if (Policyincllist.Exists(p => p.name == "Valuables"))
                        {
                            if (Session["unId"] == null && Session["profileId"] == null)
                            {
                                Session["unId"]      = Policyincllist.Where(p => p.name == "Valuables").Select(p => p.UnitId).First();
                                Session["profileId"] = Policyincllist.Where(p => p.name == "Valuables").Select(p => p.ProfileId).First();
                            }
                        }
                        else
                        {
                            return(RedirectToAction("DisclosureDetails", "Disclosure", new { cid = cid, PcId = PcId }));
                        }
                        //else
                        //{
                        //    return RedirectToAction("PremiumDetails", "Customer", new { cid = cid, PcId = PcId });
                        //}
                    }
                }
            }
            else
            {
                RedirectToAction("PolicyInclustions", "Customer", new { CustomerId = cid, type = 1029 });
            }
            MasterDataEntities    db      = new MasterDataEntities();
            NewPolicyDetailsClass HCmodel = new NewPolicyDetailsClass();
            List <SelectListItem> HCList  = new List <SelectListItem>();

            HCList = HCmodel.excessRate();
            ViewEditPolicyDetails unitdetails = new ViewEditPolicyDetails();
            var policyinclusions = db.usp_GetUnit(null, PcId, null).ToList();

            ValuablesHC.PolicyInclusion = new List <usp_GetUnit_Result>();
            if (PcId != null && PcId.HasValue && PcId > 0)
            {
                ValuablesHC.PolicyInclusion = policyinclusions;
            }
            //var suburblist = db.IT_Master_GetSuburbList().ToList();
            //ValuablesHC.SubUrb = suburblist.Where(s => !string.IsNullOrEmpty(s)).Select(s => new SelectListItem() { Text = s, Value = s }).ToList();
            if (cid != null)
            {
                ViewBag.cid            = cid;
                ValuablesHC.CustomerId = cid.Value;
            }
            else
            {
                ViewBag.cid = ValuablesHC.CustomerId;
            }
            ValuablesHC.AddressObj              = new Addresses();
            ValuablesHC.LocationObj             = new LocationNew();
            ValuablesHC.UnspecificObj           = new Unspecifics();
            ValuablesHC.UnspecificObj.EiId      = 60383;
            ValuablesHC.DescriptionObj          = new Descriptions();
            ValuablesHC.DescriptionObj.EiId     = 60391;
            ValuablesHC.SuminsuredObj           = new SumInsures();
            ValuablesHC.SuminsuredObj.EiId      = 60393;
            ValuablesHC.TotalcoverObj           = new TotalCovers();
            ValuablesHC.TotalcoverObj.EiId      = 0;
            ValuablesHC.ExcesspayObj            = new ExcessesPay();
            ValuablesHC.ExcesspayObj.ExcessList = HCList;
            ValuablesHC.ExcesspayObj.EiId       = 60399;
            string     policyid        = null;
            bool       policyinclusion = policyinclusions.Exists(p => p.Name == "Valuables");
            HttpClient hclient         = new HttpClient();
            string     url             = System.Configuration.ConfigurationManager.AppSettings["APIURL"];

            hclient.BaseAddress = new Uri(url);
            hclient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            if (PcId != null && PcId.HasValue)
            {
                int?unid      = null;
                int?profileid = null;
                if (Session["unId"] != null && Session["profileId"] != null)
                {
                    unid                 = Convert.ToInt32(Session["unId"]);
                    profileid            = Convert.ToInt32(Session["profileId"]);
                    Session["unId"]      = unid;
                    Session["profileId"] = profileid;
                }
                else
                {
                    if (policyinclusions.Exists(p => p.Name == "Valuables"))
                    {
                        unid      = policyinclusions.Where(p => p.Name == "Valuables").Select(p => p.UnId).FirstOrDefault();
                        profileid = policyinclusions.Where(p => p.Name == "Valuables").Select(p => p.UnId).FirstOrDefault();
                    }
                    else
                    {
                        return(RedirectToAction("FarmContents", "Farm", new { cid = cid, PcId = PcId }));
                    }
                }
                ValuablesHC.NewSections = cmn.NewSectionP(policyinclusions);
                if (unid == null || unid == 0)
                {
                    unid      = unitdetails.SectionData.UnId;
                    profileid = unitdetails.SectionData.ProfileUnId;
                }
                ValuablesHC.ExistingPolicyInclustions = policyinclusions;

                //int sectionId = policyinclusions.Where(p => p.Name == "Home Contents" && p.UnitNumber == unid).Select(p => p.UnId).FirstOrDefault();
                //int? profileunid = policyinclusions.Where(p => p.Name == "Home Contents" && p.ProfileUnId == profileid).Select(p => p.ProfileUnId).FirstOrDefault();
                HttpResponseMessage getunit = await hclient.GetAsync("UnitDetails?ApiKey=" + apikey + "&Action=Existing&SectionName=&SectionUnId=" + unid + "&ProfileUnId=" + profileid);

                var EmpResponse = getunit.Content.ReadAsStringAsync().Result;
                if (EmpResponse != null)
                {
                    unitdetails = JsonConvert.DeserializeObject <ViewEditPolicyDetails>(EmpResponse);
                }
            }
            else if (PcId == null && Session["unId"] != null && (Session["profileId"] != null))
            {
                int unid      = Convert.ToInt32(Session["unId"]);
                int profileid = Convert.ToInt32(Session["profileId"]);
                HttpResponseMessage getunit = await hclient.GetAsync("UnitDetails?ApiKey=" + apikey + "&Action=Existing&SectionName=&SectionUnId=" + unid + "&ProfileUnId=" + profileid);

                var EmpResponse = getunit.Content.ReadAsStringAsync().Result;
                if (EmpResponse != null)
                {
                    unitdetails = JsonConvert.DeserializeObject <ViewEditPolicyDetails>(EmpResponse);
                }
            }
            else
            {
                int HprofileId = -1;
                if (Session["HprofileId"] != null)
                {
                    HprofileId = Convert.ToInt32(Session["HprofileId"]);
                }
                HttpResponseMessage Res = await hclient.GetAsync("UnitDetails?ApiKey=" + apikey + "&Action=New&SectionName=Valuables&SectionUnId=&ProfileUnId=" + HprofileId);

                var EmpResponse = Res.Content.ReadAsStringAsync().Result;
                if (EmpResponse != null)
                {
                    unitdetails = JsonConvert.DeserializeObject <ViewEditPolicyDetails>(EmpResponse);
                    if (unitdetails.ErrorMessage != null && unitdetails.ErrorMessage.Count() > 0)
                    {
                        bool exists = ValuablesHC.PolicyInclusions.Exists(p => p.name == "Valuables");
                        if (exists == true)
                        {
                            List <SessionModel> values = new List <SessionModel>();
                            values = (List <SessionModel>)Session["Policyinclustions"];
                            for (int k = 0; k < values.Count(); k++)
                            {
                                if (values[k].name == "Valuables" && values[k].UnitId == null && values[k].ProfileId == null)
                                {
                                    values.RemoveAt(k);
                                }
                            }
                            Session["Policyinclustions"] = values;
                        }
                        var errormessage = "First please provide cover for Home Buildings.";
                        if (unitdetails.ErrorMessage.Contains(errormessage))
                        {
                            TempData["Error"] = errormessage;
                            return(RedirectToAction("HomeDescription", "RuralLifeStyle", new { cid = cid, PcId = PcId }));
                        }
                    }
                    if (Policyincllist != null && Policyincllist.Exists(p => p.name == "Valuables"))
                    {
                        var policyhomelist = Policyincllist.FindAll(p => p.name == "Valuables").ToList();
                        if (policyhomelist != null && policyhomelist.Count() > 0)
                        {
                            if (Policyincllist.FindAll(p => p.name == "Valuables").Exists(p => p.UnitId == null))
                            {
                                Policyincllist.FindAll(p => p.name == "Valuables").Where(p => p.UnitId == null).First().UnitId = unitdetails.SectionData.UnId;
                            }
                            if (Policyincllist.FindAll(p => p.name == "Valuables").Exists(p => p.ProfileId == null))
                            {
                                Policyincllist.FindAll(p => p.name == "Valuables").Where(p => p.ProfileId == null).First().ProfileId = unitdetails.SectionData.ProfileUnId;
                            }
                        }
                        else
                        {
                            Policyincllist.FindAll(p => p.name == "Valuables").First().UnitId    = unitdetails.SectionData.UnId;
                            Policyincllist.FindAll(p => p.name == "Valuables").First().ProfileId = unitdetails.SectionData.ProfileUnId;
                        }
                        ValuablesHC.PolicyInclusions = Policyincllist;
                        Session["Policyinclustions"] = Policyincllist;
                    }
                    if (unitdetails != null && unitdetails.SectionData != null)
                    {
                        Session["unId"]      = unitdetails.SectionData.UnId;
                        Session["profileId"] = unitdetails.SectionData.ProfileUnId;
                    }
                }
            }
            if (unitdetails != null)
            {
                if (unitdetails.SectionData != null)
                {
                    if (unitdetails != null && unitdetails.SectionData != null && unitdetails.SectionData.AddressData != null)
                    {
                        if (unitdetails.SectionData.AddressData != null)
                        {
                            ValuablesHC.AddressObj.Address = unitdetails.SectionData.AddressData.AddressLine1 + ", " + unitdetails.SectionData.AddressData.Suburb + " ," + unitdetails.SectionData.AddressData.State + ", " + unitdetails.SectionData.AddressData.Postcode;
                        }
                    }
                    if (unitdetails.SectionData.ValueData.Exists(p => p.Element.ElId == ValuablesHC.SuminsuredObj.EiId))
                    {
                        string val = unitdetails.SectionData.ValueData.Where(p => p.Element.ElId == ValuablesHC.SuminsuredObj.EiId).Select(p => p.Value).FirstOrDefault();
                        if (val != null && !string.IsNullOrEmpty(val))
                        {
                            ValuablesHC.SuminsuredObj.Suminsured = val;
                        }
                        if (unitdetails.SectionData.ValueData.Select(p => p.Element.ElId == ValuablesHC.SuminsuredObj.EiId).Count() > 1)
                        {
                            List <ValueDatas> elmnts = new List <ValueDatas>();
                            var suminsuredList       = unitdetails.SectionData.ValueData.Where(p => p.Element.ElId == ValuablesHC.SuminsuredObj.EiId).Select(p => p.Element.ItId).ToList();
                            for (int i = 0; i < suminsuredList.Count(); i++)
                            {
                                ValueDatas vds = new ValueDatas();
                                vds.Element      = new Elements();
                                vds.Element.ElId = 60393;
                                vds.Element.ItId = suminsuredList[i];
                                vds.Value        = unitdetails.SectionData.ValueData.Where(p => p.Element.ElId == ValuablesHC.SuminsuredObj.EiId && p.Element.ItId == suminsuredList[i]).Select(p => p.Value).FirstOrDefault();
                                elmnts.Add(vds);
                            }
                            ValuablesHC.SuminsuredObjList = elmnts;
                        }
                    }
                    if (unitdetails.SectionData.ValueData.Exists(p => p.Element.ElId == ValuablesHC.DescriptionObj.EiId))
                    {
                        string val = unitdetails.SectionData.ValueData.Where(p => p.Element.ElId == ValuablesHC.DescriptionObj.EiId).Select(p => p.Value).FirstOrDefault();
                        if (val != null && !string.IsNullOrEmpty(val))
                        {
                            ValuablesHC.DescriptionObj.Description = val;
                        }
                        if (unitdetails.SectionData.ValueData.Select(p => p.Element.ElId == ValuablesHC.DescriptionObj.EiId).Count() > 1)
                        {
                            List <ValueDatas> elmnts = new List <ValueDatas>();
                            var descriptionList      = unitdetails.SectionData.ValueData.Where(p => p.Element.ElId == ValuablesHC.DescriptionObj.EiId).Select(p => p.Element.ItId).ToList();
                            for (int i = 0; i < descriptionList.Count(); i++)
                            {
                                ValueDatas vds = new ValueDatas();
                                vds.Element      = new Elements();
                                vds.Element.ElId = 60391;
                                vds.Element.ItId = descriptionList[i];
                                vds.Value        = unitdetails.SectionData.ValueData.Where(p => p.Element.ElId == ValuablesHC.DescriptionObj.EiId && p.Element.ItId == descriptionList[i]).Select(p => p.Value).FirstOrDefault();
                                elmnts.Add(vds);
                            }
                            ValuablesHC.DescriptionObjList = elmnts;
                        }
                    }
                    if (unitdetails.SectionData.ValueData.Exists(p => p.Element.ElId == ValuablesHC.LocationObj.EiId))
                    {
                        string val = unitdetails.SectionData.ValueData.Where(p => p.Element.ElId == ValuablesHC.LocationObj.EiId).Select(p => p.Value).FirstOrDefault();
                        ValuablesHC.LocationObj.Location = val;
                    }

                    if (unitdetails.SectionData.ValueData.Exists(p => p.Element.ElId == ValuablesHC.ExcesspayObj.EiId))
                    {
                        string val = unitdetails.SectionData.ValueData.Where(p => p.Element.ElId == ValuablesHC.ExcesspayObj.EiId).Select(p => p.Value).FirstOrDefault();
                        ValuablesHC.ExcesspayObj.Excess = val;
                    }

                    if (unitdetails.SectionData.ValueData.Exists(p => p.Element.ElId == ValuablesHC.TotalcoverObj.EiId))
                    {
                        string val = unitdetails.SectionData.ValueData.Where(p => p.Element.ElId == ValuablesHC.TotalcoverObj.EiId).Select(p => p.Value).FirstOrDefault();
                        ValuablesHC.TotalcoverObj.Totalcover = val;
                    }
                    if (unitdetails.SectionData.ValueData.Exists(p => p.Element.ElId == ValuablesHC.UnspecificObj.EiId))
                    {
                        string val = unitdetails.SectionData.ValueData.Where(p => p.Element.ElId == ValuablesHC.UnspecificObj.EiId).Select(p => p.Value).FirstOrDefault();
                        ValuablesHC.UnspecificObj.Unspecific = val;
                    }
                }
            }

            if (unitdetails.ReferralList != null)
            {
                ValuablesHC.ReferralList = unitdetails.ReferralList;
                ValuablesHC.ReferralList.Replace("&nbsp;&nbsp;&nbsp;&nbsp", "");
                ValuablesHC.Referels = new List <string>();
                string[] delim = { "<br/>" };

                string[] spltd = ValuablesHC.ReferralList.Split(delim, StringSplitOptions.None);
                if (spltd != null && spltd.Count() > 0)
                {
                    for (int i = 0; i < spltd.Count(); i++)
                    {
                        ValuablesHC.Referels.Add(spltd[i].Replace("&nbsp;&nbsp;&nbsp;&nbsp", " "));
                    }
                }
            }
            if (cid != null)
            {
                ValuablesHC.CustomerId = cid.Value;
            }
            if (PcId != null && PcId > 0)
            {
                ValuablesHC.PcId = PcId;
            }
            Session["Controller"] = "HomeContentValuable";
            Session["ActionName"] = "Valuables";
            return(View(ValuablesHC));
        }
        public async System.Threading.Tasks.Task <ActionResult> PetsCover(int?cid, int?PcId)
        {
            string apikey = null;
            NewPolicyDetailsClass petsmodel   = new NewPolicyDetailsClass();
            ViewEditPolicyDetails unitdetails = new ViewEditPolicyDetails();
            Pets Pets = new Pets();
            List <SessionModel> PolicyInclustions = new List <SessionModel>();
            var Policyincllist = new List <SessionModel>();

            if (Session["ApiKey"] != null)
            {
                apikey = Session["ApiKey"].ToString();
            }
            else
            {
                return(RedirectToAction("AgentLogin", "Login"));
            }
            CommonUseFunctionClass cmn = new CommonUseFunctionClass();

            Pets.NewSections = new List <string>();
            if (Session["Policyinclustions"] != null)
            {
                Policyincllist        = Session["Policyinclustions"] as List <SessionModel>;
                Pets.PolicyInclusions = new List <SessionModel>();
                Pets.PolicyInclusions = Policyincllist;
                Pets.NewSections      = cmn.NewSectionHome(Pets.PolicyInclusions);
                if (Policyincllist != null)
                {
                    if (Policyincllist.Exists(p => p.name == "Pet" || p.name == "Pets"))
                    {
                        if (Session["unId"] == null && Session["profileId"] == null)
                        {
                            Session["unId"]      = Policyincllist.Where(p => p.name == "Pet" || p.name == "Pets").Select(p => p.UnitId).First();
                            Session["profileId"] = Policyincllist.Where(p => p.name == "Pet" || p.name == "Pets").Select(p => p.ProfileId).First();
                        }
                    }
                    else
                    {
                        if (Policyincllist.Exists(p => p.name == "Travel"))
                        {
                            return(RedirectToAction("TravelCover", "Travel", new { cid = cid, PcId = PcId }));
                        }
                        else
                        {
                            return(RedirectToAction("DisclosureDetails", "Disclosure", new { cid = cid, PcId = PcId }));
                        }
                    }
                }
            }
            else
            {
                RedirectToAction("PolicyInclustions", "Customer", new { CustomerId = cid });
            }
            var db = new MasterDataEntities();

            var policyinclusions = db.usp_GetUnit(null, PcId, null).ToList();
            List <SelectListItem> petsBreedslist = new List <SelectListItem>();

            petsBreedslist = petsmodel.breedListDog();

            Pets.SpeciesObj                 = new Speciesed();
            Pets.SpeciesObj.EiId            = 61331;
            Pets.BreedObj                   = new Breeds();
            Pets.BreedObj.BreedList         = petsBreedslist;
            Pets.BreedObj.EiId              = 61333;
            Pets.OtherbreedObj              = new OtherBreeds();
            Pets.OtherbreedObj.EiId         = 61337;
            Pets.NameObj                    = new Names();
            Pets.NameObj.EiId               = 61339;
            Pets.DatebirthObj               = new DateOfBirth();
            Pets.DatebirthObj.EiId          = 61341;
            Pets.PreexistingObj             = new PreExistings();
            Pets.PreexistingObj.EiId        = 61343;
            Pets.DescriptionillnessObj      = new DescriptionOfIllness();
            Pets.DescriptionillnessObj.EiId = 61345;
            Pets.AnnualcoverlimitObj        = new AnnualCoverLimits();
            Pets.AnnualcoverlimitObj.EiId   = 61347;
            Pets.ExcessPetObj               = new ExcessPets();
            Pets.ExcessPetObj.EiId          = 61349;
            Pets.BoardingfeeObj             = new BoardingFees();
            Pets.BoardingfeeObj.EiId        = 61365;
            Pets.AnnuallimitbfObj           = new AnnualLimitsBF();
            Pets.AnnuallimitbfObj.EiId      = 61367;
            Pets.DeathillnessObj            = new DeathFromIllness();
            Pets.DeathillnessObj.EiId       = 61369;
            Pets.AnnuallimitdtObj           = new AnnualLimitsDT();
            Pets.AnnuallimitdtObj.EiId      = 61371;
            Pets.DeathinjuryObj             = new DeathFromInjury();
            Pets.DeathinjuryObj.EiId        = 61373;
            Pets.AnnuallimitijObj           = new AnnualLimitsIJ();
            Pets.AnnuallimitijObj.EiId      = 61375;
            List <SelectListItem> sepclist = new List <SelectListItem>();

            sepclist.Add(new SelectListItem {
                Text = "Dog", Value = "1"
            });
            sepclist.Add(new SelectListItem {
                Text = "Cat", Value = "2"
            });
            Pets.SpeciesObj.SpeciesList = sepclist;
            List <SelectListItem> ExcList = new List <SelectListItem>();

            ExcList.Add(new SelectListItem {
                Text = "$250", Value = "1"
            });
            Pets.ExcessPetObj.ExcessList = ExcList;
            Pets.CustomerId = cid ?? 0;

            string     policyid        = null;
            bool       policyinclusion = policyinclusions.Exists(p => p.Name == "Pet");
            HttpClient hclient         = new HttpClient();
            string     url             = System.Configuration.ConfigurationManager.AppSettings["APIURL"];

            hclient.BaseAddress = new Uri(url);
            hclient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            int unid      = 0;
            int profileid = 0;

            if (Session["unId"] != null)
            {
                unid = Convert.ToInt32(Session["unId"]);
            }
            if (Session["profileId"] != null)
            {
                profileid = Convert.ToInt32(Session["profileId"]);
            }
            if (PcId != null && PcId.HasValue)
            {
                Pets.PolicyInclusion           = policyinclusions;
                Pets.ExistingPolicyInclustions = policyinclusions;
                Pets.NewSections = cmn.NewSectionP(policyinclusions);
                if (Session["unId"] != null && Session["profileId"] != null)
                {
                    unid      = Convert.ToInt32(Session["unId"]);
                    profileid = Convert.ToInt32(Session["profileId"]);
                }
                else
                {
                    if (policyinclusions.Exists(p => p.Name == "Pets"))
                    {
                        unid      = policyinclusions.Where(p => p.Name == "Pets").Select(p => p.UnId).FirstOrDefault();
                        profileid = policyinclusions.Where(p => p.Name == "Pets").Select(p => p.UnId).FirstOrDefault();
                    }
                    else
                    {
                        return(RedirectToAction("TravelCover", "Travel", new { cid = cid, PcId = PcId }));
                    }
                }
                //int sectionId = policyinclusions.Where(p => p.Name == "Home Contents" && p.UnitNumber == unid).Select(p => p.UnId).FirstOrDefault();
                //int? profileunid = policyinclusions.Where(p => p.Name == "Home Contents" && p.ProfileUnId == profileid).Select(p => p.ProfileUnId).FirstOrDefault();
                HttpResponseMessage getunit = await hclient.GetAsync("UnitDetails?ApiKey=" + apikey + "&Action=Existing&SectionName=&SectionUnId=" + unid + "&ProfileUnId=" + profileid);

                var EmpResponse = getunit.Content.ReadAsStringAsync().Result;
                if (EmpResponse != null)
                {
                    unitdetails = JsonConvert.DeserializeObject <ViewEditPolicyDetails>(EmpResponse);
                }
            }
            else
            {
                if (PcId == null && Session["unId"] == null && (Session["profileId"] == null || profileid == 0))
                {
                    HttpResponseMessage Res = await hclient.GetAsync("UnitDetails?ApiKey=" + apikey + "&Action=New&SectionName=Pets&SectionUnId=&ProfileUnId=0");

                    var EmpResponse = Res.Content.ReadAsStringAsync().Result;
                    if (EmpResponse != null)
                    {
                        unitdetails = JsonConvert.DeserializeObject <ViewEditPolicyDetails>(EmpResponse);
                        if (unitdetails.ErrorMessage != null && unitdetails.ErrorMessage.Count() > 0)
                        {
                            bool exists = Pets.PolicyInclusions.Exists(p => p.name == "Pet");
                            if (exists == true)
                            {
                                List <SessionModel> values = new List <SessionModel>();
                                values = (List <SessionModel>)Session["Policyinclustions"];
                                for (int k = 0; k < values.Count(); k++)
                                {
                                    if (values[k].name == "Pet" && values[k].UnitId == null && values[k].ProfileId == null)
                                    {
                                        values.RemoveAt(k);
                                    }
                                }
                                Session["Policyinclustions"] = values;
                            }
                            var errormessage = "First please provide cover for Home Buildings.";
                            if (unitdetails.ErrorMessage.Contains(errormessage))
                            {
                                TempData["Error"] = errormessage;
                                return(RedirectToAction("HomeDescription", "RuralLifeStyle", new { cid = cid, PcId = PcId }));
                            }
                        }
                        if (unitdetails != null && unitdetails.SectionData != null)
                        {
                            Session["unId"]      = unitdetails.SectionData.UnId;
                            Session["profileId"] = unitdetails.SectionData.ProfileUnId;
                            if (Policyincllist != null && Policyincllist.Exists(p => p.name == "Pet"))
                            {
                                var policyhomelist = Policyincllist.FindAll(p => p.name == "Pet").ToList();
                                if (policyhomelist != null && policyhomelist.Count() > 0)
                                {
                                    if (Policyincllist.FindAll(p => p.name == "Pet").Exists(p => p.UnitId == null))
                                    {
                                        Policyincllist.FindAll(p => p.name == "Pet").Where(p => p.UnitId == null).First().UnitId = unitdetails.SectionData.UnId;
                                    }
                                    if (Policyincllist.FindAll(p => p.name == "Pet").Exists(p => p.ProfileId == null))
                                    {
                                        Policyincllist.FindAll(p => p.name == "Pet").Where(p => p.ProfileId == null).First().ProfileId = unitdetails.SectionData.ProfileUnId;
                                    }
                                }
                                else
                                {
                                    Policyincllist.FindAll(p => p.name == "Pet").First().UnitId    = unitdetails.SectionData.UnId;
                                    Policyincllist.FindAll(p => p.name == "Pet").First().ProfileId = unitdetails.SectionData.ProfileUnId;
                                }
                                Pets.PolicyInclusions        = Policyincllist;
                                Session["Policyinclustions"] = Policyincllist;
                            }
                        }
                    }
                }
                else if (PcId == null && Session["unId"] != null && Session["profileId"] != null)
                {
                    HttpResponseMessage getunit = await hclient.GetAsync("UnitDetails?ApiKey=" + apikey + "&Action=Existing&SectionName=&SectionUnId=" + unid + "&ProfileUnId=" + profileid);

                    var EmpResponse = getunit.Content.ReadAsStringAsync().Result;
                    if (EmpResponse != null)
                    {
                        unitdetails = JsonConvert.DeserializeObject <ViewEditPolicyDetails>(EmpResponse);
                    }
                }
            }
            if (unitdetails != null)
            {
                if (unitdetails.SectionData != null && unitdetails.SectionData.ValueData != null)
                {
                    if (unitdetails.SectionData.ValueData.Exists(p => p.Element.ElId == Pets.AnnualcoverlimitObj.EiId))
                    {
                        string val = unitdetails.SectionData.ValueData.Where(p => p.Element.ElId == Pets.AnnualcoverlimitObj.EiId).Select(p => p.Value).FirstOrDefault();
                        Pets.AnnualcoverlimitObj.Annualcoverlimit = val;
                    }
                    if (unitdetails.SectionData.ValueData.Exists(p => p.Element.ElId == Pets.AnnuallimitbfObj.EiId))
                    {
                        string val = unitdetails.SectionData.ValueData.Where(p => p.Element.ElId == Pets.AnnuallimitbfObj.EiId).Select(p => p.Value).FirstOrDefault();
                        Pets.AnnuallimitbfObj.Annuallimitbf = val;
                    }
                    if (unitdetails.SectionData.ValueData.Exists(p => p.Element.ElId == Pets.AnnuallimitdtObj.EiId))
                    {
                        string val = unitdetails.SectionData.ValueData.Where(p => p.Element.ElId == Pets.AnnuallimitdtObj.EiId).Select(p => p.Value).FirstOrDefault();
                        Pets.AnnuallimitdtObj.Annuallimit = val;
                    }
                    if (unitdetails.SectionData.ValueData.Exists(p => p.Element.ElId == Pets.AnnuallimitijObj.EiId))
                    {
                        string val = unitdetails.SectionData.ValueData.Where(p => p.Element.ElId == Pets.AnnuallimitijObj.EiId).Select(p => p.Value).FirstOrDefault();
                        Pets.AnnuallimitijObj.Annuallimitij = val;
                    }
                    if (unitdetails.SectionData.ValueData.Exists(p => p.Element.ElId == Pets.BoardingfeeObj.EiId))
                    {
                        string val = unitdetails.SectionData.ValueData.Where(p => p.Element.ElId == Pets.BoardingfeeObj.EiId).Select(p => p.Value).FirstOrDefault();
                        Pets.BoardingfeeObj.Boardingfee = val;
                    }
                    if (unitdetails.SectionData.ValueData.Exists(p => p.Element.ElId == Pets.BreedObj.EiId))
                    {
                        string val = unitdetails.SectionData.ValueData.Where(p => p.Element.ElId == Pets.BreedObj.EiId).Select(p => p.Value).FirstOrDefault();
                        Pets.BreedObj.Breed = val;
                    }
                    if (unitdetails.SectionData.ValueData.Exists(p => p.Element.ElId == Pets.DatebirthObj.EiId))
                    {
                        string val = unitdetails.SectionData.ValueData.Where(p => p.Element.ElId == Pets.DatebirthObj.EiId).Select(p => p.Value).FirstOrDefault();
                        Pets.DatebirthObj.Datebirth = val;
                    }
                    if (unitdetails.SectionData.ValueData.Exists(p => p.Element.ElId == Pets.DeathillnessObj.EiId))
                    {
                        string val = unitdetails.SectionData.ValueData.Where(p => p.Element.ElId == Pets.DeathillnessObj.EiId).Select(p => p.Value).FirstOrDefault();
                        Pets.DeathillnessObj.Deathillness = val;
                    }
                    if (unitdetails.SectionData.ValueData.Exists(p => p.Element.ElId == Pets.DeathinjuryObj.EiId))
                    {
                        string val = unitdetails.SectionData.ValueData.Where(p => p.Element.ElId == Pets.DeathinjuryObj.EiId).Select(p => p.Value).FirstOrDefault();
                        Pets.DeathinjuryObj.Deathinjury = val;
                    }
                    if (unitdetails.SectionData.ValueData.Exists(p => p.Element.ElId == Pets.DescriptionillnessObj.EiId))
                    {
                        string val = unitdetails.SectionData.ValueData.Where(p => p.Element.ElId == Pets.DescriptionillnessObj.EiId).Select(p => p.Value).FirstOrDefault();
                        Pets.DescriptionillnessObj.Descriptionillness = val;
                    }
                    if (unitdetails.SectionData.ValueData.Exists(p => p.Element.ElId == Pets.ExcessPetObj.EiId))
                    {
                        string val = unitdetails.SectionData.ValueData.Where(p => p.Element.ElId == Pets.ExcessPetObj.EiId).Select(p => p.Value).FirstOrDefault();
                        Pets.ExcessPetObj.Excess = val;
                    }
                    //if (unitdetails.ProfileData.ValueData.Exists(p => p.Element.ElId == Pets.ImposedpetsObj.EiId))
                    //{
                    //    string val = unitdetails.ProfileData.ValueData.Where(p => p.Element.ElId == Pets.ImposedpetsObj.EiId).Select(p => p.Value).FirstOrDefault();
                    //    Pets.ImposedpetsObj.Imposed = val;
                    //}
                    if (unitdetails.SectionData.ValueData.Exists(p => p.Element.ElId == Pets.NameObj.EiId))
                    {
                        string val = unitdetails.SectionData.ValueData.Where(p => p.Element.ElId == Pets.NameObj.EiId).Select(p => p.Value).FirstOrDefault();
                        Pets.NameObj.Name = val;
                    }
                    if (unitdetails.SectionData.ValueData.Exists(p => p.Element.ElId == Pets.OtherbreedObj.EiId))
                    {
                        string val = unitdetails.SectionData.ValueData.Where(p => p.Element.ElId == Pets.OtherbreedObj.EiId).Select(p => p.Value).FirstOrDefault();
                        Pets.OtherbreedObj.Otherbreed = val;
                    }
                    if (unitdetails.SectionData.ValueData.Exists(p => p.Element.ElId == Pets.PreexistingObj.EiId))
                    {
                        string val = unitdetails.SectionData.ValueData.Where(p => p.Element.ElId == Pets.PreexistingObj.EiId).Select(p => p.Value).FirstOrDefault();
                        Pets.PreexistingObj.Preexisting = val;
                    }
                    //if (unitdetails.SectionData.ValueData.Exists(p => p.Element.ElId == Pets.PremiumptsObj.EiId))
                    //{
                    //    string val = unitdetails.SectionData.ValueData.Where(p => p.Element.ElId == Pets.PremiumptsObj.EiId).Select(p => p.Value).FirstOrDefault();
                    //    Pets.PremiumptsObj.Premium = val;
                    //}
                    if (unitdetails.SectionData.ValueData.Exists(p => p.Element.ElId == Pets.SpeciesObj.EiId))
                    {
                        string val = unitdetails.SectionData.ValueData.Where(p => p.Element.ElId == Pets.SpeciesObj.EiId).Select(p => p.Value).FirstOrDefault();
                        if (val == "2")
                        {
                            petsBreedslist          = petsmodel.breedListCat();
                            Pets.BreedObj.BreedList = petsBreedslist;
                        }
                        else
                        {
                            petsBreedslist          = petsmodel.breedListDog();
                            Pets.BreedObj.BreedList = petsBreedslist;
                        }
                        Pets.SpeciesObj.Species = val;
                    }
                }
            }

            if (unitdetails != null && unitdetails.ReferralList != null)
            {
                Pets.ReferralList = unitdetails.ReferralList;
                Pets.ReferralList.Replace("&nbsp;&nbsp;&nbsp;&nbsp", "");
                Pets.Referels = new List <string>();
                string[] delim = { "<br/>" };

                string[] spltd = Pets.ReferralList.Split(delim, StringSplitOptions.None);
                if (spltd != null && spltd.Count() > 0)
                {
                    for (int i = 0; i < spltd.Count(); i++)
                    {
                        Pets.Referels.Add(spltd[i].Replace("&nbsp;&nbsp;&nbsp;&nbsp", " "));
                    }
                }
            }
            if (cid != null && cid > 0)
            {
                Pets.CustomerId = cid.Value;
            }
            if (PcId != null && PcId > 0)
            {
                Pets.PcId = PcId;
            }
            Session["Controller"] = "Pets";
            Session["ActionName"] = "PetsCover";
            return(View(Pets));
        }
Exemple #6
0
        // GET: api/LogInDetails/5
        public async Task <HttpResponseMessage> Post([FromBody] LogInDetails value)
        {
            try
            {
                string          UserName   = value.UserName;
                string          Password   = value.Password;
                LoginDetailsRef loginref   = new LoginDetailsRef();
                LogInDetails    loginmodel = new LogInDetails();
                List <string>   Errors     = new List <string>();
                loginref.ErrorMessage = new List <string>();
                var regexSpace = new Regex(@"\s");
                if (UserName == null || UserName == string.Empty || string.IsNullOrWhiteSpace(UserName.Trim()) || Password == null || Password == string.Empty || string.IsNullOrWhiteSpace(Password.Trim()))
                {
                    if (UserName == null || UserName == string.Empty || string.IsNullOrWhiteSpace(UserName.Trim()))
                    {
                        Errors.Add("UserName is required");
                    }
                    if (Password == null || Password == string.Empty || string.IsNullOrWhiteSpace(Password.Trim()))
                    {
                        Errors.Add("Password is required");
                    }
                }
                else
                {
                    string specialCharacters      = @"%!#$%^&*(-)?/><,:;'\|}]{[~`+=" + "\"";
                    char[] specialCharactersArray = specialCharacters.ToCharArray();
                    int    index = UserName.IndexOfAny(specialCharactersArray);
                    //index == -1 no special characters
                    if (index == -1)
                    {
                    }
                    else
                    {
                        Errors.Add("UserName allows only three special characters '_' '.' '@' ");
                    }
                    if (regexSpace.IsMatch(UserName.Trim()))
                    {
                        Errors.Add("UserName should not have space");
                    }
                    string justNumber  = new String(UserName.Trim().Where(Char.IsDigit).ToArray());
                    string justStrings = new String(UserName.Trim().Where(Char.IsLetter).ToArray());

                    if (justStrings == null || justStrings == string.Empty && UserName.Length <= 20)
                    {
                        Errors.Add("UserName does not allow only numeric values");
                    }
                }
                if (regexSpace.IsMatch(Convert.ToString(Password).Trim()))
                {
                    Errors.Add("Password should not have space");
                }

                if (Errors != null && Errors.Count() > 0)
                {
                    loginref.Status       = "Failure";
                    loginref.ErrorMessage = Errors;
                    return(Request.CreateResponse <LoginDetailsRef>(HttpStatusCode.BadRequest, loginref));
                }
                else
                {
                    if (await CommonUseFunctionClass.CheckUser(UserName, Password))
                    {
                        string str = CommonUseFunctionClass.GenerateToken(UserName, 20);
                        if (str != string.Empty || str != null || string.IsNullOrWhiteSpace(str.Trim()))
                        {
                            loginref.Status       = "Success";
                            loginref.Access_Token = str;
                            loginmodel.UserName   = UserName;
                            loginref.LogInData    = loginmodel;
                            return(Request.CreateResponse <LoginDetailsRef>(HttpStatusCode.OK, loginref));
                        }
                        else
                        {
                            loginref.Status = "Failure";
                            loginref.ErrorMessage.Add("Token Is Not generated");
                            return(Request.CreateResponse <LoginDetailsRef>(HttpStatusCode.BadRequest, loginref));
                        }
                    }
                    else
                    {
                        loginref.Status = "Failure";
                        loginref.ErrorMessage.Add("UserName or Password are not valid.");
                        return(Request.CreateResponse <LoginDetailsRef>(HttpStatusCode.BadRequest, loginref));
                    }
                }
            }
            catch (Exception xp)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, xp.Message));
            }
            return(null);
        }
        public async System.Threading.Tasks.Task <ActionResult> LiabilityCover(int?cid, int?PcId)
        {
            LiabilityCover LiabilityCover = new LiabilityCover();

            if (cid.HasValue && cid > 0)
            {
                ViewBag.cid = cid;
                LiabilityCover.CustomerId = cid.Value;
            }
            string apikey = "";

            if (Session["ApiKey"] != null)
            {
                apikey = Session["ApiKey"].ToString();
            }
            else
            {
                return(RedirectToAction("AgentLogin", "Login"));
            }
            var Policyincllist         = Session["Policyinclustions"] as List <SessionModel>;
            CommonUseFunctionClass cmn = new CommonUseFunctionClass();

            LiabilityCover.NewSections = new List <string>();
            if (Session["Policyinclustions"] != null)
            {
                List <SessionModel> PolicyInclustions = new List <SessionModel>();

                LiabilityCover.PolicyInclusions = new List <SessionModel>();
                LiabilityCover.PolicyInclusions = Policyincllist;
                LiabilityCover.NewSections      = cmn.NewSectionHome(LiabilityCover.PolicyInclusions);
                if (Policyincllist != null)
                {
                    //var Policyincllist = Session["Policyinclustions"] as List<SessionModel>;
                    // var Suburb = new List<KeyValuePair<string, string>>();
                    // List<SelectListItem> listItems = new List<SelectListItem>();

                    if (Policyincllist != null)
                    {
                        if (Policyincllist.Exists(p => p.name == "Liability"))
                        {
                        }
                        else
                        {
                            if (Policyincllist.Exists(p => p.name == "Motor" || p.name == "Motors"))
                            {
                                return(RedirectToAction("VehicleDescription", "MotorCover", new { cid = cid }));
                            }
                            else if (Policyincllist.Exists(p => p.name == "Boat"))
                            {
                                return(RedirectToAction("BoatDetails", "Boat", new { cid = cid }));
                            }

                            else if (Policyincllist.Exists(p => p.name == "Pet" || p.name == "Pets"))
                            {
                                return(RedirectToAction("PetsCover", "Pets", new { cid = cid }));
                            }
                            else if (Policyincllist.Exists(p => p.name == "Travel"))
                            {
                                return(RedirectToAction("TravelCover", "Travel", new { cid = cid }));
                            }

                            if (Policyincllist.Exists(p => p.name == "Liability"))
                            {
                                if (Session["unId"] == null && Session["profileId"] == null)
                                {
                                    Session["unId"]      = Policyincllist.Where(p => p.name == "Liability").Select(p => p.UnitId).First();
                                    Session["profileId"] = Policyincllist.Where(p => p.name == "Liability").Select(p => p.ProfileId).First();
                                }
                            }
                            else
                            {
                                return(RedirectToAction("DisclosureDetails", "Disclosure", new { cid = cid, PcId = PcId }));
                            }
                        }
                    }
                }
            }
            //else
            //{
            //    RedirectToAction("PolicyInclustions", "Customer", new { CustomerId = cid,type=1 });
            //}
            var db = new MasterDataEntities();
            ViewEditPolicyDetails unitdetails = new ViewEditPolicyDetails();

            unitdetails.AddressData = new List <AddressData>();
            var policyinclusions = db.usp_GetUnit(null, PcId, null).ToList();

            LiabilityCover.FarmliabiltyObj           = new FarmLiabiltys();
            LiabilityCover.FarmliabiltyObj.EiId      = 60691;
            LiabilityCover.LimitindemnityObj         = new LimitofIndemnity();
            LiabilityCover.LimitindemnityObj.EiId    = 60671;
            LiabilityCover.FarmingactivitiesObj      = new Farmingactivities();
            LiabilityCover.FarmingactivitiesObj.EiId = 60673;
            LiabilityCover.FarmProduceObj            = new ProductsCoveredFP();
            LiabilityCover.FarmProduceObj.EiId       = 60675;
            LiabilityCover.ExcessLCObj      = new ExcessLC();
            LiabilityCover.ExcessLCObj.EiId = 60681;
            List <SelectListItem> ExcList = new List <SelectListItem>();

            ExcList.Add(new SelectListItem {
                Text = "$250", Value = "1"
            });
            LiabilityCover.ExcessLCObj.ExcessList = ExcList;

            string     policyid        = null;
            bool       policyinclusion = policyinclusions.Exists(p => p.Name == "Liability");
            HttpClient hclient         = new HttpClient();
            string     url             = System.Configuration.ConfigurationManager.AppSettings["APIURL"];

            hclient.BaseAddress = new Uri(url);
            hclient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            if (PcId != null && PcId.HasValue)
            {
                int?unid      = null;
                int?profileid = null;
                if (Session["unId"] != null && Session["profileId"] != null)
                {
                    unid      = Convert.ToInt32(Session["unId"]);
                    profileid = Convert.ToInt32(Session["profileId"]);
                }
                else
                {
                    if (policyinclusions.Exists(p => p.Name == "Liability"))
                    {
                        unid      = policyinclusions.Where(p => p.Name == "Liability").Select(p => p.UnId).FirstOrDefault();
                        profileid = policyinclusions.Where(p => p.Name == "Liability").Select(p => p.UnId).FirstOrDefault();
                    }
                    else
                    {
                        return(RedirectToAction("VehicleDescription", "MotorCover", new { cid = cid, PcId = PcId }));
                    }
                }
                LiabilityCover.NewSections = cmn.NewSectionP(policyinclusions);
                if (unid == null || unid == 0)
                {
                    unid      = unitdetails.SectionData.UnId;
                    profileid = unitdetails.SectionData.ProfileUnId;
                }
                LiabilityCover.PolicyInclusion           = policyinclusions;
                LiabilityCover.ExistingPolicyInclustions = policyinclusions;

                //int sectionId = policyinclusions.Where(p => p.Name == "Home Contents" && p.UnitNumber == unid).Select(p => p.UnId).FirstOrDefault();
                //int? profileunid = policyinclusions.Where(p => p.Name == "Home Contents" && p.ProfileUnId == profileid).Select(p => p.ProfileUnId).FirstOrDefault();
                HttpResponseMessage getunit = await hclient.GetAsync("UnitDetails?ApiKey=" + apikey + "&Action=Existing&SectionName=&SectionUnId=" + unid + "&ProfileUnId=" + profileid);

                var EmpResponse = getunit.Content.ReadAsStringAsync().Result;
                if (EmpResponse != null)
                {
                    unitdetails = JsonConvert.DeserializeObject <ViewEditPolicyDetails>(EmpResponse);
                }
            }
            else
            {
                int HprofileId = 0;
                int unid       = 0;
                int profileid  = 0;
                if (Session["unId"] != null && Session["profileId"] != null)
                {
                    unid      = Convert.ToInt32(Session["unId"]);
                    profileid = Convert.ToInt32(Session["profileId"]);
                }
                if (Session["HProfileId"] != null)
                {
                    HprofileId = Convert.ToInt32(Session["HprofileId"]);
                }
                if (HprofileId != null && HprofileId < 0 && unid != null && unid < 0)
                {
                    HttpResponseMessage Res = await hclient.GetAsync("UnitDetails?ApiKey=" + apikey + "&Action=Existing&SectionName=&SectionUnId=" + unid + "&ProfileUnId=" + profileid);

                    var EmpResponse = Res.Content.ReadAsStringAsync().Result;
                    if (EmpResponse != null)
                    {
                        unitdetails = JsonConvert.DeserializeObject <ViewEditPolicyDetails>(EmpResponse);
                        if (unitdetails != null && unitdetails.SectionData != null)
                        {
                            Session["unId"]      = unitdetails.SectionData.UnId;
                            Session["profileId"] = unitdetails.SectionData.ProfileUnId;
                        }
                    }
                }
                else
                {
                    HttpResponseMessage Res = await hclient.GetAsync("UnitDetails?ApiKey=" + apikey + "&Action=New&SectionName=Liability&SectionUnId=&ProfileUnId=" + HprofileId);

                    var EmpResponse = Res.Content.ReadAsStringAsync().Result;
                    if (EmpResponse != null)
                    {
                        unitdetails = JsonConvert.DeserializeObject <ViewEditPolicyDetails>(EmpResponse);
                        if (unitdetails != null && unitdetails.SectionData != null)
                        {
                            Session["unId"]      = unitdetails.SectionData.UnId;
                            Session["profileId"] = unitdetails.SectionData.ProfileUnId;
                            if (Policyincllist != null && Policyincllist.Exists(p => p.name == "Liability"))
                            {
                                var policyhomelist = Policyincllist.FindAll(p => p.name == "Liability").ToList();
                                if (policyhomelist != null && policyhomelist.Count() > 0)
                                {
                                    if (Policyincllist.FindAll(p => p.name == "Liability").Exists(p => p.UnitId == null))
                                    {
                                        Policyincllist.FindAll(p => p.name == "Liability").Where(p => p.UnitId == null).First().UnitId = unitdetails.SectionData.UnId;
                                    }
                                    if (Policyincllist.FindAll(p => p.name == "Liability").Exists(p => p.ProfileId == null))
                                    {
                                        Policyincllist.FindAll(p => p.name == "Liability").Where(p => p.ProfileId == null).First().ProfileId = unitdetails.SectionData.ProfileUnId;
                                    }
                                }
                                else
                                {
                                    Policyincllist.FindAll(p => p.name == "Liability").First().UnitId    = unitdetails.SectionData.UnId;
                                    Policyincllist.FindAll(p => p.name == "Liability").First().ProfileId = unitdetails.SectionData.ProfileUnId;
                                }
                                LiabilityCover.PolicyInclusions = Policyincllist;
                                Session["Policyinclustions"]    = Policyincllist;
                            }
                        }
                    }
                }
            }
            if (unitdetails != null)
            {
                if (unitdetails.SectionData != null && unitdetails.SectionData.ValueData != null)
                {
                    if (unitdetails.SectionData.ValueData.Exists(p => p.Element.ElId == LiabilityCover.ExcessLCObj.EiId))
                    {
                        string val = unitdetails.SectionData.ValueData.Where(p => p.Element.ElId == LiabilityCover.ExcessLCObj.EiId).Select(p => p.Value).FirstOrDefault();
                        LiabilityCover.ExcessLCObj.Excess = val;
                    }
                    if (unitdetails.SectionData.ValueData.Exists(p => p.Element.ElId == LiabilityCover.FarmliabiltyObj.EiId))
                    {
                        string val = unitdetails.SectionData.ValueData.Where(p => p.Element.ElId == LiabilityCover.FarmliabiltyObj.EiId).Select(p => p.Value).FirstOrDefault();
                        LiabilityCover.FarmliabiltyObj.Farmliabilty = val;
                    }
                    if (unitdetails.SectionData.ValueData.Exists(p => p.Element.ElId == LiabilityCover.LimitindemnityObj.EiId))
                    {
                        string val = unitdetails.SectionData.ValueData.Where(p => p.Element.ElId == LiabilityCover.LimitindemnityObj.EiId).Select(p => p.Value).FirstOrDefault();
                        LiabilityCover.LimitindemnityObj.Limitindemnity = Convert.ToInt32(val);
                    }
                    else
                    {
                        //if (Session["CoverAmount"]!=null)
                        //{
                        LiabilityCover.LimitindemnityObj.Limitindemnity = 3000000;
                        //}
                    }
                    if (unitdetails.SectionData.ValueData.Exists(p => p.Element.ElId == LiabilityCover.FarmingactivitiesObj.EiId))
                    {
                        string val = unitdetails.SectionData.ValueData.Where(p => p.Element.ElId == LiabilityCover.FarmingactivitiesObj.EiId).Select(p => p.Value).FirstOrDefault();
                        LiabilityCover.FarmingactivitiesObj.Activities = val;
                    }
                    if (unitdetails.SectionData.ValueData.Exists(p => p.Element.ElId == LiabilityCover.FarmProduceObj.EiId))
                    {
                        string val = unitdetails.SectionData.ValueData.Where(p => p.Element.ElId == LiabilityCover.FarmProduceObj.EiId).Select(p => p.Value).FirstOrDefault();
                        if (val == "1")
                        {
                            LiabilityCover.FarmProduceObj.Farmproduce = true;
                            LiabilityCover.allproducts = "1";
                        }
                        else if (val == "2")
                        {
                            LiabilityCover.FarmProduceObj.Farmproduce = true;
                            LiabilityCover.allproducts = "2";
                        }
                        else if (val == "1,2")
                        {
                            LiabilityCover.FarmProduceObj.Farmproduce = true;
                            LiabilityCover.allproducts = "1,2";
                        }
                        else if (val == "0")
                        {
                            LiabilityCover.FarmProduceObj.Farmproduce = false;
                            LiabilityCover.allproducts = "0";
                        }
                    }
                }
            }
            if (unitdetails != null && unitdetails.ReferralList != null)
            {
                LiabilityCover.ReferralList = unitdetails.ReferralList;
                LiabilityCover.ReferralList.Replace("&nbsp;&nbsp;&nbsp;&nbsp", "");
                LiabilityCover.Referels = new List <string>();
                string[] delim = { "<br/>" };

                string[] spltd = LiabilityCover.ReferralList.Split(delim, StringSplitOptions.None);
                if (spltd != null && spltd.Count() > 0)
                {
                    for (int i = 0; i < spltd.Count(); i++)
                    {
                        LiabilityCover.Referels.Add(spltd[i].Replace("&nbsp;&nbsp;&nbsp;&nbsp", " "));
                    }
                }
            }
            if (cid != null && cid.HasValue)
            {
                LiabilityCover.CustomerId = cid.Value;
            }
            if (PcId != null && PcId.HasValue)
            {
                LiabilityCover.PcId = PcId;
            }
            Session["Controller"] = "Liabilities";
            Session["ActionName"] = "LiabilityCover";
            return(View(LiabilityCover));
        }
Exemple #8
0
        public async System.Threading.Tasks.Task <ActionResult> AgentLogin(string UserName, string Password)
        {
            try
            {
                LoginDetailsRef loginref   = new LoginDetailsRef();
                LogInDetails    loginmodel = new LogInDetails();
                List <string>   Errors     = new List <string>();
                loginref.ErrorMessage = new List <string>();
                loginmodel.Errors     = new List <string>();
                var regexSpace = new Regex(@"\s");
                if (UserName == null || UserName == string.Empty || string.IsNullOrWhiteSpace(UserName.Trim()) || Password == null || Password == string.Empty || string.IsNullOrWhiteSpace(Password.Trim()))
                {
                    if (UserName == null || UserName == string.Empty || string.IsNullOrWhiteSpace(UserName.Trim()))
                    {
                        Errors.Add("User Name is required");
                    }
                    if (Password == null || Password == string.Empty || string.IsNullOrWhiteSpace(Password.Trim()))
                    {
                        Errors.Add("Password is required");
                    }
                }
                else
                {
                    string specialCharacters      = @"%!#$%^&*(-)?/><,:;'\|}]{[~`+=" + "\"";
                    char[] specialCharactersArray = specialCharacters.ToCharArray();
                    int    index = UserName.IndexOfAny(specialCharactersArray);
                    //index == -1 no special characters
                    if (index == -1)
                    {
                    }
                    else
                    {
                        Errors.Add("User Name allows only three special characters '_' '.' '@' ");
                    }
                    if (regexSpace.IsMatch(UserName.Trim()))
                    {
                        Errors.Add("User Name should not have space");
                    }
                    string justNumber  = new String(UserName.Trim().Where(Char.IsDigit).ToArray());
                    string justStrings = new String(UserName.Trim().Where(Char.IsLetter).ToArray());

                    if (justStrings == null || justStrings == string.Empty && UserName.Length <= 20)
                    {
                        Errors.Add("User Name does not allow only numeric values");
                    }
                }
                if (regexSpace.IsMatch(Convert.ToString(Password).Trim()))
                {
                    Errors.Add("Password should not have space");
                }

                if (Errors != null && Errors.Count() > 0)
                {
                    loginref.Status       = "Failure";
                    loginref.ErrorMessage = Errors;
                    return(View());
                }
                else
                {
                    //#region Remove
                    //LogInDetailsClass ld = new LogInDetailsClass();

                    //LoginDetailsRef LoginDetailsRef = new LoginDetailsRef();
                    //LoginDetailsRef.ErrorMessage = new List<string>();
                    //LoginDetailsRef = await ld.GetLogInDetailsPage(UserName, Password);
                    //{
                    //    if(LoginDetailsRef.ErrorMessage!=null && LoginDetailsRef.ErrorMessage.Count()>0)
                    //    {
                    //        loginmodel.Errors = LoginDetailsRef.ErrorMessage;
                    //        return View(loginmodel);
                    //    }
                    //}
                    //#endregion
                    if (await CommonUseFunctionClass.CheckUser(UserName, Password))
                    {
                        string str = CommonUseFunctionClass.GenerateToken(UserName, 20);
                        if (str != string.Empty || str != null || string.IsNullOrWhiteSpace(str.Trim()))
                        {
                            Session["IyId"]       = 9262;
                            loginref.Status       = "Success";
                            loginref.Access_Token = str;
                            loginmodel.UserName   = UserName;
                            loginref.LogInData    = loginmodel;
                            return(RedirectToAction("CustomerSearch", "Customer"));
                        }
                        else
                        {
                            loginref.Status = "Failure";
                            loginref.ErrorMessage.Add("Token is not generated");
                            ViewBag.ErrorMessage = "";
                            return(View());
                        }
                    }
                    else
                    {
                        loginref.Status = "Failure";
                        loginref.ErrorMessage.Add("User Name or Password are not valid.");
                        ViewBag.ErrorMessage = "User Name or Password are not valid.";
                        return(View());
                    }
                }
            }

            catch (Exception ex)
            {
                ViewBag.ErrorMessage = "User Name or Password are not valid.";
                return(View());
            }

            return(View());
        }