public long GetEarliestStart(ResultContext kpiContext, Job simulationWorkschedule, SimulationType simulationType, int simulationId, List <Job> schedules = null)
        {
            if (simulationType == SimulationType.Central)
            {
                var orderId = simulationWorkschedule.OrderId.Replace(oldValue: "[", newValue: "").Replace(oldValue: "]", newValue: "");
                var start   = kpiContext.SimulationJobs
                              .Where(predicate: x => x.SimulationConfigurationId == simulationId && x.SimulationType == simulationType)
                              .Where(predicate: a =>
                                     a.OrderId.Equals("[" + orderId.ToString() + ",") ||
                                     a.OrderId.Equals("," + orderId.ToString() + "]") ||
                                     a.OrderId.Equals("[" + orderId.ToString() + "]") ||
                                     a.OrderId.Equals("," + orderId.ToString() + ",")).Min(selector: b => b.Start);
                return(start);
            }

            var children = new List <Job>();

            children = schedules.Where(predicate: x => x.SimulationConfigurationId == simulationId && x.SimulationType == simulationType)
                       .Where(predicate: a => a.ParentId.Equals(value: simulationWorkschedule.ProductionOrderId.ToString())).ToList();

            if (!children.Any())
            {
                return(simulationWorkschedule.Start);
            }
            var startTimes = children.Select(selector: child => GetEarliestStart(kpiContext: kpiContext, simulationWorkschedule: child, simulationType: simulationType, simulationId: simulationId, schedules: schedules)).ToList();

            return(startTimes.Min());
        }
        public static void SaveData(ResultContext source, ResultContext target)
        {
            foreach (var item in source.Kpis)
            {
                target.Kpis.Add(entity: item.CopyProperties());
            }
            target.SaveChanges();

            foreach (var item in source.SimulationOperations)
            {
                target.SimulationOperations.Add(entity: item.CopyProperties());
            }
            target.SaveChanges();

            foreach (var item in source.StockExchanges)
            {
                target.StockExchanges.Add(entity: item.CopyProperties());
            }
            target.SaveChanges();
        }