public static void DeleteByClient(int id) { using (var unitOfWork = new UnitOfWork()) { using (var items = new XPCollection <DB.Orders>(unitOfWork)) { var dbItems = items.Where(u => u.Client != null && u.Client.Id == id).ToArray(); items.DeleteObjectOnRemove = true; //связи for (int index = 0; index < dbItems.Count(); index++) { var item = dbItems[index]; OrderDamages.DeleteByOrder(item.Id, unitOfWork); OrderServices.DeleteByOrder(item.Id, unitOfWork); items.Remove(item); } } unitOfWork.CommitChanges(); } }
public static void Delete(int id) { using (var unitOfWork = new UnitOfWork()) { using (var items = new XPCollection <DB.Orders>(unitOfWork)) { var dbItem = items.FirstOrDefault(u => u.Id == id); if (dbItem == null) { throw new Exception(Resources.Orders_Read_Заказ_не_найден_); } items.DeleteObjectOnRemove = true; //связи OrderDamages.DeleteByOrder(id, unitOfWork); OrderServices.DeleteByOrder(id, unitOfWork); items.Remove(dbItem); } unitOfWork.CommitChanges(); } }
internal static int Change(Order item) { using (var unitOfWork = new UnitOfWork()) { DB.Orders dbItem; using (var items = new XPCollection <DB.Orders>(unitOfWork)) { dbItem = items.FirstOrDefault(u => u.Id == item.Id); if (dbItem == null) { throw new Exception(Resources.Orders_Read_Заказ_не_найден_); } dbItem.Closed = item.Closed; dbItem.DateFrom = item.DateFrom; dbItem.DateTo = item.DateTo; dbItem.MileageEnd = item.MileageEnd; dbItem.Other = item.Other; dbItem.Overrun = item.Overrun; dbItem.Territory = item.Territory; dbItem.Wash = item.Wash; dbItem.Discount = item.Discount; dbItem.DiscountType = item.DiscountType; dbItem.SiteId = item.SiteId; dbItem.Deleted = item.Deleted; FillDependencies(unitOfWork, dbItem, item); } //связи OrderDamages.DeleteByOrder(item.Id, unitOfWork); OrderServices.DeleteByOrder(item.Id, unitOfWork); AddDependencies(unitOfWork, item, dbItem); unitOfWork.CommitChanges(); return(item.Id); } }