예제 #1
0
        public async System.Threading.Tasks.Task <ActionResult> CreatePolicy(Policy policy)
        {
            ValidationService   validationService   = new ValidationService();
            RatingEngineService ratingEngineService = new RatingEngineService();
            travel_policy       polisaEntity        = new travel_policy();

            Uri        uri    = new Uri(ConfigurationManager.AppSettings["webpage_url"] + "/api/premium/calculate");
            HttpClient client = new HttpClient();

            client.BaseAddress = uri;
            var         mediaType     = new MediaTypeHeaderValue("application/json");
            var         jsonFormatter = new JsonMediaTypeFormatter();
            HttpContent content       = new ObjectContent <Policy>(policy, jsonFormatter);

            HttpResponseMessage responseMessage = client.PostAsync(uri, content).Result;
            string responseBody = await responseMessage.Content.ReadAsStringAsync();

            dynamic data    = JObject.Parse(responseBody);
            int     premium = data.PremiumAmount;

            bool   valid         = validationService.masterValidate(polisaEntity);
            double?vkupnaPremija = ratingEngineService.totalPremium(policy);

            policy.Total_Premium = vkupnaPremija;
            System.Web.HttpContext.Current.Session.Add("SessionId", policy.Policy_Number);

            if (valid)
            {
                string PolicyNumber = _ps.CreatePolicyNumber();
                string ID_Company   = _ps.GetCompanyID(policy.Policy_Number);
                int    tempID;
                if (String.IsNullOrEmpty(ID_Company))
                {
                    tempID = 0;
                }
                else
                {
                    string ID_trim  = ID_Company.Substring(0, 4);
                    string ID_trim2 = ID_Company.Substring(5);
                    tempID = int.Parse(ID_trim2) + 1;
                }
                polisaEntity.Policy_Number           = PolicyNumber;
                polisaEntity.Policy_TypeID           = policy.Policy_TypeID;
                polisaEntity.CountryID               = policy.CountryID;
                polisaEntity.Start_Date              = policy.Start_Date;
                polisaEntity.End_Date                = policy.End_Date;
                polisaEntity.Valid_Days              = policy.Valid_Days;
                polisaEntity.Travel_Insurance_TypeID = policy.Travel_Insurance_TypeID;
                polisaEntity.Travel_NumberID         = policy.Travel_NumberID;
                polisaEntity.Exchange_RateID         = (policy.Exchange_RateID.HasValue)? policy.Exchange_RateID.Value : 1;
                var result = _ps.AddPolicy(polisaEntity);
            }

            return(Json(new { success = true, responseText = "Success." }, JsonRequestBehavior.AllowGet));
        }
예제 #2
0
        public IHttpActionResult Code(Policy policy)
        {
            ok_setup Last_Entry = _os.GetLast();

            if (Last_Entry.SSNValidationActive == 1)
            {
                ValidationService validatePremium = new ValidationService();

                if (!validatePremium.validateSSN_Advanced(policy.SSN))
                {
                    return(Json(new { isValid = false, status = "error", message = Resource.Error_EMBG_Val_Advanced }));
                }
            }

            if (!policy.isMobile && policy.IsSamePolicyHolderInsured)
            {
                policy.PolicyHolderName        = policy.Name;
                policy.PolicyHolderLastName    = policy.LastName;
                policy.PolicyHolderSSN         = policy.SSN;
                policy.PolicyHolderEmail       = policy.Email;
                policy.PolicyHolderAddress     = policy.Address;
                policy.PolicyHolderBirthDate   = policy.BirthDate;
                policy.PolicyHolderCity        = policy.City;
                policy.PolicyHolderPostalCode  = policy.PostalCode;
                policy.PolicyHolderPhoneNumber = policy.PhoneNumber;
            }
            if (!policy.isMobile)
            {
                ModelState.Remove("PolicyHolderName");
                ModelState.Remove("PolicyHolderLastName");
                ModelState.Remove("PolicyHolderEmail");
                ModelState.Remove("PolicyHolderAddress");
                ModelState.Remove("PolicyHolderBirthDate");
                ModelState.Remove("PolicyHolderCity");
                ModelState.Remove("PolicyHolderPostalCode");
                ModelState.Remove("PolicyHolderPhoneNumber");
                ModelState.Remove("PolicyHolderSSN");
            }

            if (ModelState.IsValid && policy != null)
            {
                RatingEngineService ratingEngineService = new RatingEngineService();

                Premium Premium = new Premium();
                Premium.PremiumAmount = (int)ratingEngineService.totalPremium(policy);
                return(Ok(new { PremiumAmount = Premium.PremiumAmount }));
            }
            else
            {
                return(BadRequest("Внесете ги сите полиња!"));
            }
        }
예제 #3
0
        public IHttpActionResult CalculatePremium(CalculatePremiumViewModel data)
        {
            RatingEngineService ratingEngineService = new RatingEngineService();
            Premium             Premium             = new Premium();

            var policy = new Policy();

            policy.additional_charges = new List <additional_charge>();
            policy = Mapper.Map <CalculatePremiumViewModel, Policy>(data);

            Premium.PremiumAmount = (int)ratingEngineService.totalPremium(policy);
            return(Ok(new { PremiumAmount = Premium.PremiumAmount }));
        }
예제 #4
0
        public async Task <JsonResult> Index(Policy policy)
        {
            string username = System.Web.HttpContext.Current.User.Identity.Name;

            ok_setup Last_Entry = _os.GetLast();

            if (Last_Entry.SSNValidationActive == 1)
            {
                ValidationService validatePremium = new ValidationService();

                if (!validatePremium.validateSSN_Advanced(policy.SSN))
                {
                    return(Json(new { isValid = false, status = "error", message = Resource.Error_EMBG_Val_Advanced }));
                }
            }

            if (policy.IsSamePolicyHolderInsured)
            {
                policy.PolicyHolderName        = policy.Name;
                policy.PolicyHolderLastName    = policy.LastName;
                policy.PolicyHolderSSN         = policy.SSN;
                policy.PolicyHolderEmail       = policy.Email;
                policy.PolicyHolderAddress     = policy.Address;
                policy.PolicyHolderBirthDate   = policy.BirthDate;
                policy.PolicyHolderCity        = policy.City;
                policy.PolicyHolderPostalCode  = policy.PostalCode;
                policy.PolicyHolderPhoneNumber = policy.PhoneNumber;
            }
            else
            {
                ModelState.Remove("PolicyHolderName");
                ModelState.Remove("PolicyHolderLastName");
                ModelState.Remove("PolicyHolderEmail");
                ModelState.Remove("PolicyHolderAddress");
                ModelState.Remove("PolicyHolderBirthDate");
                ModelState.Remove("PolicyHolderCity");
                ModelState.Remove("PolicyHolderPostalCode");
                ModelState.Remove("PolicyHolderPhoneNumber");
                ModelState.Remove("PolicyHolderSSN");
            }

            if (ModelState.IsValid && policy != null)
            {
                RatingEngineService ratingEngineService = new RatingEngineService();
                Premium             Premium             = new Premium();
                Premium.PremiumAmount = (int)ratingEngineService.totalPremium(policy);
                if (_roleAuthorize.IsUser("Broker manager", username))
                {
                    if (Premium.PremiumAmount > 10000)
                    {
                        return(Json(new { isValid = false, status = "error", message = "ThePremiumIsExceeded", PremiumAmount = Premium.PremiumAmount }));
                    }
                }
                else if (_roleAuthorize.IsUser("Broker", username))
                {
                    if (Premium.PremiumAmount > 10000)
                    {
                        return(Json(new { isValid = false, status = "error", message = "ThePremiumIsExceeded", PremiumAmount = Premium.PremiumAmount }));
                    }
                }

                return(Json(new { isValid = true, status = "ok", PremiumAmount = Premium.PremiumAmount }));
            }
            else
            {
                return(Json(new { isValid = false, status = "error", message = InsuredTraveling.Resource.EnterAllData }));
            }
        }