Esempio n. 1
0
        public async Task <IActionResult> Edit(int id, [Bind("BuggyID,Name")] BuggyModel buggyModel)
        {
            if (id != buggyModel.BuggyID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(buggyModel);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!BuggyModelExists(buggyModel.BuggyID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(buggyModel));
        }
Esempio n. 2
0
        public async Task <IActionResult> Create([Bind("BuggyID,Name")] BuggyModel buggyModel)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    _context.Add(buggyModel);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
            }
            catch (DbUpdateException /* ex */)
            {
                //Log the error (uncomment ex variable name and write a log.
                ModelState.AddModelError("", "Unable to save changes. " +
                                         "Try again, and if the problem persists " +
                                         "see your system administrator.");
            }
            return(View(buggyModel));
        }
Esempio n. 3
0
        public static void Initialize(FactoryContext context)
        {
            context.Database.EnsureCreated();

            if (context.Lines.Any())
            {
                return;
            }

            var lines = new LineModel[]
            {
                new LineModel {
                    Name = "A"
                },
                new LineModel {
                    Name = "B"
                },
                new LineModel {
                    Name = "C"
                },
                new LineModel {
                    Name = "D"
                },
                new LineModel {
                    Name = "E"
                },
                new LineModel {
                    Name = "F"
                }
            };

            foreach (LineModel l in lines)
            {
                context.Lines.Add(l);
            }
            context.SaveChanges();


            if (context.Users.Any())
            {
                return;
            }

            var users = new UserModel[]
            {
                new UserModel {
                    Name = "Matej", LineID = 1
                },
                new UserModel {
                    Name = "Petr", LineID = 2
                },
            };

            foreach (UserModel u in users)
            {
                context.Users.Add(u);
            }
            context.SaveChanges();

            var buggies = new BuggyModel[]
            {
                new BuggyModel {
                    BuggyID = 150, Name = "A1"
                },
                new BuggyModel {
                    BuggyID = 250, Name = "B1"
                },
                new BuggyModel {
                    BuggyID = 350, Name = "A2"
                },
                new BuggyModel {
                    BuggyID = 450, Name = "A3"
                },
                new BuggyModel {
                    BuggyID = 550, Name = "A5"
                },
                new BuggyModel {
                    BuggyID = 650, Name = "B3"
                }
            };

            foreach (BuggyModel b in buggies)
            {
                context.Buggies.Add(b);
            }
            context.SaveChanges();

            var routes = new RouteModel[]
            {
                new RouteModel {
                    LineID = 1, BuggyID = 150
                },
                new RouteModel {
                    LineID = 1, BuggyID = 250
                },
                new RouteModel {
                    LineID = 1, BuggyID = 350
                },
                new RouteModel {
                    LineID = 4, BuggyID = 450
                },
                new RouteModel {
                    LineID = 5, BuggyID = 550
                },
                new RouteModel {
                    LineID = 6, BuggyID = 650
                },
                new RouteModel {
                    LineID = 2, BuggyID = 250
                },
                new RouteModel {
                    LineID = 3, BuggyID = 350
                },
                new RouteModel {
                    LineID = 6, BuggyID = 150
                },
            };

            foreach (RouteModel r in routes)
            {
                context.Routes.Add(r);
            }
            context.SaveChanges();
        }