private bool TryFinishDemandsAndOrderParts(Order order) { var unfinishedOrderParts = order.OrderParts.Where(a => a.State != State.Finished).ToList(); /*var unfinishedRequester = (from uop in unfinishedOrderParts * from dop in uop.DemandOrderParts * where dop.State != State.Finished * select dop).ToList(); * if (unfinishedOrderParts.Any(a => a.DemandOrderParts.Any(b => b.State != State.Finished))) * { * if (unfinishedRequester.Any() && unfinishedRequester.Any(a => a.State != State.Finished)) * return false; * }*/ foreach (var uop in unfinishedOrderParts) { foreach (var dop in uop.DemandOrderParts.Where(a => a.State != State.Finished)) { if (_context.TryUpdateStockProvider(dop)) { dop.State = State.Finished; _context.Update(dop); } else { _context.SaveChanges(); return(false); } } uop.State = State.Finished; _context.Update(uop); } _context.SaveChanges(); return(true); }