private decimal GetTaxPercentForProduct(string productName) { VendorsTotalReportEntities context = new VendorsTotalReportEntities(); var taxPercent = 0m; using (context) { taxPercent = context.Taxes.Where(x => x.ProductName == productName).Select(x => x.TaxPercent).FirstOrDefault(); } return(taxPercent); }
public void AddTax(string productName) { VendorsTotalReportEntities context = new VendorsTotalReportEntities(); using (context) { Random rand = new Random(); int randomTaxPercent = rand.Next(10, 21); var tax = context.Taxes.Where(x => x.ProductName == productName).FirstOrDefault(); if (tax == null) { var newTax = new Tax() { ProductName = productName, TaxPercent = randomTaxPercent }; context.Taxes.Add(newTax); context.SaveChanges(); } } }