Exemplo n.º 1
0
        public IActionResult Edit(Car carModel)
        {
            if (ModelState.IsValid)
            {
                var brandModelMatching = new CarModelValidation();

                if (brandModelMatching.AllowedModelsOnBrand[carModel.Brand.ToLower()].Contains(carModel.Model.ToLower()))
                {
                    var carFromDb = _dbContext.Car.Find(carModel.CarId);
                    carFromDb.Brand        = carModel.Brand;
                    carFromDb.EuroStandard = carModel.EuroStandard;
                    carFromDb.Model        = carModel.Model;
                    carFromDb.EngineCC     = carModel.EngineCC;
                    carFromDb.Year         = carModel.Year;
                    _dbContext.SaveChanges();

                    return(RedirectToAction("list", "car", new { area = "broker" }));
                }
                else
                {
                    ViewBag.BrandModelMatchingError = $"There is no match between {carModel.Brand} and {carModel.Model} !!!";
                    return(View(carModel)); // the brand/model combination does not exist
                }
            }
            else
            {
                return(View(carModel)); // some validation error occured, return model to the view to render the errors
            }
        }
Exemplo n.º 2
0
        public void UpdateLimitOnAccidentsCover()
        {
            using (var _dbContext = new CarInsuranceContextV3())
            {
                var limitRetrieved    = _dbContext.Limit.Where(pk => pk.LimitCoverId.Equals(_testedBrokerGuid)).FirstOrDefault();
                var listOfLimitValues = new List <int>();
                foreach (var limit in limitRetrieved.LimitValues.Split(',', StringSplitOptions.RemoveEmptyEntries))
                {
                    listOfLimitValues.Add(int.Parse(limit));
                }
                listOfLimitValues.Add(2000);

                var newLimitValues = string.Empty;
                foreach (var limit in listOfLimitValues)
                {
                    newLimitValues += limit.ToString() + ",";
                }

                limitRetrieved.LimitValues = newLimitValues;
                _dbContext.SaveChanges();

                var limitRetrieved2 = _dbContext.Limit.Where(pk => pk.LimitCoverId.Equals(_testedBrokerGuid)).FirstOrDefault();

                Assert.AreEqual(limitRetrieved2.LimitValues.Split(',', StringSplitOptions.RemoveEmptyEntries).ToList().Last(), "2000");
            }
        }
Exemplo n.º 3
0
        public void AddLimitRuleForLimit()
        {
            using (var _dbContext = new CarInsuranceContextV3())
            {
                var coverRetrieved = _dbContext.Cover.Where(c => c.CoverBrokerRefId.Equals(_testedBrokerGuid) && c.Type.Equals("theft"))
                                     .Include(l => l.Limit)
                                     .FirstOrDefault();


                var newLimitRule1 = new LimitRule()
                {
                    LimitRuleCoverId = coverRetrieved.Limit.FirstOrDefault().LimitRuleCoverId,
                    Name             = "Equal500",
                    RuleText         = "EqualTo500",
                    Multiplier       = 0.6f,
                };

                var newLimitRule2 = new LimitRule()
                {
                    LimitRuleCoverId = coverRetrieved.Limit.FirstOrDefault().LimitRuleCoverId,
                    Name             = "Equal1000",
                    RuleText         = "EqualTo1000",
                    Multiplier       = 0.8f,
                };

                _dbContext.LimitRule.AddRange(newLimitRule1, newLimitRule2);
                _dbContext.SaveChanges();
            }
        }
Exemplo n.º 4
0
        //[Ignore("Outdated")]
        public void AddingLimitAndCheckingItBack()
        {
            using (var _dbContext = new CarInsuranceContextV3())
            {
                var brokerTemplate = new BrokerPolicyTemplate()
                {
                    BrokerReferenceId = _testedBrokerGuid,
                    CarBrokerRefId    = _testedBrokerGuid,
                    CoverBrokerRefId  = _testedBrokerGuid,
                    CreationDate      = DateTime.Now,
                    TemplateReady     = false,
                };

                _dbContext.BrokerPolicyTemplate.Add(brokerTemplate);
                _dbContext.SaveChanges();

                var coverAccidents = new Cover()
                {
                    CoverBrokerRefId = _testedBrokerGuid,
                    AdditionDate     = DateTime.Now,
                    LimitCoverId     = _testedBrokerGuid,
                    QuestionCoverId  = _testedBrokerGuid,
                    Type             = "accidents"
                };

                _dbContext.Cover.Add(coverAccidents);
                _dbContext.SaveChanges();

                Limit limit = new Limit
                {
                    LimitCoverId     = _testedBrokerGuid,
                    CoverType        = "accidents",
                    LimitRuleCoverId = _testedBrokerGuid,
                    LimitValues      = "0,100,500,1000",
                    Name             = "AccidentsLimit"
                };

                _dbContext.Limit.Add(limit);
                var res = _dbContext.SaveChanges();

                Assert.AreEqual(res, 1);

                var retrievedLimit = _dbContext.Limit.Where(pk => pk.LimitCoverId.Equals(_testedBrokerGuid)).FirstOrDefault();

                Assert.IsTrue(retrievedLimit.CoverType.Equals("accidents"));
            }
        }
Exemplo n.º 5
0
        public void Update(BrokerPolicyTemplate template)
        {
            var templateFromDb = _dbContext.BrokerPolicyTemplate.FirstOrDefault(t => t.CoverBrokerRefId.Equals(template.CoverBrokerRefId));

            if (templateFromDb != null)
            {
                templateFromDb.TemplateReady = template.TemplateReady;
                _dbContext.SaveChanges();
            }
        }
Exemplo n.º 6
0
        public void Update(Cover cover)
        {
            var coverFromDb = _dbContext.Cover.FirstOrDefault(c => c.CoverBrokerRefId.Equals(cover.CoverBrokerRefId));

            if (coverFromDb != null)
            {
                coverFromDb.Limit    = cover.Limit;
                coverFromDb.Question = cover.Question;

                _dbContext.SaveChanges();
            }
        }
Exemplo n.º 7
0
        public void Update(Car car)
        {
            var carFromDb = _dbContext.Car.FirstOrDefault(c => c.CarBrokerRefId.Equals(car.CarBrokerRefId));

            if (carFromDb != null)
            {
                carFromDb.Brand = car.Brand;
                carFromDb.Model = car.Model;
                carFromDb.EngineCC = car.EngineCC;
                carFromDb.EuroStandard = car.EuroStandard;
                carFromDb.Year = car.Year;

                _dbContext.SaveChanges();
            }
        }
Exemplo n.º 8
0
        public void AddGoodCover()
        {
            using (var _dbContext = new CarInsuranceContextV3())
            {
                var testCover = new Cover()
                {
                    CoverBrokerRefId = _testedBrokerGuid,
                    AdditionDate     = DateTime.Now,
                    LimitCoverId     = Guid.NewGuid(),
                    QuestionCoverId  = Guid.NewGuid(),
                    Type             = "theft"
                };

                _dbContext.Cover.Add(testCover);
                var result = _dbContext.SaveChanges();
                Assert.AreEqual(result, 1);
            }
        }
Exemplo n.º 9
0
        public void AddLimitForCover()
        {
            using (var _dbContext = new CarInsuranceContextV3())
            {
                var coverRetrieved = _dbContext.Cover.Where(c => c.CoverBrokerRefId.Equals(_testedBrokerGuid) && c.Type.Equals("theft")).FirstOrDefault();

                var newLimit = new Limit()
                {
                    CoverType        = coverRetrieved.Type,
                    LimitCoverId     = coverRetrieved.LimitCoverId,
                    LimitRuleCoverId = Guid.NewGuid(),
                    Name             = "TheftLimit",
                    LimitValues      = "0,100,1000"
                };

                _dbContext.Limit.Add(newLimit);
                _dbContext.SaveChanges();
            }
        }
Exemplo n.º 10
0
        public void AddGoodCar()
        {
            using (var _dbContext = new CarInsuranceContextV3())
            {
                var car = new Car()
                {
                    CarBrokerRefId = _testedBrokerGuid,
                    Brand          = "Opel",
                    EngineCC       = 1600,
                    EuroStandard   = "euro4",
                    Model          = "astra",
                    Year           = DateTime.Parse("05/06/2008"),
                    CarRuleCoverId = Guid.NewGuid()
                };

                _dbContext.Car.Add(car);
                var result = _dbContext.SaveChanges();
                Assert.AreEqual(result, 1);
            }
        }
Exemplo n.º 11
0
        public bool CreateBrokerPolicyTemplate(AppUser user)
        {
            int result = 0;

            if (CheckIsBroker(user) && !CheckBrokerHasPolicyTemplate(user))
            {
                var brokerTemplate = new BrokerPolicyTemplate()
                {
                    BrokerReferenceId = Guid.Parse(user.Id),
                    CarBrokerRefId    = Guid.Parse(user.Id),
                    CoverBrokerRefId  = Guid.Parse(user.Id),
                    CreationDate      = DateTime.Now,
                    TemplateReady     = false
                };

                _dbContext.BrokerPolicyTemplate.Add(brokerTemplate);
                result = _dbContext.SaveChanges();
            }
            return(result == 1);
        }
Exemplo n.º 12
0
        public void CoverAdditionCoverTypeConstraints()
        {
            using (var _dbContext = new CarInsuranceContextV3())
            {
                var testCover = new Cover()
                {
                    CoverBrokerRefId = _testedBrokerGuid,
                    AdditionDate     = DateTime.Now,
                    LimitCoverId     = Guid.NewGuid(),
                    QuestionCoverId  = Guid.NewGuid(),
                    Type             = "test"
                };

                try
                {
                    _dbContext.Cover.Add(testCover);
                    _dbContext.SaveChanges();
                }
                catch (SqlException ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
        }
Exemplo n.º 13
0
 public int Save()
 {
     return(_dbContext.SaveChanges());
 }