Ejemplo n.º 1
0
        public IActionResult Create()
        {
            ScenarioCreateViewModel viewmodel = new ScenarioCreateViewModel();

            List <ILocation> locations;

            if (!cache.TryGetValue(CacheKeys.LOCATION, out locations))
            {
                locations = new List <ILocation>();
            }

            List <IVehicle> vehicles;

            if (!cache.TryGetValue(CacheKeys.VEHICLE, out vehicles))
            {
                vehicles = new List <IVehicle>();
            }


            viewmodel.setVehicles(vehicles);
            viewmodel.locations      = locations;
            viewmodel.scenario       = new Scenario();
            viewmodel.id             = viewmodel.scenario.id;
            viewmodel.scenario.start = DateTime.Now;

            cache.Set("ScenarioEdit", viewmodel.scenario);

            return(View(viewmodel));
        }
Ejemplo n.º 2
0
        public IActionResult Edit(string id)
        {
            ScenarioCreateViewModel viewmodel = new ScenarioCreateViewModel();

            List <ILocation> locations;

            if (!cache.TryGetValue(CacheKeys.LOCATION, out locations))
            {
                locations = new List <ILocation>();
            }

            List <IVehicle> vehicles;

            if (!cache.TryGetValue(CacheKeys.VEHICLE, out vehicles))
            {
                vehicles = new List <IVehicle>();
            }

            if (!cache.TryGetValue(CacheKeys.SCENARIO, out scenarios))
            {
                scenarios = new List <IScenario>();
            }

            foreach (Scenario s in scenarios)
            {
                if (s.id.Equals(id))
                {
                    locations.Add(s.location);
                    viewmodel.setVehicles(vehicles);
                    for (int i = 0; i < vehicles.Count; i++)
                    {
                        int count = 0;
                        foreach (Vehicle v in s.vehicles)
                        {
                            if (v.id.Equals(vehicles[i].id))
                            {
                                count++;
                            }
                        }
                        viewmodel.countVehicles[i] = count;
                    }
                    viewmodel.locations      = locations;
                    viewmodel.scenario       = s;
                    viewmodel.id             = viewmodel.scenario.id;
                    viewmodel.countRushhours = s.rushhours.Count;

                    cache.Set("ScenarioEdit", viewmodel.scenario);

                    scenarios.Remove(s);
                    cache.Set(CacheKeys.SCENARIO, scenarios);

                    return(View("Create", viewmodel));
                }
            }

            return(RedirectToAction("Index"));
        }