private async Task <Tax> AddTax(Tax tax) { if (!ValidTaxAmount(tax.TaxAmount)) { throw new TaxesManagerException(Messages.TaxAmountOutOfRange); } if (tax.Municipality == null || tax.StartDate == null || tax.EndDate == null) { throw new TaxesManagerException(Messages.MissingPrimaryKey); } if (TaxExists(tax.Municipality, tax.StartDate, tax.EndDate)) { throw new TaxesManagerException(Messages.ExistingTax); } try { _context.Taxes.Add(tax); await _context.SaveChangesAsync(); } catch (DbUpdateException) { throw new TaxesManagerException(); } return(tax); }
internal async Task CleanUpDatabase() { var taxes = _context.Taxes; _context.Taxes.RemoveRange(taxes); await _context.SaveChangesAsync(); }