Example #1
0
 public CalculatePremiumViewModel()
 {
     Policy_Holder      = new insured();
     Insureds           = new List <insured>();
     additional_charges = new List <int>();
     Additional_charges = new List <additional_charge>();
 }
        public void UpdateInsuredData(insured insured)
        {
            var insuredOld = _db.insureds.Where(x => x.ID == insured.ID && x.Created_By == insured.Modified_By).SingleOrDefault();

            insuredOld = insured;
            _db.SaveChanges();
        }
        public int AddInsured(insured Insured)
        {
            var InsuredData = _db.insureds.Where(x => x.SSN == Insured.SSN).FirstOrDefault();

            if (InsuredData != null)
            {
                return(InsuredData.ID);
            }
            _db.insureds.Add(Insured);
            _db.SaveChanges();
            return(Insured.ID);
        }
        public static int SaveInsured(IInsuredsService _iss, string FirstName, string LastName, string SSN,
                                      string Email, DateTime BirthDate, string PhoneNumber, string PassportNumber_ID, string Address,
                                      string City, string PostalCode, string CreatedById)
        {
            var insuredId = _iss.GetInsuredIdBySsn(SSN);

            if (insuredId != -1)
            {
                insured updateInsuredData = new insured();
                updateInsuredData.ID                       = insuredId;
                updateInsuredData.Name                     = FirstName;
                updateInsuredData.Lastname                 = LastName;
                updateInsuredData.SSN                      = SSN;
                updateInsuredData.Email                    = Email;
                updateInsuredData.DateBirth                = BirthDate;
                updateInsuredData.Phone_Number             = PhoneNumber;
                updateInsuredData.Passport_Number_IdNumber = PassportNumber_ID;
                updateInsuredData.City                     = City;
                updateInsuredData.Postal_Code              = PostalCode;
                updateInsuredData.Address                  = Address;
                updateInsuredData.Date_Modified            = DateTime.UtcNow;
                updateInsuredData.Modified_By              = CreatedById;
                _iss.UpdateInsuredData(updateInsuredData);

                return(insuredId);
            }
            var newInsured = _iss.Create();

            newInsured.Name                     = FirstName;
            newInsured.Lastname                 = LastName;
            newInsured.SSN                      = SSN;
            newInsured.Email                    = Email;
            newInsured.DateBirth                = BirthDate;
            newInsured.Phone_Number             = PhoneNumber;
            newInsured.Passport_Number_IdNumber = PassportNumber_ID;
            newInsured.City                     = City;
            newInsured.Postal_Code              = PostalCode;
            newInsured.Address                  = Address;
            newInsured.Date_Created             = DateTime.UtcNow;
            newInsured.Created_By               = CreatedById;
            try
            {
                insuredId = _iss.AddInsured(newInsured);
            }
            finally { }
            return(insuredId);
        }
Example #5
0
        public JObject GetExistentInsuredUserData(string ssn)
        {
            var dateTime       = ConfigurationManager.AppSettings["DateFormat"];
            var dateTimeFormat = dateTime != null && (dateTime.Contains("yy") && !dateTime.Contains("yyyy")) ? dateTime.Replace("yy", "yyyy") : dateTime;

            var     Result      = new JObject();
            insured InsuredUser = null;

            if (_roleAuthorize.IsUser("Admin"))
            {
                InsuredUser = _iss.GetInsuredBySsn(ssn);
            }
            else if (_roleAuthorize.IsUser("Broker"))
            {
                InsuredUser = _iss.GetInsuredBySsnAndCreatedBy(ssn, _us.GetUserIdByUsername(System.Web.HttpContext.Current.User.Identity.Name));
            }
            else if (_roleAuthorize.IsUser("Broker manager"))
            {
                InsuredUser = _iss.GetBrokerManagerInsuredBySsnAndCreatedBy(ssn, _us.GetUserIdByUsername(System.Web.HttpContext.Current.User.Identity.Name));
            }
            JObject insuredData = new JObject();

            if (InsuredUser != null)
            {
                insuredData.Add("FirstName", InsuredUser.Name);
                insuredData.Add("Name", InsuredUser.Lastname);
                insuredData.Add("Address", InsuredUser.Address);
                insuredData.Add("City", InsuredUser.City);
                insuredData.Add("PostalCode", InsuredUser.Postal_Code);
                insuredData.Add("Ssn", InsuredUser.SSN);

                insuredData.Add("DateBirth", InsuredUser.DateBirth.ToString(dateTimeFormat, new CultureInfo("en-US")));
                insuredData.Add("PassportID", InsuredUser.Passport_Number_IdNumber);
                insuredData.Add("Email", InsuredUser.Email);
                insuredData.Add("PhoneNumber", InsuredUser.Phone_Number);

                Result.Add("InsuredData", insuredData);
                return(Result);
            }
            else
            {
                Result.Add("response", "User with that SSN not found");
                return(Result);
            }
        }
Example #6
0
        public async Task <ActionResult> Index(string ssn)
        {
            if (!System.Web.HttpContext.Current.User.Identity.IsAuthenticated)
            {
                Response.Redirect(ConfigurationManager.AppSettings["webpage_url"] + "/Login");
            }

            Policy p = new Policy();

            var type_policies      = GetTypeOfPolicy();
            var countries          = GetTypeOfCountry();
            var franchises         = GetTypeOfFranchise();
            var additional_charges = GetTypeOfAdditionalCharges();

            await Task.WhenAll(type_policies, countries, franchises, additional_charges);

            ViewBag.TypeOfPolicy       = type_policies.Result;
            ViewBag.Countries          = countries.Result;
            ViewBag.Franchise          = franchises.Result;
            ViewBag.additional_charges = additional_charges.Result;
            ViewBag.DisableDefault     = false;

            if (!String.IsNullOrEmpty(ssn))
            {
                insured insured = _iss.GetInsuredBySsn(ssn);
                if (insured == null)
                {
                    return(View());
                }
                p.PolicyHolderAddress           = insured.Address;
                p.PolicyHolderBirthDate         = insured.DateBirth;
                p.PolicyHolderCity              = insured.City;
                p.PolicyHolderEmail             = insured.Email;
                p.PolicyHolderName              = insured.Name;
                p.PolicyHolderLastName          = insured.Lastname;
                p.PolicyHolderPostalCode        = insured.Postal_Code;
                p.PolicyHolderSSN               = insured.SSN;
                p.PolicyHolderPassportNumber_ID = insured.Passport_Number_IdNumber;
                return(View(p));
            }
            return(View());
        }
Example #7
0
        public async Task <ActionResult> Preview(int policyId)
        {
            travel_policy            policy            = _ps.GetPolicyById(policyId);
            insured                  policyHolder      = _ps.GetPolicyHolderByPolicyID(policyId);
            List <insured>           insureds          = _pis.GetAllInsuredByPolicyId(policyId);
            List <additional_charge> additionalCharges = _acs.GetAdditionalChargesByPolicyId(policyId);


            Policy policyPreview = new Policy
            {
                Policy_Number             = policy.Policy_Number,
                PaymentStatys             = policy.Payment_Status == true ? 1 : 0,
                Exchange_RateID           = policy.Exchange_RateID,
                CountryID                 = policy.CountryID,
                Policy_TypeID             = policy.Policy_TypeID,
                IsSamePolicyHolderInsured = policy.Policy_HolderID == policy.insured.ID,
                Date_Created              = policy.Date_Created,
                Created_By                = policy.Created_By,
                Start_Date                = policy.Start_Date,
                End_Date                      = policy.End_Date,
                Valid_Days                    = policy.Valid_Days,
                Travel_NumberID               = policy.Travel_NumberID,
                Total_Premium                 = policy.Total_Premium,
                PolicyHolderId                = policy.Policy_HolderID,
                PolicyHolderName              = policyHolder.Name,
                PolicyHolderAddress           = policyHolder.Address,
                PolicyHolderBirthDate         = policyHolder.DateBirth,
                PolicyHolderCity              = policyHolder.City,
                PolicyHolderEmail             = policyHolder.Email,
                PolicyHolderLastName          = policyHolder.Lastname,
                PolicyHolderPassportNumber_ID = policyHolder.Passport_Number_IdNumber,
                PolicyHolderPhoneNumber       = policyHolder.Phone_Number,
                PolicyHolderPostalCode        = policyHolder.Postal_Code,
                PolicyHolderSSN               = policyHolder.SSN,
                insureds                      = insureds,
                additional_charges            = additionalCharges,
                Address           = insureds[0].Address,
                Name              = insureds[0].Name,
                LastName          = insureds[0].Lastname,
                City              = insureds[0].City,
                PostalCode        = insureds[0].Postal_Code,
                BirthDate         = insureds[0].DateBirth,
                SSN               = insureds[0].SSN,
                Email             = insureds[0].Email,
                PhoneNumber       = insureds[0].Phone_Number,
                PassportNumber_ID = insureds[0].Passport_Number_IdNumber
            };
            var type_policies      = GetTypeOfPolicy();
            var countries          = GetTypeOfCountry();
            var franchises         = GetTypeOfFranchise();
            var additional_charges = GetTypeOfAdditionalCharges();

            await Task.WhenAll(type_policies, countries, franchises, additional_charges);

            ViewBag.TypeOfPolicy       = type_policies.Result;
            ViewBag.Countries          = countries.Result;
            ViewBag.Franchise          = franchises.Result;
            ViewBag.additional_charges = additional_charges.Result;
            ViewBag.Doplatok1          = 0;
            ViewBag.Doplatok2          = 0;
            if (additionalCharges.Count >= 1 && additionalCharges[0] != null)
            {
                if (additionalCharges[0].ID == 2)
                {
                    ViewBag.Doplatok1 = 1;
                }
            }
            if (additionalCharges.Count >= 2 && additionalCharges[1] != null)
            {
                if (additionalCharges[1].ID == 3)
                {
                    ViewBag.Doplatok2 = 1;
                }
            }
            ViewBag.DisableDefault = true;
            return(View(policyPreview));
        }
        public insured GetPolicyHolderByPolicyID(int PolicyID)
        {
            insured PolicyHolder = _db.travel_policy.Where(x => x.ID == PolicyID).Select(x => x.insured).Single();

            return(PolicyHolder);
        }
Example #9
0
 public long Create(insured _insured)
 {
     using MySqlConnection conexao = new MySqlConnection(_configuration.GetConnectionString("ConnMySql"));
     return(conexao.Insert(_insured));
 }
        public insured GetInsuredData(int InsuredId)
        {
            insured InsuredData = _db.insureds.Where(x => x.ID == InsuredId).SingleOrDefault();

            return(InsuredData);
        }
        public static int SavePolicy(Policy p,
                                     IPolicyService _ps,
                                     IUserService _us,
                                     IInsuredsService _iss,
                                     IPolicyInsuredService _pis,
                                     IAdditionalChargesService _acs)
        {
            var policy   = _ps.Create();
            var username = "";

            if (p.isMobile)
            {
                username          = p.username;
                policy.Created_By = _us.GetUserIdByUsername(p.username);
            }
            else
            {
                username          = System.Web.HttpContext.Current.User.Identity.Name;
                policy.Created_By = _us.GetUserIdByUsername(username);
            }

            policy.Date_Created            = DateTime.UtcNow;
            policy.Policy_Number           = _ps.CreatePolicyNumber();
            policy.CountryID               = p.CountryID;
            policy.Exchange_RateID         = (p.Exchange_RateID.HasValue) ? p.Exchange_RateID.Value : 1;
            policy.Policy_TypeID           = p.Policy_TypeID;
            policy.Retaining_RiskID        = p.Retaining_RiskID;
            policy.Start_Date              = p.Start_Date;
            policy.End_Date                = p.End_Date;
            policy.Valid_Days              = p.Valid_Days;
            policy.Travel_NumberID         = p.Travel_NumberID;
            policy.Total_Premium           = p.Total_Premium;
            policy.Payment_Status          = false;
            policy.Travel_Insurance_TypeID = p.Travel_Insurance_TypeID;

            RoleAuthorize r = new RoleAuthorize();

            if (p.IsSamePolicyHolderInsured && (p.isMobile || r.IsUser("End user")))
            {
                _us.UpdateSsnById(policy.Created_By, p.SSN);

                var PolicyHolderId = SaveInsuredHelper.SaveInsured(_iss, p.Name, p.LastName, p.SSN, p.Email, p.BirthDate, p.PhoneNumber, p.PassportNumber_ID, p.Address, p.City, p.PostalCode, policy.Created_By);
                policy.Policy_HolderID = PolicyHolderId;
            }
            else if (p.IsSamePolicyHolderInsured && (r.IsUser("Admin") || r.IsUser("Broker") || r.IsUser("Broker manager")))
            {
                if (p.IsExistentPolicyHolder)
                {
                    policy.Policy_HolderID = _iss.GetInsuredBySsn(p.SSN).ID;
                }
                else
                {
                    var PolicyHolderId = SaveInsuredHelper.SaveInsured(_iss, p.PolicyHolderName, p.PolicyHolderLastName, p.PolicyHolderSSN, p.PolicyHolderEmail, p.PolicyHolderBirthDate.Value, p.PolicyHolderPhoneNumber, p.PolicyHolderPassportNumber_ID, p.PolicyHolderAddress, p.PolicyHolderCity, p.PolicyHolderPostalCode, policy.Created_By);
                    policy.Policy_HolderID = PolicyHolderId;
                }
            }

            if (!p.IsSamePolicyHolderInsured)
            {
                var ssn = "";
                if (r.IsUser("Admin") || r.IsUser("Broker") || r.IsUser("Broker manager"))
                {
                    ssn = p.PolicyHolderSSN;
                    var policyHolderId = _iss.GetInsuredIdBySsnAndCreatedBy(ssn, policy.Created_By);
                    if (policyHolderId != -1)
                    {
                        insured updateInsuredData = new insured();

                        policy.Policy_HolderID     = policyHolderId;
                        updateInsuredData.ID       = policyHolderId;
                        updateInsuredData.Name     = p.PolicyHolderName;
                        updateInsuredData.Lastname = p.PolicyHolderLastName;
                        updateInsuredData.SSN      = p.PolicyHolderSSN;

                        updateInsuredData.Email        = p.PolicyHolderEmail;
                        updateInsuredData.DateBirth    = p.PolicyHolderBirthDate ?? DateTime.UtcNow;
                        updateInsuredData.Phone_Number = p.PolicyHolderPhoneNumber;

                        updateInsuredData.Passport_Number_IdNumber = p.PolicyHolderPassportNumber_ID;

                        updateInsuredData.City        = p.PolicyHolderCity;
                        updateInsuredData.Postal_Code = p.PolicyHolderPostalCode;
                        updateInsuredData.Address     = p.PolicyHolderAddress;

                        updateInsuredData.Date_Modified = DateTime.Now;
                        updateInsuredData.Modified_By   = policy.Created_By;

                        _iss.UpdateInsuredData(updateInsuredData);
                    }
                    else
                    {
                        var newInsured = _iss.Create();

                        newInsured.Name     = p.PolicyHolderName;
                        newInsured.Lastname = p.PolicyHolderLastName;
                        newInsured.SSN      = p.PolicyHolderSSN;

                        newInsured.Email        = p.PolicyHolderEmail;
                        newInsured.DateBirth    = p.PolicyHolderBirthDate ?? DateTime.UtcNow;
                        newInsured.Phone_Number = p.PolicyHolderPhoneNumber;

                        newInsured.Passport_Number_IdNumber = p.PolicyHolderPassportNumber_ID;

                        newInsured.City        = p.PolicyHolderCity;
                        newInsured.Postal_Code = p.PolicyHolderPostalCode;
                        newInsured.Address     = p.PolicyHolderAddress;

                        newInsured.Date_Created = DateTime.Now;
                        newInsured.Created_By   = policy.Created_By;
                        try
                        {
                            var Id = _iss.AddInsured(newInsured);
                            policy.Policy_HolderID = Id;
                        }
                        finally { }
                    }
                }
                else if (r.IsUser("End user"))
                {
                    ssn = _us.GetUserSsnByUsername(username);
                    var policyHolderId = _iss.GetInsuredIdBySsnAndCreatedBy(ssn, policy.Created_By);
                    if (policyHolderId != -1)
                    {
                        policy.Policy_HolderID = policyHolderId;
                    }
                    else
                    {
                        var currentEndUser = _us.GetUserDataByUsername(username);
                        var newInsured     = _iss.Create();

                        newInsured.Name     = currentEndUser.FirstName;
                        newInsured.Lastname = currentEndUser.LastName;
                        newInsured.SSN      = currentEndUser.EMBG;

                        newInsured.Email        = currentEndUser.Email;
                        newInsured.DateBirth    = currentEndUser.DateOfBirth.HasValue == true ? currentEndUser.DateOfBirth.Value: DateTime.Now;
                        newInsured.Phone_Number = currentEndUser.PhoneNumber;

                        newInsured.Passport_Number_IdNumber = currentEndUser.PassportNumber;

                        newInsured.City        = currentEndUser.City;
                        newInsured.Postal_Code = currentEndUser.PostalCode;
                        newInsured.Address     = currentEndUser.Address;

                        newInsured.Date_Created = DateTime.Now;
                        newInsured.Created_By   = policy.Created_By;
                        try
                        {
                            var Id = _iss.AddInsured(newInsured);
                            policy.Policy_HolderID = Id;
                        }
                        finally { }
                    }
                }
            }

            var policyID  = _ps.AddPolicy(policy);
            var insuredId = _iss.GetInsuredIdBySsnAndCreatedBy(p.SSN, policy.Created_By);

            if (insuredId != -1)
            {
                // da se update
                var policyInsured = _pis.Create();
                policyInsured.InsuredID = insuredId;
                policyInsured.PolicyID  = policyID;
                _pis.Add(policyInsured);
            }
            else
            {
                var newInsured = _iss.Create();
                newInsured.Date_Created = DateTime.Now;
                newInsured.Created_By   = policy.Created_By;
                newInsured.Name         = p.Name;
                newInsured.Lastname     = p.LastName;
                newInsured.SSN          = p.SSN;

                newInsured.Email        = p.Email;
                newInsured.DateBirth    = p.BirthDate;
                newInsured.Phone_Number = p.PhoneNumber;

                newInsured.Passport_Number_IdNumber = p.PassportNumber_ID;

                newInsured.City        = p.City;
                newInsured.Postal_Code = p.PostalCode;
                newInsured.Address     = p.Address;
                try
                {
                    var            insuredIdNew  = _iss.AddInsured(newInsured);
                    policy_insured policyInsured = new policy_insured();
                    policyInsured.InsuredID = insuredIdNew;
                    policyInsured.PolicyID  = policyID;
                    _pis.Add(policyInsured);
                }
                finally { }
            }

            if (p.isMobile)
            {
                if (p.AdditionalChargeId1 != 1)
                {
                    var addChargeNew = _acs.Create();
                    addChargeNew.PolicyID            = policyID;
                    addChargeNew.Additional_ChargeID = p.AdditionalChargeId1;
                    _acs.AddAdditionalChargesPolicy(addChargeNew);
                }

                if (p.AdditionalChargeId2 != 1)
                {
                    var addChargeNew = _acs.Create();
                    addChargeNew.PolicyID            = policyID;
                    addChargeNew.Additional_ChargeID = p.AdditionalChargeId2;
                    _acs.AddAdditionalChargesPolicy(addChargeNew);
                }
            }
            else
            {
                if (p.additional_charges != null)
                {
                    foreach (additional_charge additionalCharge in p.additional_charges)
                    {
                        if (additionalCharge.ID != 1)
                        {
                            var addChargeNew = _acs.Create();
                            addChargeNew.PolicyID            = policyID;
                            addChargeNew.Additional_ChargeID = additionalCharge.ID;
                            _acs.AddAdditionalChargesPolicy(addChargeNew);
                        }
                    }
                }
            }
            return(policyID);
        }