Exemple #1
0
        public ActionResult Create([Bind(Include = "LotID,GoatID,CustomerID,GoatName,CustomerFirst,CustomerLast,LotAddress,LotDescription")] Lot lot)
        {
            if (ModelState.IsValid)
            {
                db.Lots.Add(lot);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(lot));
        }
Exemple #2
0
        public ActionResult Create([Bind(Include = "GoatID,GoatName,GoatColor,GoatType,GoatGender")] Goat goat)
        {
            if (ModelState.IsValid)
            {
                db.Goats.Add(goat);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(goat));
        }
Exemple #3
0
        /* public ActionResult Create([Bind(Include = "CustomerID,CustomerFirst,CustomerLast,CustomerAddress,CustomerEmail")] Customer customer)
         * {
         * if (ModelState.IsValid)
         * {
         *   db.Customers.Add(customer);
         *   db.SaveChanges();
         *   return RedirectToAction("Index");
         * }
         *
         * return View(customer);
         * }*/

        public ActionResult Create([Bind(Include = "CustomerID,CustomerFirst,CustomerLast,CustomerAddress,CustomerEmail")] Customer customer)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    db.Customers.Add(customer);
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
            }
            catch (DataException /* dex */)
            {
                //Log the error (uncomment dex variable name and add a line here to write a log.
                ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator.");
            }
            return(View(customer));
        }
        protected override void Seed(GrazingContext context)
        {
            var goats = new List <Goat>
            {
                new Goat {
                    GoatName = "Carson", GoatColor = "Black", GoatType = "Alpine", GoatGender = "Buck"
                },
                new Goat {
                    GoatName = "Meredith", GoatColor = "White", GoatType = "Pygmy", GoatGender = "Doe"
                },
                new Goat {
                    GoatName = "Arturo", GoatColor = "Red", GoatType = "Cross", GoatGender = "Doe"
                },
                new Goat {
                    GoatName = "Gytis", GoatColor = "Brown", GoatType = "Boer", GoatGender = "Buck"
                },
            };

            goats.ForEach(g => context.Goats.Add(g));
            context.SaveChanges();

            var pastures = new List <Pasture>
            {
                new Pasture {
                    GoatID = 1, Field = "A"
                },
                new Pasture {
                    GoatID = 2, Field = "B"
                },
                new Pasture {
                    GoatID = 3, Field = "C"
                },
                new Pasture {
                    GoatID = 4, Field = "D"
                },
            };

            pastures.ForEach(p => context.Pastures.Add(p));
            context.SaveChanges();

            var lots = new List <Lot>
            {
                new Lot {
                    LotID = 1, GoatID = 1, CustomerID = 1, CustomerFirst = "Ashley", CustomerLast = "Smith", GoatName = "Carson", LotAddress = "123 West Ave", LotDescription = "Hill"
                },
                new Lot {
                    LotID = 2, GoatID = 2, CustomerID = 2, CustomerFirst = "Jerry", CustomerLast = "Jones", GoatName = "Meredith", LotAddress = "456 East Ave", LotDescription = "Trees"
                },
                new Lot {
                    LotID = 3, GoatID = 3, CustomerID = 3, CustomerFirst = "Timmy", CustomerLast = "Wilson", GoatName = "Arturo", LotAddress = "789 North Ave", LotDescription = "Level"
                }
            };

            lots.ForEach(l => context.Lots.Add(l));
            context.SaveChanges();

            var customers = new List <Customer>
            {
                new Customer {
                    CustomerID = 1, CustomerFirst = "Ashley", CustomerLast = "Smith", CustomerEmail = "*****@*****.**", CustomerAddress = "123 West Ave",
                },
                new Customer {
                    CustomerID = 2, CustomerFirst = "Jerry", CustomerLast = "Jones", CustomerEmail = "*****@*****.**", CustomerAddress = "456 East Ave"
                },
                new Customer {
                    CustomerID = 3, CustomerFirst = "Timmy", CustomerLast = "Wilson", CustomerEmail = "*****@*****.**", CustomerAddress = "789 North Ave"
                }
            };

            customers.ForEach(c => context.Customers.Add(c));
            context.SaveChanges();


            var authors = new List <Author>
            {
                new Author {
                    Name = "Sue Weaver", ID = 1
                },
                new Author {
                    Name = "Cheryl K. Smith", ID = 2
                },
                new Author {
                    Name = "Taylor David", ID = 3
                },
            };

            authors.ForEach(a => context.Authors.Add(a));
            context.SaveChanges();


            var books = new List <Book>
            {
                new Book {
                    Title = "The Backyard Goat", Year = DateTime.Parse("2011-04-16"), AuthorID = 1
                },
                new Book {
                    Title = "Raising Goats For Dummies", Year = DateTime.Parse("2010-02-19"), AuthorID = 2
                },
                new Book {
                    Title = "Nigerian Dwarf Goats Care", Year = DateTime.Parse("2013-06-27"), AuthorID = 3
                },
            };

            books.ForEach(b => context.Books.Add(b));
            context.SaveChanges();
        }