Ejemplo n.º 1
0
        /// <summary>
        /// Метод возвращает PolicyModel с данными полученными из Insurance.BL.Models.Policy.
        /// </summary>
        /// <param name="policy">Insurance.BL.Models.Policy по которому берутся данные.</param>
        /// <returns>PolicyModel с данными из Insurance.BL.Models.Policy. Свойство Client = null.</returns>
        public PolicyModel PolicyToPolicyModel(Policy policy)
        {
            if (policy == null)
            {
                return(null);
            }

            CarModel   carModel   = null;
            RatioModel ratioModel = null;

            if (policy.Car != null)
            {
                var carRepository = new CarRepository(_context);
                carModel = carRepository.CarToCarModel(policy.Car);
            }

            if (policy.Ratio != null)
            {
                var ratioRepository = new RatioRepository(_context);
                ratioModel = ratioRepository.RatioToRatioModel(policy.Ratio);
            }

            var policyModel = new PolicyModel()
            {
                policyCost  = policy.Cost,
                Client      = null,
                ClientEmail = policy.UsersEmail,
                PolicyDate  = policy.PolicyDate,
                Car         = carModel,
                Ratio       = ratioModel
            };

            if (carModel != null)
            {
                carModel.Policy = policyModel;
            }

            if (ratioModel != null)
            {
                ratioModel.Policy = policyModel;
            }

            return(policyModel);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Метод возвращает Insurance.BL.Models.Policy с данными полученными из PolicyModel.
        /// </summary>
        /// <param name="policyModel">PolicyModel по которому берутся данные.</param>
        /// <returns>Insurance.BL.Models.Policy с данными из PolicyModel.</returns>
        public Policy PolicyModelToPolicy(PolicyModel policyModel)
        {
            if (policyModel == null)
            {
                return(null);
            }

            Car   car   = null;
            Ratio ratio = null;

            if (policyModel.Car != null)
            {
                var carRepository = new CarRepository(_context);
                car = carRepository.CarModelToCar(policyModel.Car);
            }

            if (policyModel.Ratio != null)
            {
                var ratioRepository = new RatioRepository(_context);
                ratio = ratioRepository.RatioModelToRatio(policyModel.Ratio);
            }

            var clientEmail =
                policyModel.Client != null ?
                policyModel.Client.EMail : policyModel.ClientEmail != null ?
                policyModel.ClientEmail : null;

            var policy = new Policy
                         (
                policyModel.policyCost,
                clientEmail,
                policyModel.PolicyDate,
                car,
                ratio
                         );

            policy.PolicyId = policyModel.PolicyID;

            return(policy);
        }
Ejemplo n.º 3
0
 public void Initialize()
 {
     _ratioRepository = new RatioRepository();
 }