public async Task Create_ShouldReturnCorrectResults(double operationAmount) { string errorMessagePrefix = "PremiumService Create(PremiumServiceModel) method does not work properly."; var context = HealthInsDbContextInMemoryFactory.InitializeContext(); this.moneyInService = new MoneyInService(context); await SeedData(context); MoneyInServiceModel moneyIn = new MoneyInServiceModel() { Id = 14, ContractId = 2, OperationAmount = operationAmount }; var actualResults = await this.moneyInService.Create(moneyIn); var actualEntry = context.MoneyIns.Include(m => m.Contract).SingleOrDefault(m => m.Id == 14); var contract = context.Contracts.SingleOrDefault(c => c.Id == actualEntry.Contract.Id); Assert.True(moneyIn.ContractId == actualEntry.Contract.Id, errorMessagePrefix + " " + "Contract is not returned properly."); Assert.True(moneyIn.OperationAmount == actualEntry.OperationAmount, errorMessagePrefix + " " + "OperationAmount is not returned properly."); Assert.True(HealthIns.Data.Models.Financial.Enums.Status.Pending == actualEntry.Status, errorMessagePrefix + " " + "Status is not set properly."); }
public async Task <bool> Create(MoneyInServiceModel moneyInServiceModel) { MoneyIn moneyIn = AutoMapper.Mapper.Map <MoneyIn>(moneyInServiceModel); Contract contract = this.context.Contracts.SingleOrDefault(p => p.Id == moneyInServiceModel.ContractId); moneyIn.Contract = contract; moneyIn.RecordDate = DateTime.Now; moneyIn.Status = HealthIns.Data.Models.Financial.Enums.Status.Pending; context.MoneyIns.Add(moneyIn); int result = await context.SaveChangesAsync(); return(result > 0); }
public async Task <IActionResult> Create(MoneyInCreateInputModel moneyInCreateInputModel) { if (!this.ModelState.IsValid) { return(this.View()); } MoneyInServiceModel moneyInServiceModel = AutoMapper.Mapper.Map <MoneyInServiceModel>(moneyInCreateInputModel); moneyInServiceModel.ContractId = moneyInCreateInputModel.Id; moneyInServiceModel.Id = 0; await this.moneyInService.Create(moneyInServiceModel); await this.contractService.TryToApplyFinancial(moneyInServiceModel.ContractId); this.TempData["info"] = String.Format(MONEYIN_CREATED); return(this.Redirect($"/Contract/Details/{moneyInServiceModel.ContractId}")); }