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);
            }
        }
示例#2
0
        public void CreateOrUpdate(SaleOrderContract saleOrderContract)
        {
            var saleorder = SaleOrderRepository.Get(saleOrderContract.Id);

            if (saleorder != null)
            {
                saleorder.Code = saleOrderContract.Code;
                //saleorder.CreationDate = saleOrderContract.CreationDate;
                saleorder.Title = saleOrderContract.Title;
                for (int i = 0; i < saleOrderContract.SaleOrderItems.Count; i++)
                {
                    var temp = saleOrderContract.SaleOrderItems[i];
                    if (saleorder.SaleOrderItems.Any(s => s.Id == temp.Id))
                    {
                        var indatabaesaleorder = saleorder.SaleOrderItems.FirstOrDefault(s => s.Id == temp.Id);
                        indatabaesaleorder.NetPrice   = temp.NetPrice;
                        indatabaesaleorder.Quantity   = temp.Quantity;
                        indatabaesaleorder.TotalPrice = temp.TotalPrice;
                        indatabaesaleorder.UnitPrice  = temp.UnitPrice;
                        indatabaesaleorder.Item       = ItemRepository.Get(temp.ItemId);
                        indatabaesaleorder.Rack       = RackRepository.Get(temp.RackId);
                    }
                    else
                    {
                        var saleorderitem = new SaleOrderItem();
                        saleorderitem.NetPrice   = temp.NetPrice;
                        saleorderitem.Quantity   = temp.Quantity;
                        saleorderitem.TotalPrice = temp.TotalPrice;
                        saleorderitem.UnitPrice  = temp.UnitPrice;
                        saleorderitem.Item       = ItemRepository.Get(temp.ItemId);
                        saleorderitem.Rack       = RackRepository.Get(temp.RackId);

                        saleorder.SaleOrderItems.Add(saleorderitem);
                    }
                }
                for (int i = 0; i < saleorder.SaleOrderItems.Count; i++)
                {
                    var temp = saleorder.SaleOrderItems.ToArray()[i];
                    if (!saleOrderContract.SaleOrderItems.Any(s => s.Id == temp.Id))
                    {
                        saleorder.SaleOrderItems.Remove(temp);
                    }
                }

                SaleOrderRepository.Update(saleorder);
            }
            else
            {
                saleorder              = new SaleOrder();
                saleorder.Code         = saleOrderContract.Code;
                saleorder.CreationDate = saleOrderContract.CreationDate;
                saleorder.Title        = saleOrderContract.Title;
                for (int i = 0; i < saleOrderContract.SaleOrderItems.Count; i++)
                {
                    var temp = saleOrderContract.SaleOrderItems[i];

                    var indatabaesaleorder = saleorder.SaleOrderItems.FirstOrDefault(s => s.Id == temp.Id);
                    indatabaesaleorder.NetPrice   = temp.NetPrice;
                    indatabaesaleorder.Quantity   = temp.Quantity;
                    indatabaesaleorder.TotalPrice = temp.TotalPrice;
                    indatabaesaleorder.UnitPrice  = temp.UnitPrice;
                    indatabaesaleorder.Item       = ItemRepository.Get(temp.ItemId);
                    indatabaesaleorder.Rack       = RackRepository.Get(temp.RackId);
                }

                SaleOrderRepository.Insert(saleorder);
            }
        }