Exemplo n.º 1
0
        public bool SavePolicy(PolicyViewModel policy, string package, string franshiza, string tipkind, string tipkind1, int typepolicy, out string policyID)
        {
            //Tipkind p_tipkind1=null;
            //Tipkind p_tipkind2 = null;
            //Package p_pckg=null;
            //Franshiza p_f=null;
            policyID = string.Empty;
            ValidatePolicy(policy);
            int     p_tipkindContractor = Convert.ToInt32(tipkind);
            int     p_tipkindInsured    = Convert.ToInt32(tipkind1);
            Tipkind p_tipkind1          = context.Tipkinds.FirstOrDefault(x => x.Id == p_tipkindContractor);
            Tipkind p_tipkind2          = context.Tipkinds.FirstOrDefault(x => x.Id == p_tipkindInsured);

            Policy ac = new Policy();

            ac.Contractor    = new List <Contractor>();
            ac.Insurers      = new List <Insured>();
            ac.Beneficiaries = new List <Beneficiary>();
            ac.Vehicles      = new List <Vehicle>();

            ac.DateSale     = DateTime.Now;
            ac.FromDate     = policy.FromDate;
            ac.ToDate       = policy.ToDate;
            ac.Moment       = DateTime.Now;
            ac.Premium      = policy.Premium;
            ac.DDV          = policy.DDV;
            ac.Premiumtotal = policy.Premium + policy.DDV;

            Contractor acc = new Contractor();

            acc.Tipkind   = p_tipkind1.Id.ToString();
            acc.Name      = policy.ContractorName;
            acc.Surname   = policy.ContractorSurname;
            acc.EMBG      = policy.ContractorEMBG;
            acc.Regnumber = policy.ContractorRegnumber;
            acc.Phone     = policy.ContractorPhone;
            acc.Fax       = policy.ContractorFax;
            ac.Contractor.Add(acc);

            Insured accc = new Insured();

            accc.Tipkind   = p_tipkind2.Id.ToString();
            accc.Name      = policy.InsuredName;
            accc.Surname   = policy.InsuredSurname;
            accc.EMBG      = policy.InsuredEMBG;
            accc.Regnumber = policy.InsuredRegnumber;
            accc.Phone     = policy.InsuredPhone;
            accc.Fax       = policy.InsuredFax;
            ac.Insurers.Add(accc);

            Vehicle acccc = new Vehicle();

            acccc.TypeVehicle = policy.VehicleTypeVehicle;
            acccc.Regnumber   = policy.VehicleRegnumber;
            acccc.Chassis     = policy.VehicleChassis;
            acccc.MotorNum    = policy.VehicleMotorNum;
            acccc.Power       = policy.VehiclePower;
            acccc.Capacity    = policy.VehicleCapacity;
            acccc.Color       = policy.VehicleColor;
            acccc.SeetsNum    = policy.VehicleSeetsNum;
            ac.Vehicles.Add(acccc);

            if (typepolicy == 200)
            {
                int       p_package = Convert.ToInt32(package);
                Guid      p_fransh  = Guid.Parse(franshiza);
                Package   p_pckg    = context.Packages.FirstOrDefault(x => x.Id == p_package);
                Franshiza p_f       = context.Franshizas.FirstOrDefault(x => x.Id == p_fransh);

                ac.Package   = p_pckg.Id.ToString();
                ac.Franshiza = p_f.Id.ToString();
            }
            if (typepolicy == 201)
            {
            }

            context.Policies.Add(ac);
            try
            {
                context.SaveChanges();
                policyID = ac.ID.ToString();
                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }

            #region allcode
            //ValidatePolicy(policy);
            #region ConvertPackageFranshTipKind


            #endregion

            #region ContextFirstOrDefault

            #endregion

            #region PolicyModel
            //Policy p = new Policy();
            //p.Contractor = new List<Contractor>();
            //p.Insurers = new List<Insured>();
            //p.Beneficiaries = new List<Beneficiary>();
            //p.Vehicles = new List<Vehicle>();

            //p.Package = p_pckg.Id.ToString();
            //p.Franshiza = p_f.Id.ToString();
            //p.Moment = DateTime.Now;
            //p.DateSale = DateTime.Now;
            //p.FromDate = policy.FromDate;
            //p.ToDate = policy.ToDate;
            //p.Premium = policy.Premium;
            //p.DDV = policy.DDV;
            //p.Premiumtotal = policy.Premium + policy.DDV;
            #endregion
            //Dogovarac(toj sto gi dava parite)
            #region ContractorModel
            //Contractor c = new Contractor();
            //c.Tipkind = p_tipkind1.Id.ToString();
            //c.Name = policy.ContractorName;
            //c.Surname = policy.ContractorSurname;
            //c.EMBG = policy.ContractorEMBG;
            //c.Regnumber = policy.ContractorRegnumber;
            //c.Phone = policy.ContractorPhone;
            //c.Fax = policy.ContractorFax;
            //p.Contractor.Add(c);
            #endregion
            //Osigurenik(toj sto e pokrien so polisata)
            #region InsuredModel
            //Insured i = new Insured();
            //i.Tipkind = p_tipkind2.Id.ToString();
            //i.Name = policy.InsuredName;
            //i.Surname = policy.InsuredSurname;
            //i.EMBG = policy.InsuredEMBG;
            //i.Regnumber = policy.InsuredRegnumber;
            //i.Phone = policy.InsuredPhone;
            //i.Fax = policy.InsuredFax;
            //p.Insurers.Add(i);
            #endregion
            //Korisnik na sredstva(toj gi zema parite)
            #region BeneficiaryModel
            //Beneficiary b = new Beneficiary();
            //b.Name = policy.BeneficiaryName;
            //b.Surname = policy.BeneficiarySurname;
            //b.EMBG = policy.BeneficiaryEMBG;
            //b.Regnumber = policy.BeneficiaryRegnumber;
            //b.Phone = policy.BeneficiaryPhone;
            //b.Fax = policy.BeneficiaryEMBG;
            //p.Beneficiaries.Add(b);
            #endregion
            #region VehicleModel
            //Vehicle v = new Vehicle();
            //v.TypeVehicle = policy.VehicleTypeVehicle;
            //v.Regnumber = policy.VehicleRegnumber;
            //v.Chassis = policy.VehicleChassis;
            //v.MotorNum = policy.VehicleMotorNum;
            //v.Power = policy.VehiclePower;
            //v.Capacity = policy.VehicleCapacity;
            //v.Color = policy.VehicleColor;
            //v.SeetsNum = policy.VehicleSeetsNum;
            //p.Vehicles.Add(v);
            #endregion

            //Calculations
            //#region Calculations
            //decimal CapacityDec =Convert.ToDecimal(v.Capacity);
            //p.SumOsig = CapacityDec;

            #region SaveData
            //context.Policies.Add(p);
            //try
            //{
            //    context.SaveChanges();
            //    policyID = p.ID.ToString();
            //    return true;
            //}
            //catch (Exception ex)
            //{
            //    return false;
            //}
            #endregion
            #endregion
        }
Exemplo n.º 2
0
        public bool SavePolicy(PolicyViewModel policy, string package, string franshiza, string tipkind, string tipkind1, out string policyID)
        {
            policyID = string.Empty;
            ValidatePolicy(policy);
            #region ConvertPackageFranshTipKind
            int  p_package           = Convert.ToInt32(package);
            Guid p_fransh            = Guid.Parse(franshiza);
            int  p_tipkindContractor = Convert.ToInt32(tipkind);
            int  p_tipkindInsured    = Convert.ToInt32(tipkind1);
            #endregion

            #region ContextFirstOrDefault
            Package   p_pckg     = context.Packages.FirstOrDefault(x => x.Id == p_package);
            Franshiza p_f        = context.Franshizas.FirstOrDefault(x => x.Id == p_fransh);
            Tipkind   p_tipkind1 = context.Tipkinds.FirstOrDefault(x => x.Id == p_tipkindContractor);
            Tipkind   p_tipkind2 = context.Tipkinds.FirstOrDefault(x => x.Id == p_tipkindInsured);
            #endregion

            #region PolicyModel
            Policy p = new Policy();
            p.Contractor    = new List <Contractor>();
            p.Insurers      = new List <Insured>();
            p.Beneficiaries = new List <Beneficiary>();
            p.Vehicles      = new List <Vehicle>();

            p.Package      = p_pckg.Id.ToString();
            p.Franshiza    = p_f.Id.ToString();
            p.Moment       = DateTime.Now;
            p.DateSale     = DateTime.Now;
            p.FromDate     = policy.FromDate;
            p.ToDate       = policy.ToDate;
            p.Premium      = policy.Premium;
            p.DDV          = policy.DDV;
            p.Premiumtotal = policy.Premiumtotal;
            #endregion
            //Dogovarac(toj sto gi dava parite)
            #region ContractorModel
            Contractor c = new Contractor();
            c.Tipkind   = p_tipkind1.Id.ToString();
            c.Name      = policy.ContractorName;
            c.Surname   = policy.ContractorSurname;
            c.EMBG      = policy.ContractorEMBG;
            c.Regnumber = policy.ContractorRegnumber;
            c.Phone     = policy.ContractorPhone;
            c.Fax       = policy.ContractorFax;
            p.Contractor.Add(c);
            #endregion
            //Osigurenik(toj sto e pokrien so polisata)
            #region InsuredModel
            Insured i = new Insured();
            i.Tipkind   = p_tipkind2.Id.ToString();
            i.Name      = policy.InsuredName;
            i.Surname   = policy.InsuredSurname;
            i.EMBG      = policy.InsuredEMBG;
            i.Regnumber = policy.InsuredRegnumber;
            i.Phone     = policy.InsuredPhone;
            i.Fax       = policy.InsuredFax;
            p.Insurers.Add(i);
            #endregion
            //Korisnik na sredstva(toj gi zema parite)
            #region BeneficiaryModel
            Beneficiary b = new Beneficiary();
            b.Name      = policy.BeneficiaryName;
            b.Surname   = policy.BeneficiarySurname;
            b.EMBG      = policy.BeneficiaryEMBG;
            b.Regnumber = policy.BeneficiaryRegnumber;
            b.Phone     = policy.BeneficiaryPhone;
            b.Fax       = policy.BeneficiaryEMBG;
            p.Beneficiaries.Add(b);
            #endregion
            #region VehicleModel
            Vehicle v = new Vehicle();
            v.TypeVehicle = policy.VehicleTypeVehicle;
            v.Regnumber   = policy.VehicleRegnumber;
            v.Chassis     = policy.VehicleChassis;
            v.MotorNum    = policy.VehicleMotorNum;
            v.Power       = policy.VehiclePower;
            v.Capacity    = policy.VehicleCapacity;
            v.Color       = policy.VehicleColor;
            v.SeetsNum    = policy.VehicleSeetsNum;
            p.Vehicles.Add(v);
            #endregion

            //Calculations
            #region Calculations
            decimal CapacityDec = Convert.ToDecimal(v.Capacity);
            p.SumOsig = CapacityDec;
            #endregion
            #region SaveData
            context.Policies.Add(p);
            try
            {
                context.SaveChanges();
                policyID = p.ID.ToString();
                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
            #endregion
        }