private void SaveDetails() { List <PurchaseItem> lstInsert = new List <PurchaseItem>(); List <PurchaseItem> lstUpdate = new List <PurchaseItem>(); foreach (var d in Details) { var pi = new PurchaseItem() { ID = d.PurchaseItemID, ItemID = d.ItemID, PurchaseID = Purchase.ID, Price = d.Price, Quantity = d.Quantity }; if (pi.ID == 0) { pi.Available = pi.Quantity; lstInsert.Add(pi); } else { pi.Available = pi.Quantity - d.Sold; lstUpdate.Add(pi); } } if (lstInsert.Count > 0) { _purchaseService.AddPurchaseItems(lstInsert); } if (lstUpdate.Count > 0) { _purchaseService.UpdatePurchaseItems(lstUpdate); } if (_deletedDetails.Count > 0) { _purchaseService.DeletePurchaseItems(_deletedDetails); } }
private void Save() { if (Purchase.Total <= 0) { Messages.Error("لا يمكن حفظ فاتورة بهذا الاجمالي " + Purchase.Total); return; } if (SelectedSupplier == null) { Messages.Error("يجب اضافة شركة للفاتورة اولا"); return; } Purchase p = new Purchase(); p.ID = Purchase.PurchaseID; p.SupplierID = SelectedSupplier.ID; p.Date = Purchase.Date; p.Number = Purchase.Number; p.Total = Purchase.Total; p.Paid = Purchase.Paid; if (p.ID == 0) { purchaseService.AddPurchase(p); } else { purchaseService.UpdatePurchase(p); } List <PurchaseItem> lstInsert = new List <PurchaseItem>(); List <PurchaseItem> lstUpdate = new List <PurchaseItem>(); foreach (var d in Purchase.Details) { var pi = new PurchaseItem() { ID = d.PurchaseItemID, ItemID = d.ItemID, PurchaseID = p.ID, Price = d.Price, Quantity = d.Quantity }; if (pi.ID == 0) { lstInsert.Add(pi); } else { lstUpdate.Add(pi); } } if (lstInsert.Count > 0) { purchaseService.AddPurchaseItems(lstInsert); } if (lstUpdate.Count > 0) { purchaseService.UpdatePurchaseItems(lstUpdate); } if (lstDeleted.Count > 0) { purchaseService.DeletePurchaseItems(lstDeleted); } completed = true; Purchase.Name = SelectedSupplier.Name; Purchase.SupplierID = SelectedSupplier.ID; if (_edit) { eventAggregator.GetEvent <PurchaseUpdated>().Publish(Purchase); } else { eventAggregator.GetEvent <PurchaseAdded>().Publish(Purchase); } navigationContext.NavigationService.RequestNavigate(RegionNames.PurchasesMain); }