public static void addItemOrder(Item item, int userNo, string suppliercode) { string itemSupplier = item.supplier1; SOrder lastUnconfirmedAuto = StoreSupplierDAO.findLastUnapprovedOrder(userNo, suppliercode); if (lastUnconfirmedAuto.OrderItems.Where(x => x.itemcode == item.itemcode && x.purchaseordernumber == lastUnconfirmedAuto.purchaseordernumber).Count() == 0) { OrderItem oi = new OrderItem(); oi.purchaseordernumber = lastUnconfirmedAuto.purchaseordernumber; oi.itemcode = item.itemcode; oi.orderquantity = item.reorderquantity; oi.cost = StoreSupplierDAO.findTenderQuotation(itemSupplier, item.itemcode) * item.reorderquantity; ds.OrderItems.Attach(oi); ds.OrderItems.Add(oi); lastUnconfirmedAuto.OrderItems.Add(oi); if (lastUnconfirmedAuto.totalcost == null) { lastUnconfirmedAuto.totalcost = StoreSupplierDAO.findTenderQuotation(itemSupplier, item.itemcode) * oi.orderquantity; } else { lastUnconfirmedAuto.totalcost = lastUnconfirmedAuto.totalcost + StoreSupplierDAO.findTenderQuotation(itemSupplier, item.itemcode) * item.reorderquantity; } ds.SaveChanges(); } else { OrderItem oi = lastUnconfirmedAuto.OrderItems.Where(x => x.itemcode == item.itemcode && x.purchaseordernumber == lastUnconfirmedAuto.purchaseordernumber).First(); oi.orderquantity = oi.orderquantity + item.reorderquantity; oi.cost = StoreSupplierDAO.findTenderQuotation(itemSupplier, item.itemcode) * oi.orderquantity; if (lastUnconfirmedAuto.totalcost == null) { lastUnconfirmedAuto.totalcost = StoreSupplierDAO.findTenderQuotation(itemSupplier, item.itemcode) * oi.orderquantity; } else { lastUnconfirmedAuto.totalcost = lastUnconfirmedAuto.totalcost + StoreSupplierDAO.findTenderQuotation(itemSupplier, item.itemcode) * item.reorderquantity; } ds.SaveChanges(); } }