public PaymentController(IUserService us, IPolicyService ps, IInsuredsService iss, IPolicyInsuredService pis, IAdditionalChargesService acs)
 {
     ViewBag.IsPaid = false;
     this._us       = us;
     this._ps       = ps;
     _iss           = iss;
     _pis           = pis;
     _acs           = acs;
 }
Ejemplo n.º 2
0
 public PolicyController(IPolicyService ps, IPolicyTypeService pts, ICountryService cs, IFranchiseService fs,
                         IAdditionalChargesService acs, IUserService us, IInsuredsService iss, IPolicyInsuredService pis, IOkSetupService os)
 {
     _ps            = ps;
     _pts           = pts;
     _cs            = cs;
     _fs            = fs;
     _acs           = acs;
     _us            = us;
     _iss           = iss;
     _pis           = pis;
     _roleAuthorize = new RoleAuthorize();
     _os            = os;
 }
        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);
        }
Ejemplo n.º 4
0
 public MobileApiController(IUserService us,
                            IPolicyInsuredService pis,
                            IAdditionalChargesService acs,
                            IPolicyService ps,
                            IFirstNoticeOfLossService fnls,
                            IHealthInsuranceService his,
                            ILuggageInsuranceService lis,
                            IOkSetupService oss,
                            IBankAccountService bas,
                            IInsuredsService iss,
                            IFirstNoticeOfLossService fis,
                            IPolicyTypeService pts,
                            IAdditionalInfoService ais,
                            ICountryService coun,
                            IExchangeRateService exch,
                            IFranchiseService fran,
                            ITravelNumberService tn,
                            IOkSetupService os)
 {
     _ps   = ps;
     _us   = us;
     _fnls = fnls;
     _lis  = lis;
     _oss  = oss;
     _his  = his;
     _bas  = bas;
     _iss  = iss;
     _fis  = fis;
     _pts  = pts;
     _ais  = ais;
     _pis  = pis;
     _acs  = acs;
     _coun = coun;
     _exch = exch;
     _fran = fran;
     _tn   = tn;
     _os   = os;
 }
 public FirstNoticeOfLossController(IUserService us,
                                    IPolicyService ps,
                                    IPolicyInsuredService pis,
                                    IInsuredsService iss,
                                    IFirstNoticeOfLossService fis,
                                    IBankAccountService bas,
                                    IPolicyTypeService pts,
                                    IAdditionalInfoService ais,
                                    IHealthInsuranceService his,
                                    ILuggageInsuranceService lis,
                                    IFirstNoticeOfLossArchiveService firstNoticeLossArchiveService)
 {
     _us  = us;
     _ps  = ps;
     _pis = pis;
     _iss = iss;
     _bas = bas;
     _pts = pts;
     _ais = ais;
     _fis = fis;
     _his = his;
     _lis = lis;
     _firstNoticeLossArchiveService = firstNoticeLossArchiveService;
 }
        public static int SaveFirstNoticeOfLoss(IInsuredsService _iss, IUserService _us, IFirstNoticeOfLossService _fis,
                                                IBankAccountService _bas, IPolicyTypeService _pts, IAdditionalInfoService _ais,
                                                FirstNoticeOfLossReportViewModel firstNoticeOfLossViewModel, IEnumerable <HttpPostedFileBase> invoices,
                                                IEnumerable <HttpPostedFileBase> documentsHealth, IEnumerable <HttpPostedFileBase> documentsLuggage)
        {
            var result         = -1;
            var additionalInfo = _ais.Create();

            if (firstNoticeOfLossViewModel.IsHealthInsurance)
            {
                additionalInfo.Accident_place = firstNoticeOfLossViewModel.AccidentPlaceHealth;
                if (firstNoticeOfLossViewModel.AccidentDateTimeHealth != null)
                {
                    var      dateTime = firstNoticeOfLossViewModel.AccidentDateTimeHealth.Value;
                    var      timeSpan = firstNoticeOfLossViewModel.AccidentTimeHealth.Value;
                    DateTime d        = new DateTime(dateTime.Year, dateTime.Month, dateTime.Day);
                    d.Add(timeSpan);
                    additionalInfo.Datetime_accident = d;
                }
                var healthInsuranceInfo = new health_insurance_info
                {
                    Additional_infoId        = _ais.Add(additionalInfo),
                    additional_info          = additionalInfo,
                    Datetime_doctor_visit    = firstNoticeOfLossViewModel.DoctorVisitDateTime,
                    Doctor_info              = firstNoticeOfLossViewModel.DoctorInfo,
                    Medical_case_description = firstNoticeOfLossViewModel.MedicalCaseDescription,
                    Previous_medical_history = firstNoticeOfLossViewModel.PreviousMedicalHistory,
                    Responsible_institution  = firstNoticeOfLossViewModel.ResponsibleInstitution
                };

                try
                {
                    _ais.AddHealthInsuranceInfo(healthInsuranceInfo);
                }
                finally { }
            }
            else
            {
                additionalInfo.Accident_place = firstNoticeOfLossViewModel.AccidentPlaceLuggage;
                if (firstNoticeOfLossViewModel.AccidentDateTimeLuggage != null)
                {
                    var      dateTime = firstNoticeOfLossViewModel.AccidentDateTimeLuggage.Value;
                    var      timeSpan = firstNoticeOfLossViewModel.AccidentTimeLuggage.Value;
                    DateTime d        = new DateTime(dateTime.Year, dateTime.Month, dateTime.Day);
                    additionalInfo.Datetime_accident = d + timeSpan;
                }
                var luggageInsuranceInfo = new luggage_insurance_info
                {
                    Additional_infoId     = _ais.Add(additionalInfo),
                    additional_info       = additionalInfo,
                    Place_description     = firstNoticeOfLossViewModel.PlaceDescription,
                    Detail_description    = firstNoticeOfLossViewModel.DetailDescription,
                    Report_place          = firstNoticeOfLossViewModel.ReportPlace,
                    Floaters              = firstNoticeOfLossViewModel.Floaters,
                    Floaters_value        = float.Parse(firstNoticeOfLossViewModel.FloatersValue),
                    Luggage_checking_Time = firstNoticeOfLossViewModel.LugaggeCheckingTime ?? new TimeSpan(0, 0, 0)
                };

                try
                {
                    _ais.AddLuggageInsuranceInfo(luggageInsuranceInfo);
                }
                finally { }
            }
            var firstNoticeOfLossEntity = _fis.Create();

            firstNoticeOfLossEntity.PolicyId   = firstNoticeOfLossViewModel.PolicyId;
            firstNoticeOfLossEntity.ClaimantId = firstNoticeOfLossViewModel.ClaimantId;
            firstNoticeOfLossEntity.Relation_claimant_policy_holder = firstNoticeOfLossViewModel.RelationClaimantPolicyHolder;
            firstNoticeOfLossEntity.Destination       = firstNoticeOfLossViewModel.Destination;
            firstNoticeOfLossEntity.Depart_Date_Time  = firstNoticeOfLossViewModel.DepartDateTime;
            firstNoticeOfLossEntity.Arrival_Date_Time = firstNoticeOfLossViewModel.ArrivalDateTime;
            firstNoticeOfLossEntity.Transport_means   = firstNoticeOfLossViewModel.TransportMeans;
            firstNoticeOfLossEntity.Total_cost        = firstNoticeOfLossViewModel.TotalCost;
            firstNoticeOfLossEntity.CreatedDateTime   = DateTime.Now;
            firstNoticeOfLossEntity.FNOL_Number       = _fis.CreateFNOLNumber();

            string username;

            if (firstNoticeOfLossViewModel.isMobile)
            {
                username = firstNoticeOfLossViewModel.username;
            }
            else
            {
                username = System.Web.HttpContext.Current.User.Identity.Name;
            }
            firstNoticeOfLossEntity.CreatedBy = _us.GetUserIdByUsername(username);
            //firstNoticeOfLossEntity.Message = "";
            firstNoticeOfLossEntity.Additional_infoID = additionalInfo.ID;
            firstNoticeOfLossEntity.PolicyId          = firstNoticeOfLossViewModel.PolicyId;
            firstNoticeOfLossEntity.ClaimantId        = firstNoticeOfLossEntity.ClaimantId;
            firstNoticeOfLossEntity.Relation_claimant_policy_holder = firstNoticeOfLossEntity.Relation_claimant_policy_holder;

            if (!firstNoticeOfLossViewModel.isMobile && firstNoticeOfLossViewModel.ClaimantExistentBankAccount)
            {
                firstNoticeOfLossEntity.Claimant_bank_accountID = firstNoticeOfLossViewModel.ClaimantForeignBankAccountId;
            }
            else
            {
                var bankAccountId = SaveBankAccountInfoHelper.SaveBankAccountInfo(_bas, firstNoticeOfLossViewModel.ClaimantId,
                                                                                  firstNoticeOfLossViewModel.ClaimantBankName,
                                                                                  firstNoticeOfLossViewModel.ClaimantBankAccountNumber);

                firstNoticeOfLossEntity.Claimant_bank_accountID = bankAccountId;
            }

            if (firstNoticeOfLossViewModel.PolicyHolderExistentBankAccount)
            {
                firstNoticeOfLossEntity.Policy_holder_bank_accountID = firstNoticeOfLossViewModel.PolicyHolderForeignBankAccountId;
            }
            else
            {
                var bankAccountId = SaveBankAccountInfoHelper.SaveBankAccountInfo(_bas, firstNoticeOfLossViewModel.PolicyHolderId,
                                                                                  firstNoticeOfLossViewModel.PolicyHolderBankName,
                                                                                  firstNoticeOfLossViewModel.PolicyHolderBankAccountNumber);

                firstNoticeOfLossEntity.Policy_holder_bank_accountID = bankAccountId;
            }

            int FirstNoticeOfLossID = 0;

            try
            {
                FirstNoticeOfLossID = _fis.Add(firstNoticeOfLossEntity);
            }

            finally { }
            var lastDocumentId = _fis.LastDocumentId();

            if (invoices != null)
            {
                foreach (var file in invoices)
                {
                    lastDocumentId++;
                    if (file != null && file.ContentLength > 0)
                    {
                        string fileName = file.FileName + "_" + FirstNoticeOfLossID + "_" + lastDocumentId;
                        var    path     = @"~/DocumentsFirstNoticeOfLoss/Invoices/" + fileName;
                        file.SaveAs(System.Web.HttpContext.Current.Server.MapPath(path));

                        var document = new document();
                        document.Name = fileName;
                        var documentID = _fis.AddDocument(document);
                        _fis.AddInvoice(documentID);
                        _fis.AddDocumentToFirstNoticeOfLoss(documentID, FirstNoticeOfLossID);
                    }
                }
            }

            if (documentsHealth != null)
            {
                foreach (var file in documentsHealth)
                {
                    lastDocumentId++;
                    if (file != null && file.ContentLength > 0)
                    {
                        string fileName = file.FileName + "_" + FirstNoticeOfLossID + "_" + lastDocumentId;
                        var    path     = @"~/DocumentsFirstNoticeOfLoss/HealthInsurance/" + fileName;
                        file.SaveAs(System.Web.HttpContext.Current.Server.MapPath(path));
                        var document = new document();
                        document.Name = fileName;
                        var documentID = _fis.AddDocument(document);
                        _fis.AddDocumentToFirstNoticeOfLoss(documentID, FirstNoticeOfLossID);
                    }
                }
            }

            if (documentsLuggage != null)
            {
                foreach (var file in documentsLuggage)
                {
                    if (file != null && file.ContentLength > 0)
                    {
                        var path = @"~/DocumentsFirstNoticeOfLoss/LuggageInsurance/" + file.FileName;
                        file.SaveAs(System.Web.HttpContext.Current.Server.MapPath(path));
                        var document = new document();
                        document.Name = file.FileName;
                        var documentID = _fis.AddDocument(document);
                        _fis.AddDocumentToFirstNoticeOfLoss(documentID, FirstNoticeOfLossID);
                    }
                }
            }
            result = FirstNoticeOfLossID;
            return(result);
        }
 public ClientController(IInsuredsService ins, IUserService userService)
 {
     _ins         = ins;
     _userService = userService;
 }
        public static int SavePolicyFromMobile(AddPolicyMobileViewModel addPolicyMobile,
                                               IPolicyService _ps,
                                               IUserService _us,
                                               IInsuredsService _iss,
                                               IPolicyInsuredService _pis,
                                               IAdditionalChargesService _acs)
        {
            try
            {
                //add policy details
                var username = addPolicyMobile.Username;

                var policy = _ps.Create();
                policy.Policy_Number           = _ps.CreatePolicyNumber();
                policy.Exchange_RateID         = addPolicyMobile.Exchange_RateID;
                policy.CountryID               = addPolicyMobile.CountryID;
                policy.Policy_TypeID           = addPolicyMobile.Policy_TypeID;
                policy.Retaining_RiskID        = addPolicyMobile.Retaining_RiskID;
                policy.Start_Date              = addPolicyMobile.Start_Date;
                policy.End_Date                = addPolicyMobile.End_Date;
                policy.Valid_Days              = addPolicyMobile.Valid_Days;
                policy.Travel_NumberID         = addPolicyMobile.Travel_NumberID;
                policy.Travel_Insurance_TypeID = addPolicyMobile.Travel_Insurance_TypeID;
                policy.Total_Premium           = addPolicyMobile.Total_Premium;
                policy.Created_By              = addPolicyMobile.Created_By;
                policy.Date_Created            = DateTime.UtcNow;
                policy.Payment_Status          = false;

                //add policy holder
                var policyHolder = _iss.GetInsuredBySsnAndCreatedBy(addPolicyMobile.SSN, addPolicyMobile.Created_By);
                if (policyHolder == null)
                {
                    var policyHolderID = SaveInsuredHelper.SaveInsured(_iss, addPolicyMobile.Name,
                                                                       addPolicyMobile.LastName,
                                                                       addPolicyMobile.SSN,
                                                                       addPolicyMobile.Email,
                                                                       addPolicyMobile.DateBirth,
                                                                       addPolicyMobile.Phone_Number,
                                                                       addPolicyMobile.Passport_Number_IdNumber,
                                                                       addPolicyMobile.Address,
                                                                       addPolicyMobile.City,
                                                                       addPolicyMobile.Postal_Code,
                                                                       addPolicyMobile.Created_By);
                    policy.Policy_HolderID = policyHolderID;
                }
                else
                {
                    policy.Policy_HolderID = policyHolder.ID;
                }

                var policyID = _ps.AddPolicy(policy);

                if (addPolicyMobile.Insureds != null)
                {
                    foreach (var insured in addPolicyMobile.Insureds)
                    {
                        var addInsured   = _iss.GetInsuredBySsnAndCreatedBy(insured.SSN, addPolicyMobile.Created_By);
                        var addInsuredID = SaveInsuredHelper.SaveInsured(_iss, insured.Name,
                                                                         insured.Lastname,
                                                                         insured.SSN,
                                                                         insured.Email,
                                                                         insured.DateBirth,
                                                                         insured.Phone_Number,
                                                                         insured.Passport_Number_IdNumber,
                                                                         insured.Address,
                                                                         insured.City,
                                                                         insured.Postal_Code,
                                                                         addPolicyMobile.Created_By);

                        var policyInsured = _pis.Create();
                        policyInsured.InsuredID = addInsuredID;
                        policyInsured.PolicyID  = policyID;
                        _pis.Add(policyInsured);
                    }
                }

                if (addPolicyMobile.Additional_charges != null)
                {
                    foreach (var additionalChargeId in addPolicyMobile.Additional_charges)
                    {
                        var additionalChargeObject = _acs.GetAdditionalChargeById(additionalChargeId);
                        if (additionalChargeObject != null)
                        {
                            var addNewCharge = _acs.Create();
                            addNewCharge.PolicyID            = policyID;
                            addNewCharge.Additional_ChargeID = additionalChargeObject.ID;
                            _acs.AddAdditionalChargesPolicy(addNewCharge);
                        }
                    }
                }
                return(policyID);
            }
            catch (Exception e)
            {
                return(-1);
            }
        }
        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);
        }