public async Task <int> SeedDiscounts(IDiscountsService discountsService) { if (discountsService.All().Count == 0) { var child = new InputDiscountViewModel { Name = InputModelsConstants.ChildDiscountText, Percent = InputModelsConstants.ChildDiscountPercent }; var senior = new InputDiscountViewModel { Name = InputModelsConstants.SeniorDiscountText, Percent = InputModelsConstants.SeniorDiscountPercent }; var student = new InputDiscountViewModel { Name = InputModelsConstants.StudentDiscountText, Percent = InputModelsConstants.StudentDiscountPercent }; var normal = new InputDiscountViewModel { Name = InputModelsConstants.NormalDiscountText, Percent = InputModelsConstants.NormalDiscountPercent }; await discountsService.Add(child); await discountsService.Add(senior); await discountsService.Add(student); await discountsService.Add(normal); } return(0); }
public async Task <int> Add(InputDiscountViewModel model) { var discount = new Discount { Name = model.Name, Percent = model.Percent, }; await this._discountRepository.AddAsync(discount); var result = await this._discountRepository.SaveChangesAsync(); return(result); }