public void CreateAndUpdateRackItemLevel(RackItemLevelContract rackItemLevelContract) { var rackitemLevel = IRackItemLevelRepository.Get(rackItemLevelContract.Id); if (rackitemLevel != null) { //save rackitemLevel.Item = IitemRepository.Get(rackItemLevelContract.ItemId); rackitemLevel.Rack = IRackRepository.Get(rackItemLevelContract.RackId); rackitemLevel.CurrentQuantity = rackItemLevelContract.CurrentQuantity; rackitemLevel.InQuantity = rackItemLevelContract.InQuantity; rackitemLevel.OutQuantity = rackItemLevelContract.OutQuantity; IRackItemLevelRepository.Update(rackitemLevel); } else { //creat rackitemLevel = new RackItemLevel(); rackitemLevel.Item = IitemRepository.Get(rackItemLevelContract.ItemId); rackitemLevel.Rack = IRackRepository.Get(rackItemLevelContract.RackId); rackitemLevel.CurrentQuantity = rackItemLevelContract.CurrentQuantity; rackitemLevel.InQuantity = rackItemLevelContract.InQuantity; rackitemLevel.OutQuantity = rackItemLevelContract.OutQuantity; IRackItemLevelRepository.Insert(rackitemLevel); } }
public void CreateAndUpdatePurchaseOrder(SaleOrderContract saleOrderContract) { var saleOrder = SaleOrderRepository.Get(saleOrderContract.Id); if (saleOrder != null) { // Update Order saleOrder.Title = saleOrderContract.Title; for (int i = 0; i < saleOrderContract.SaleOrderItemContracts.Count; i++) { var temp = saleOrderContract.SaleOrderItemContracts[i]; if (saleOrder.SaleOrderItems.Any(x => x.Id == temp.Id)) { // Update OrdetItem .. var InDatabaseOrderItem = saleOrder.SaleOrderItems.FirstOrDefault(x => x.Id == temp.Id); InDatabaseOrderItem.NetPrice = temp.NetPrice; InDatabaseOrderItem.Quantity = temp.Quantity; InDatabaseOrderItem.UnitPrice = temp.UnitPrice; InDatabaseOrderItem.TotalPrice = temp.TotalPrice; InDatabaseOrderItem.Item = IitemRepository.Get(temp.ItemId); InDatabaseOrderItem.Rack = IRackRepository.Get(temp.RackId); } else { // Create OrderItem var InDatabaseOrderItem = new SaleOrderItem(); InDatabaseOrderItem.NetPrice = temp.NetPrice; InDatabaseOrderItem.Quantity = temp.Quantity; InDatabaseOrderItem.UnitPrice = temp.UnitPrice; InDatabaseOrderItem.TotalPrice = temp.TotalPrice; InDatabaseOrderItem.Item = IitemRepository.Get(temp.ItemId); InDatabaseOrderItem.Rack = IRackRepository.Get(temp.RackId); saleOrder.SaleOrderItems.Add(InDatabaseOrderItem); } } //Delete extra orderItems in order(DB) for (int i = 0; i < saleOrder.SaleOrderItems.Count; i++) { var temp = saleOrder.SaleOrderItems[i]; if (!saleOrderContract.SaleOrderItemContracts.Any(x => x.Id == temp.Id)) { saleOrder.SaleOrderItems.Remove(temp); } } SaleOrderRepository.Update(saleOrder); } else { // Create Order saleOrder = new SaleOrder(); saleOrder.Code = saleOrderContract.Code; saleOrder.CreationDate = saleOrderContract.CreationDate; saleOrder.Title = saleOrderContract.Title; for (int i = 0; i < saleOrderContract.SaleOrderItemContracts.Count; i++) { var temp = saleOrderContract.SaleOrderItemContracts[i]; var InDatabaseOrderItem = new SaleOrderItem(); InDatabaseOrderItem.NetPrice = temp.NetPrice; InDatabaseOrderItem.Quantity = temp.Quantity; InDatabaseOrderItem.UnitPrice = temp.UnitPrice; InDatabaseOrderItem.TotalPrice = temp.TotalPrice; InDatabaseOrderItem.Item = IitemRepository.Get(temp.ItemId); InDatabaseOrderItem.Rack = IRackRepository.Get(temp.RackId); saleOrder.SaleOrderItems.Add(InDatabaseOrderItem); } SaleOrderRepository.Insert(saleOrder); } }
public void CreateAndUpdatePurchaseOrder(PurchaseOrderContract purchaseOrderContract) { //db var purchaseOrder = PurchaseOrderRepository.Get(purchaseOrderContract.Id); if (purchaseOrder != null) { // Update Order purchaseOrder.Title = purchaseOrderContract.Title; for (int i = 0; i < purchaseOrderContract.PurchaseOrderItemContracts.Count; i++) { var temp = purchaseOrderContract.PurchaseOrderItemContracts[i]; if (purchaseOrder.PurchaseOrderItems.Any(x => x.Id == temp.Id)) { //Update OrderItem var InDatabaseOrderItem = purchaseOrder.PurchaseOrderItems.FirstOrDefault(x => x.Id == temp.Id); InDatabaseOrderItem.NetPrice = temp.NetPrice; InDatabaseOrderItem.Quantity = temp.Quantity; InDatabaseOrderItem.UnitPrice = temp.UnitPrice; InDatabaseOrderItem.TotalPrice = temp.TotalPrice; InDatabaseOrderItem.Item = IitemRepository.Get(temp.ItemId); InDatabaseOrderItem.Rack = IRackRepository.Get(temp.RackId); } else { //Create OrderItem var InDatabaseOrderItem = new PurchaseOrderItem(); InDatabaseOrderItem.NetPrice = temp.NetPrice; InDatabaseOrderItem.Quantity = temp.Quantity; InDatabaseOrderItem.UnitPrice = temp.UnitPrice; InDatabaseOrderItem.TotalPrice = temp.TotalPrice; InDatabaseOrderItem.Item = IitemRepository.Get(temp.ItemId); InDatabaseOrderItem.Rack = IRackRepository.Get(temp.RackId); purchaseOrder.PurchaseOrderItems.Add(InDatabaseOrderItem); } } for (int i = 0; i < purchaseOrder.PurchaseOrderItems.Count; i++) //db { var temp = purchaseOrder.PurchaseOrderItems[i]; //Delete extra orderItems in order(DB) if (!purchaseOrderContract.PurchaseOrderItemContracts.Any(x => x.Id == temp.Id)) { ; } { //if (purchaseOrderContract.PurchaseOrderItemContracts.Exists(d => d.Id != temp.Id)) purchaseOrder.PurchaseOrderItems.Remove(temp); } } PurchaseOrderRepository.Update(purchaseOrder); } else { // Create Order purchaseOrder = new PurchaseOrder(); purchaseOrder.Code = purchaseOrderContract.Code; purchaseOrder.CreationDate = purchaseOrderContract.CreationDate; purchaseOrder.Title = purchaseOrderContract.Title; for (int i = 0; i < purchaseOrderContract.PurchaseOrderItemContracts.Count; i++) { var temp = purchaseOrderContract.PurchaseOrderItemContracts[i]; var InDatabaseOrderItem = new PurchaseOrderItem(); InDatabaseOrderItem.NetPrice = temp.NetPrice; InDatabaseOrderItem.Quantity = temp.Quantity; InDatabaseOrderItem.UnitPrice = temp.UnitPrice; InDatabaseOrderItem.TotalPrice = temp.TotalPrice; InDatabaseOrderItem.Item = IitemRepository.Get(temp.ItemId); InDatabaseOrderItem.Rack = IRackRepository.Get(temp.RackId); purchaseOrder.PurchaseOrderItems.Add(InDatabaseOrderItem); } PurchaseOrderRepository.Insert(purchaseOrder); } }