コード例 #1
0
        public List <IDemandToProvider> UpdateStateDemandRequester(List <IDemandToProvider> provider)
        {
            var changedRequester = new List <IDemandToProvider>();

            foreach (var singleProvider in provider)
            {
                var prov = Demands.Include(a => a.DemandRequester).ThenInclude(b => b.DemandProvider).Single(a => a.Id == singleProvider.Id);
                if (prov.DemandRequester.DemandProvider.Any(a => a.State != State.Finished))
                {
                    if (!TryUpdateStockProvider(prov.DemandRequester))
                    {
                        continue;
                    }
                }
                //check for PO then set ready if it has started and taken out the articles from the stock
                if (prov.DemandRequester.GetType() == typeof(DemandProductionOrderBom))
                {
                    var dpob = Demands.OfType <DemandProductionOrderBom>().Single(a => a.Id == prov.DemandRequester.Id);
                    if (dpob.ProductionOrderBom.ProductionOrderParent.ProductionOrderWorkSchedule.All(a => a.ProducingState == ProducingState.Created))
                    {
                        continue;
                    }
                }

                prov.DemandRequester.State = State.Finished;
                Update(prov.DemandRequester);
                SaveChanges();
                changedRequester.Add(prov.DemandRequester);
            }
            var test  = Demands.OfType <DemandProductionOrderBom>().Where(a => a.State != State.Finished);
            var test2 = test.Where(a => a.DemandProvider.All(b => b.State == State.Finished));

            Debug.WriteLine(test2.Count() + " items waiting to be concluded");
            Debug.WriteLine(test2.Count(a => a.ProductionOrderBom.ProductionOrderParent.ProductionOrderWorkSchedule.First().Name == "Wedding"));

            var dpobs = Demands.OfType <DemandProductionOrderBom>().Where(a => a.State != State.Finished &&
                                                                          a.ProductionOrderBom.ProductionOrderParent.ProductionOrderWorkSchedule.Any(c => c.ProducingState != ProducingState.Created));

            foreach (var dpob in dpobs)
            {
                dpob.State = State.Finished;
                changedRequester.Add(dpob);
            }
            return(changedRequester);
        }