private void SetupModels() { _conrtactId = 1; _contactServiceModel = new ContractServiceModel { Id = _conrtactId, CustomerId = 1, Date = It.IsAny <DateTime>(), Tarif = "postpejd", WorkerId = 1 }; _contractControllerModel = new ContractControllerModel { Id = _contactServiceModel.Id, CustomerId = _contactServiceModel.CustomerId, Tarif = _contactServiceModel.Tarif, WorkerId = _contactServiceModel.WorkerId }; _contractSreviceModelList = new List <ContractServiceModel> { new ContractServiceModel { Id = 1, CustomerId = 1, WorkerId = 1, Date = DateTime.Now, Tarif = "pripejd" }, new ContractServiceModel { Id = 2, CustomerId = 2, WorkerId = 2, Date = DateTime.Now, Tarif = "pripejd" } }; _custumerControllerModelList = new List <ContractControllerModel> { new ContractControllerModel { Id = 1, CustomerId = 1, WorkerId = 1, Tarif = "pripejd" }, new ContractControllerModel { Id = 1, CustomerId = 1, WorkerId = 1, Tarif = "pripejd" } }; }
public async Task Update_ShouldReturnCorrectResults() { string errorMessagePrefix = "ContractService Update(ContractServiceModel) method does not work properly."; var context = HealthInsDbContextInMemoryFactory.InitializeContext(); this.contractService = new ContractService(context); await SeedData(context); ContractServiceModel contract = context.Contracts.First().To <ContractServiceModel>(); contract.NextBillingDueDate = DateTime.Now; contract.StartDate = DateTime.Now; contract.Amount = 10000; contract.Frequency = "ANNUAL"; contract.Duration = 12; var actualResults = await this.contractService.Update(contract); var actualEntry = this.contractService.GetById(contract.Id); Assert.True(contract.NextBillingDueDate == actualEntry.NextBillingDueDate, errorMessagePrefix + " " + "NextBillingDueDate is not returned properly."); Assert.True(contract.StartDate == actualEntry.StartDate, errorMessagePrefix + " " + "StartDate is not returned properly."); Assert.True(contract.Amount == actualEntry.Amount, errorMessagePrefix + " " + "Amount is not returned properly."); Assert.True(contract.Frequency == actualEntry.Frequency, errorMessagePrefix + " " + "Frequency is not returned properly."); Assert.True(contract.Duration == actualEntry.Duration, errorMessagePrefix + " " + "Duration is not returned properly."); }
public async Task <bool> Create(ContractServiceModel contractServiceModel) { Contract contract = AutoMapper.Mapper.Map <Contract>(contractServiceModel); Product product = this.context.Products.SingleOrDefault(p => p.Idntfr == contractServiceModel.ProductIdntfr); Person person = this.context.Persons.SingleOrDefault(p => p.Id == contractServiceModel.PersonId); Distributor distributor = this.context.Distributors.SingleOrDefault(p => p.Id == contractServiceModel.DistributorId); contract.Product = product; contract.Person = person; contract.Distributor = distributor; contract.Status = Status.InForce; contract.CreationDate = DateTime.Now; contract.EndDate = contract.StartDate.AddYears(contract.Duration); var premiumAmount = this.ReturnPremiumAmount(contract); contract.PremiumAmount = premiumAmount; //contract.FrequencyRule = String.Join(" ", productServiceModel.FrequencyRule); context.Contracts.Add(contract); int result = await context.SaveChangesAsync(); contractServiceModel.Id = contract.Id; return(result > 0); }
public async Task Create_ShouldReturnCorrectResults() { string errorMessagePrefix = "ContractService Create(ContractServiceModel) method does not work properly."; var context = HealthInsDbContextInMemoryFactory.InitializeContext(); this.contractService = new ContractService(context); await SeedData(context); ContractServiceModel newContract = new ContractServiceModel() { Id = 4, Frequency = "ANNUAL", StartDate = DateTime.Parse("01/01/2019"), Duration = 10, ProductIdntfr = "LIFE1", PersonId = 39, DistributorId = 39 }; var actualResults = await this.contractService.Create(newContract); var actualEntry = this.contractService.GetById(4); Assert.True(newContract.Frequency == actualEntry.Frequency, errorMessagePrefix + " " + "Frequency is not returned properly."); Assert.True(newContract.StartDate == actualEntry.StartDate, errorMessagePrefix + " " + "StartDate is not returned properly."); }
public async Task <IActionResult> Edit(long id) { ContractServiceModel contractFromDB = this.contractService.GetById(id); ContractCreateInputModel contract = contractFromDB.To <ContractCreateInputModel>(); return(this.View(contract)); }
public async Task <IActionResult> Edit(ContractCreateInputModel contractCreateInputModel) { if (!this.ModelState.IsValid) { return(this.View(contractCreateInputModel)); } ContractServiceModel contractServiceModel = AutoMapper.Mapper.Map <ContractServiceModel>(contractCreateInputModel); var output = this.productService.CheckProductRules(contractServiceModel); if (output.Any()) { this.TempData["error"] = output.FirstOrDefault(); return(this.View(contractCreateInputModel)); } await this.contractService.Update(contractServiceModel); this.TempData["info"] = String.Format(CONTRACT_UPDATED, contractServiceModel.Id); return(this.Redirect("/Contract/Search")); }
public async Task <bool> Update(ContractServiceModel contractServiceModel) { Contract contractDB = this.context.Contracts.Include(c => c.Person).Include(c => c.Product).SingleOrDefault(p => p.Id == contractServiceModel.Id); Distributor distributor = this.context.Distributors.SingleOrDefault(d => d.Id == contractServiceModel.DistributorId); contractDB.Distributor = distributor; contractDB.Frequency = contractServiceModel.Frequency; contractDB.Amount = contractServiceModel.Amount; contractDB.Duration = contractServiceModel.Duration; contractDB.NextBillingDueDate = contractServiceModel.NextBillingDueDate; contractDB.StartDate = contractServiceModel.StartDate; contractDB.EndDate = contractServiceModel.StartDate.AddYears(contractServiceModel.Duration); var premiumAmount = this.ReturnPremiumAmount(contractDB); contractDB.PremiumAmount = premiumAmount; context.Update(contractDB); int result = await context.SaveChangesAsync(); return(result > 0); }
public async Task <IActionResult> Details(ContractViewModel contractViewModel) { ContractServiceModel contractFromDB = this.contractService.GetById(contractViewModel.Id); List <PremiumServiceModel> premiumsForContractServiceModel = await this.premiumService.FindPremiumsByContractId(contractViewModel.Id).ToListAsync(); List <PremiumViewModel> premiumsForContractViewModel = AutoMapper.Mapper.Map <List <PremiumViewModel> >(premiumsForContractServiceModel); List <MoneyInServiceModel> moneyInsForContractServiceModel = await this.moneyInService.FindMoneyInsByContractId(contractViewModel.Id).ToListAsync(); List <MoneyInViewModel> moneyInsForContractViewModel = AutoMapper.Mapper.Map <List <MoneyInViewModel> >(moneyInsForContractServiceModel); List <ClaimActivityServiceModel> claimsForContractServiceModel = await this.claimActivityService.FindClaimsActivityByContractId(contractViewModel.Id).ToListAsync(); List <ClaimActivityViewModel> claimsForContractViewModel = AutoMapper.Mapper.Map <List <ClaimActivityViewModel> >(claimsForContractServiceModel); ContractViewModel contract = contractFromDB.To <ContractViewModel>(); contract.PremiumsFound = premiumsForContractViewModel; contract.MoneyInsFound = moneyInsForContractViewModel; contract.ClaimsFound = claimsForContractViewModel; contract.SelectedTab = contractViewModel.SelectedTab; return(this.View(contract)); }
public List <string> CheckProductRules(ContractServiceModel contract) { var productId = contract.ProductIdntfr; var product = this.context.Products.SingleOrDefault(p => p.Idntfr == productId); DateTime startDt = contract.StartDate; List <string> output = new List <string>(); if (!product.FrequencyRule.Contains(contract.Frequency.ToString())) { string[] freqRule = product.FrequencyRule.Replace('_', '-').Split(","); string concat = ""; foreach (var s in freqRule) { if (freqRule[freqRule.Length - 1].Equals(s)) { concat += s.First().ToString().ToUpper() + String.Join("", s.ToLower().Skip(1)) + "!"; } else { concat += s.First().ToString().ToUpper() + String.Join("", s.ToLower().Skip(1)) + ", "; } } output.Add(ERROR_FREQUENCY_ALLOWED + concat); } var person = this.context.Persons.SingleOrDefault(p => p.Id == contract.PersonId); int age = person.GetAge(startDt); int maxAge = product.MaxAge; int minAge = product.MinAge; if (age > maxAge) { output.Add(String.Format(ERROR_MAXIMUM_AGE, age, maxAge)); } if (age < minAge) { output.Add(String.Format(ERROR_MINIMUM_AGE, age, minAge)); } return(output); }
public ContractController(ContractServiceModel contractServiceModel) { _contractServiceModel = contractServiceModel; }