public async Task <Response> DeleteProduct(ProductRequest productRequest) { if (productRequest == null) { throw new ArgumentNullException(nameof(productRequest)); } ProductAgg product = null; if (productRequest.ProductId != 0) { product = _bagelSalesControlContext.Product.ToList().Find(p => p.ProductId == productRequest.ProductId); if (product != null) { IDbContextTransaction transaction = _bagelSalesControlContext.Database.BeginTransaction(); _bagelSalesControlContext.Remove <ProductAgg>(product); await _bagelSalesControlContext.SaveChangesAsync(); transaction.Commit(); _bagelSalesControlContext.Dispose(); return(new Response { Message = "Product removed successfully" }); } } _bagelSalesControlContext.Dispose(); return(new Response { Notification = "ProductId is requerid" }); }
public async Task <Response> DeleteSale(SalesRequest salesRequest) { if (salesRequest == null) { throw new ArgumentNullException(nameof(salesRequest)); } Sales sale = null; if (salesRequest.SaleId != 0) { sale = _bagelSalesControlContext.Sales.ToList().Find(s => s.SaleId == salesRequest.SaleId); if (sale != null) { IDbContextTransaction transaction = _bagelSalesControlContext.Database.BeginTransaction(); _bagelSalesControlContext.Remove <Sales>(sale); await _bagelSalesControlContext.SaveChangesAsync(); transaction.Commit(); _bagelSalesControlContext.Dispose(); transaction.Dispose(); return(new Response { Message = "Sale removed successfully" }); } } _bagelSalesControlContext.Dispose(); return(new Response { Notification = "SaleId is requerid" }); }