public void Remove(int id) { StockCard stockCard = List().FirstOrDefault(p => p.Id == id); context.StockCards.Remove(stockCard); context.SaveChanges(); }
public void Update(StockCard stockcard) { StockCard st = List().FirstOrDefault(p => p.TransLogId == stockcard.TransLogId); StockCard sc = context.StockCards.Find(st.Id); context.SaveChanges(); }
public void Add(StockCard stockcard) { if (stockcard.Date == DateTime.MinValue) { stockcard.Date = DateTime.Now; } stockcard.CompanyId = stockcard.CompanyId; context.StockCards.Add(stockcard); context.SaveChanges(); }
//For Stock Card public void InsertStockCard(int ReferenceId, int itemId, decimal unitcost, int quantiy) { ItemStockCardRepository stockcardRepo = new ItemStockCardRepository(); StockCard stockCard = new StockCard { ItemId = itemId, ReferenceModule = "Purchase Order", ReferenceId = ReferenceId, Qty = quantiy, UnitCost = unitcost, CompanyId = Sessions.CompanyId.Value, Date = DateTime.Now }; context.StockCards.Add(stockCard); }
public void InsertStockCard(int ReferenceId, int itemId, decimal unitcost, int quantiy, int?TransLogId) { ItemStockCardRepository stockcardRepo = new ItemStockCardRepository(); StockCard stockCard = new StockCard { ItemId = itemId, ReferenceModule = "Requisition", ReferenceId = ReferenceId, Qty = quantiy, UnitCost = unitcost, CompanyId = Sessions.CompanyId.Value, Date = DateTime.Now, TransLogId = TransLogId }; stockcardRepo.Add(stockCard); }
public void Save(PurchaseOrder po) { bool poExist = context.PurchaseOrders.Count(p => p.No == po.No) > 0; int id; if (!poExist) { po.ShipToCompany = null; po.Vendor = null; po.No = GeneratePoNumber(po.Date); context.PurchaseOrders.Add(po); context.SaveChanges(); id = po.Id; foreach (ItemPriceLogs poItem in po.ItemPriceLogs.ToList()) { poItem.PurchaseOrderId = id; InsertStockCard(id, poItem.ItemId, poItem.UnitCost, poItem.Qty); } } else { PurchaseOrder dbEntry = context.PurchaseOrders.FirstOrDefault(p => p.No == po.No); if (dbEntry != null) { dbEntry.No = po.No; dbEntry.Date = po.Date; dbEntry.VendorId = po.VendorId; dbEntry.ShipTo = po.ShipTo; dbEntry.Terms = vendorRepo.GetById(po.VendorId).Terms; dbEntry.PreparedBy = Common.GetCurrentUser.Id; dbEntry.ApprovedBy = Common.GetCurrentUser.GeneralManagerId; dbEntry.CheckedBy = po.CheckedBy; } id = dbEntry.Id; //Delete previous items foreach (PurchaseOrderItem poItem in dbEntry.PurchaseOrderItems.ToList()) { context.PurchaseOrderItems.Remove(poItem); } foreach (PurchaseOrderItem poItem in po.PurchaseOrderItems.ToList()) { poItem.PurchaseOrderId = id; context.PurchaseOrderItems.Add(poItem); } //Delete previous items foreach (ItemPriceLogs poItem in dbEntry.ItemPriceLogs.ToList()) { StockCard sc = context.StockCards.FirstOrDefault(p => p.ReferenceId == poItem.PurchaseOrderId); context.StockCards.Remove(sc); context.ItemPriceLogs.Remove(poItem); } foreach (ItemPriceLogs poItem in po.ItemPriceLogs.ToList()) { poItem.PurchaseOrderId = id; InsertStockCard(id, poItem.ItemId, poItem.UnitCost, poItem.Qty); context.ItemPriceLogs.Add(poItem); } } context.SaveChanges(); }