Example #1
0
        public IActionResult Create(InfoInsuranceModel iim)
        {
            if (!this.insuranceService.IsItInsuranceCreated(iim.Id))
            {
                try
                {
                    this.insuranceService.CreateInsuranceAsync(iim);
                }
                catch (Exception)
                {
                    this.BadRequest();
                }
            }

            return(this.Redirect("/Insurance/All"));
        }
        public void CreateInsurances()
        {
            var insurance = new InfoInsuranceModel()
            {
                Id          = "aa11bb22cc33",
                VinNumber   = "000001",
                DateOfStart = DateTime.UtcNow.Date,
                DateOfEnd   = DateTime.UtcNow.Date.AddYears(1),
                Description = "Insurance cost 100lv.",
            };

            this.insuranceService.CreateInsuranceAsync(insurance);
            var expect = 1;
            var real   = this.insuranceService.GetAllInsurances().Count();

            Assert.Equal(expect, real);
        }
        public async Task CreateInsuranceAsync(InfoInsuranceModel insuranceModel)
        {
            int result = DateTime.Compare(insuranceModel.DateOfStart, insuranceModel.DateOfEnd);

            if (result >= 0)
            {
                throw new ArgumentException("Not valid date!");
            }

            var insurance = new Insurance()
            {
                VinNumber   = insuranceModel.VinNumber,
                DateOfStart = insuranceModel.DateOfStart.ToString("d"),
                DateOfEnd   = insuranceModel.DateOfEnd.ToString("d"),
                Description = insuranceModel.Description,
            };

            await this.insuranceRepository.AddAsync(insurance);

            await this.insuranceRepository.SaveChangesAsync();
        }