Beispiel #1
0
        private void AddPodsAndPricesToDB(ERecargaDbContext context)
        {
            Random gen   = new Random();
            int    podId = 1;

            for (int i = 1; i < 16; i++)
            {
                int podIdentifier = 1;
                for (int j = 1; j < 11; j++)
                {
                    context.Pods.AddOrUpdate(x => x.Id,
                                             new Pod()
                    {
                        Id = podId++, isActive = true, StationId = i, PodId = PodTypeEnum.Normal, Identifier = podIdentifier++
                    });
                }

                for (int j = 1; j < 11; j++)
                {
                    context.Pods.AddOrUpdate(x => x.Id,
                                             new Pod()
                    {
                        Id = podId++, isActive = true, StationId = i, PodId = PodTypeEnum.Fast, Identifier = podIdentifier++
                    });
                }

                foreach (var price in ScheduleGenerator.GeneratePrices(gen.Next(5, 15), gen.Next(10, 25)))
                {
                    price.StationId = i;
                    context.Prices.Add(price);
                }
            }
        }
Beispiel #2
0
        public ActionResult Create(StationViewModel viewModel)
        {
            var user = db.Employees.Find(User.Identity.GetUserId());

            viewModel._Station.CompanyId = user.CompanyId;

            if (ModelState.IsValid)
            {
                db.Stations.Add(viewModel._Station);

                foreach (var price in ScheduleGenerator.GeneratePrices(Double.Parse(viewModel.NormalCost), Double.Parse(viewModel.FastCost)))
                {
                    price.StationId = viewModel._Station.Id;
                    db.Prices.Add(price);
                }

                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(viewModel));
        }