public void Add(Purchase entity) { entity.DateOfPurchase = DateTime.Now; _categoryContext.Purchases.Add(entity); _categoryContext.SaveChanges(); Stock brandCheck = _categoryContext.Stocks.Where(s => s.BrandID == entity.BrandID && s.ItemID == entity.ItemID).FirstOrDefault(); if (brandCheck == null) { Stock stock = new Stock(); stock.PurchaseID = entity.PurchaseID; stock.AvailableQuantity = entity.Quantity; stock.CostPricePerUnit = entity.CostPerUnit; stock.SellingPricePertUnit = entity.CostPerUnit + (entity.CostPerUnit * 10 / 100); stock.Discount = 0; stock.MRP = stock.SellingPricePertUnit - stock.Discount; stock.ItemID = entity.ItemID; stock.BrandID = entity.BrandID; _categoryContext.Stocks.Add(stock); _categoryContext.SaveChanges(); } else { Stock stock = _categoryContext.Stocks.Where(s => s.BrandID == entity.BrandID && s.ItemID == entity.ItemID).FirstOrDefault(); stock.AvailableQuantity = stock.AvailableQuantity + entity.Quantity; _categoryContext.SaveChanges(); } }
public void Add(OrderDetail entity) { Stock checkStock = _Context.Stocks.Where(s => s.StockID == entity.StockID).FirstOrDefault(); float stockToSell = checkStock.AvailableQuantity; try { if (stockToSell >= entity.Quantity) { Random random = new Random(); int unique1 = random.Next(); int uniqueID = unique1; CustomShippingAddress customShipping = new CustomShippingAddress(); customShipping.UniqueOrderID = uniqueID; customShipping.CellPhone = "Not Specified"; customShipping.ShippingAddress = "Not Specified"; _Context.CustomShippingAddress.Add(customShipping); _Context.SaveChanges(); Stock stock = _Context.Stocks.Where(s => s.StockID == entity.StockID).FirstOrDefault(); entity.PricePerUnit = stock.SellingPricePertUnit; entity.TotalBill = entity.PricePerUnit * (decimal)entity.Quantity; entity.UniqueID = uniqueID; entity.Status = "Pending"; entity.CustomerID = "Not Specified"; _Context.OrderDetails.Add(entity); _Context.SaveChanges(); // We should send uniqueID to the customer table where customer id = current login ID; Stock mainStock = _Context.Stocks.Where(s => s.StockID == entity.StockID).FirstOrDefault(); float availableStock = mainStock.AvailableQuantity; if (availableStock >= entity.Quantity) { mainStock.AvailableQuantity = availableStock - entity.Quantity; _Context.SaveChanges(); } else { } } } catch { } }
public void Add(Payment entity) { _categoryContext.Payments.Add(entity); _categoryContext.SaveChanges(); }
public void Add(Brand entity) { _brandContext.Brands.Add(entity); _brandContext.SaveChanges(); }
public void Add(Supplier entity) { _SupplierContext.Suppliers.Add(entity); _SupplierContext.SaveChanges(); }
public void Add(CancelOrder entity) { _cancelOrderContext.CancelOrders.Add(entity); _cancelOrderContext.SaveChanges(); }
public void Add(Category category) { _categoryContext.Categories.Add(category); _categoryContext.SaveChanges(); }
public void Add(Stock stock) { _categoryContext.Stocks.Add(stock); _categoryContext.SaveChanges(); }
public void Add(Customer entity) { _CustomerContext.Customers.Add(entity); _CustomerContext.SaveChanges(); }
public void Add(Item item) { _categoryContext.Items.Add(item); _categoryContext.SaveChanges(); }