public void CreateAndUpdateSaleOrder(SaleOrderContract saleOrderContract) { var saleorder = ISaleOrderRepository.Get(saleOrderContract.Id); if (saleorder != null) { saleorder.Code = saleOrderContract.Code; //saleorder.CreationDate = saleOrderContract.CreationDate; lazem nist moghe sakht object bevojode amede mesl Id saleorder.Title = saleOrderContract.Title; for (int i = 0; i < saleOrderContract.SaleOrderItemContracts.Count; i++) { var Temp = saleOrderContract.SaleOrderItemContracts[i]; if (saleorder.saleOrderItems.Any(s => s.Id == Temp.Id)) { var Insaleorderitem = saleorder.saleOrderItems.FirstOrDefault(s => s.Id == Temp.Id); Insaleorderitem.NetPrice = Temp.NetPrice; Insaleorderitem.Quantity = Temp.Quantity; Insaleorderitem.TotalPrice = Temp.TotalPrice; Insaleorderitem.UnitPrice = Temp.UnitPrice; Insaleorderitem.Rack = IRackRepository.Get(Temp.RackId); Insaleorderitem.Item = IItemRepository.Get(Temp.ItemId); } else { Insaleorderitem = new SaleOrderItem(); Insaleorderitem.NetPrice = Temp.NetPrice; Insaleorderitem.Quantity = Temp.Quantity; Insaleorderitem.TotalPrice = Temp.TotalPrice; Insaleorderitem.UnitPrice = Temp.UnitPrice; Insaleorderitem.Rack = IRackRepository.Get(Temp.RackId); Insaleorderitem.Item = IItemRepository.Get(Temp.ItemId); saleorder.saleOrderItems.Add(Insaleorderitem); } } //var DeleteOrderItem = saleorder.saleOrderItems.Where(x => // !saleOrderContract.SaleOrderItemContracts.Any(y => y.Id == x.Id)); for (int i = 0; i < saleorder.saleOrderItems.Count; i++) { var Temp = saleorder.saleOrderItems.ToArray()[i]; if (!saleOrderContract.SaleOrderItemContracts.Any(s => s.Id == Temp.Id)) { saleorder.saleOrderItems.Remove(Temp); //var temp = ISaleOrderRepository.Get(Temp.Id); //ISaleOrderRepository.Delete(temp); } } ISaleOrderRepository.Update(saleorder); } else { 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]; Insaleorderitem = new SaleOrderItem(); Insaleorderitem.NetPrice = Temp.NetPrice; Insaleorderitem.Quantity = Temp.Quantity; Insaleorderitem.TotalPrice = Temp.TotalPrice; Insaleorderitem.UnitPrice = Temp.UnitPrice; Insaleorderitem.Rack = IRackRepository.Get(Temp.RackId); Insaleorderitem.Item = IItemRepository.Get(Temp.ItemId); saleorder.saleOrderItems.Add(Insaleorderitem); } ISaleOrderRepository.Insert(saleorder); } }
public void DeleteSaleOrder(SaleOrderContract saleOrderContract) { var saleorder = ISaleOrderRepository.Get(saleOrderContract.Id); ISaleOrderRepository.Delete(saleorder); }
public void Delete(SaleOrderContract saleOrderContract) { var SaleOrderContract = ISaleOrderRepository.Get(saleOrderContract.Id); ISaleOrderRepository.Delete(SaleOrderContract); }
//esmet ke doros nist public void CreateAndDelete(SaleOrderContract saleOrderContract) { var SaleOrder = ISaleOrderRepository.Get(saleOrderContract.Id); if (SaleOrder != null) { SaleOrder.CreationDate = DateTime.Now; SaleOrder.Title = saleOrderContract.Title; SaleOrder.Code = saleOrderContract.Code; for (int i = 0; i < saleOrderContract.SaleorderItems.Count; i++) { var temp = saleOrderContract.SaleorderItems[i]; if (SaleOrder.SaleorderItems.Any(p => p.Id == temp.Id)) { var Sorderitem = SaleOrder.SaleorderItems.FirstOrDefault(p => p.Id == temp.Id); Sorderitem.QTY = temp.QTY; Sorderitem.Name = temp.Name; Sorderitem.NetPrice = temp.NetPrice; Sorderitem.TotalPrice = temp.TotalPrice; Sorderitem.UnitPrice = temp.UnitPrice; Sorderitem.Item1 = iitemRepository.Get(temp.ItemId); Sorderitem.Rack1 = iRackRepository.Get(temp.RackId); } else { var res = new SaleOrderItem(); res.QTY = temp.QTY; res.Name = temp.Name; res.NetPrice = temp.NetPrice; res.TotalPrice = temp.TotalPrice; res.UnitPrice = temp.UnitPrice; res.Item1 = iitemRepository.Get(temp.ItemId); res.Rack1 = iRackRepository.Get(temp.RackId); SaleOrder.SaleorderItems.Add(res); } } foreach (var item in SaleOrder.SaleorderItems) { if (SaleOrder.SaleorderItems.Any(s => s.Id != item.Id)) { SaleOrder.SaleorderItems.Remove(item); } } ISaleOrderRepository.Update(SaleOrder); } else { SaleOrder.CreationDate = saleOrderContract.CreationDate; SaleOrder.Title = saleOrderContract.Title; SaleOrder.Code = saleOrderContract.Code; for (int i = 0; i < saleOrderContract.SaleorderItems.Count; i++) { var temp = saleOrderContract.SaleorderItems[i]; if (SaleOrder.SaleorderItems.Any(p => p.Id == temp.Id)) { var sorderitem = SaleOrder.SaleorderItems.FirstOrDefault(p => p.Id == temp.Id); sorderitem.QTY = temp.QTY; sorderitem.Name = temp.Name; sorderitem.NetPrice = temp.NetPrice; sorderitem.TotalPrice = temp.TotalPrice; sorderitem.UnitPrice = temp.UnitPrice; sorderitem.Item1 = iitemRepository.Get(temp.ItemId); sorderitem.Rack1 = iRackRepository.Get(temp.RackId); } } ISaleOrderRepository.Insert(SaleOrder); } }
public void CreateOrUpdate(SaleOrderContract saleOrderContract) { var SaleOrder = ISaleOrderRepository.Get(saleOrderContract.Id); if (SaleOrder != null) { SaleOrder.CreationDate = DateTime.Now; SaleOrder.Title = saleOrderContract.Title; SaleOrder.Code = saleOrderContract.Code; for (int i = 0; i < saleOrderContract.SaleOrderItems.Count; i++) { var temp = saleOrderContract.SaleOrderItems[i]; if (SaleOrder.SaleOrderItems.Any(p => p.Id == temp.Id)) { var Sorderitem = SaleOrder.SaleOrderItems.FirstOrDefault(p => p.Id == temp.Id); Sorderitem.Quantity = temp.Quantity; Sorderitem.NetPrice = temp.NetPrice; Sorderitem.TotalPrice = temp.TotalPrice; Sorderitem.UnitPrice = temp.UnitPrice; Sorderitem.Item = IItemRepository.Get(temp.ItemId); Sorderitem.Rack = IRackRepository.Get(temp.RackId); } else { var Sorderitem = new SaleOrderItem(); Sorderitem.Quantity = temp.Quantity; Sorderitem.NetPrice = temp.NetPrice; Sorderitem.TotalPrice = temp.TotalPrice; Sorderitem.UnitPrice = temp.UnitPrice; Sorderitem.Item = IItemRepository.Get(temp.ItemId); Sorderitem.Rack = IRackRepository.Get(temp.RackId); SaleOrder.SaleOrderItems.Add(Sorderitem); } } foreach (var item in SaleOrder.SaleOrderItems) { if (!saleOrderContract.SaleOrderItems.Any(p => p.Id == item.Id)) { SaleOrder.SaleOrderItems.Remove(item); } } ISaleOrderRepository.Update(SaleOrder); } else { SaleOrder = new SaleOrder(); SaleOrder.CreationDate = saleOrderContract.CreationDate; SaleOrder.Title = saleOrderContract.Title; SaleOrder.Code = saleOrderContract.Code; for (int i = 0; i < saleOrderContract.SaleOrderItems.Count; i++) { var temp = saleOrderContract.SaleOrderItems[i]; var Sorderitem = new SaleOrderItem(); Sorderitem.NetPrice = temp.NetPrice; Sorderitem.TotalPrice = temp.TotalPrice; Sorderitem.UnitPrice = temp.UnitPrice; Sorderitem.Item = IItemRepository.Get(temp.ItemId); Sorderitem.Rack = IRackRepository.Get(temp.RackId); SaleOrder.SaleOrderItems.Add(Sorderitem); } ISaleOrderRepository.Insert(SaleOrder); } }