// this method deletes a brand with matching brand id public async Task <int> DeleteBrand(int id) { try { Brand brand = await getBrandById(id); if (brand != null) { sde.Products.RemoveRange(brand.Products); await sde.SaveChangesAsync(); sde.Brands.Remove(brand); sde.SaveChanges(); return(1); } else { return(0); } } catch (Exception ex) { throw ex; } }
public async Task <int> DeletePacking(int id) { try { Packing pack = await getPackingById(id); if (pack != null) { sde.Products.RemoveRange(pack.Products); await sde.SaveChangesAsync(); sde.Packings.Remove(pack); sde.SaveChanges(); return(1); } else { return(0); } } catch (Exception ex) { throw ex; } }
public async Task <int> DeleteSubCategory(int id) { try { SubCategory subcat = await getSubCategoryById(id); if (subcat != null) { sde.Products.RemoveRange(subcat.Products); await sde.SaveChangesAsync(); sde.SubCategories.Remove(subcat); sde.SaveChanges(); return(1); } else { return(0); } } catch (Exception ex) { throw ex; } }
// DeleteProduct method to add new product to database. public async Task <int> DeleteProduct(int productId) { try { Product prod = await getProductById(productId); if (prod != null) { sde.Stocks.RemoveRange(prod.Stocks); await sde.SaveChangesAsync(); // In order to delete product, first we need to delete stock then we need to delete products sde.Products.Remove(prod); // deleting a product from product list sde.SaveChanges(); // saving the changes to database return(1); } else { return(0); } } catch (Exception ex) { throw ex; } }
// this method deletes the stock with matching stock id from database. public async Task <int> DeleteStock(int stockId) { try { Stock stock = await getStockByStockId(stockId); if (stock != null) { sde.Stocks.Remove(stock); sde.SaveChanges(); return(1); } else { return(0); } } catch (Exception ex) { throw ex; } }