Ejemplo n.º 1
0
 public IActionResult HistoryNew(History history)
 {
     db.Histories.Add(history);
     db.SaveChanges();
     ViewBag.DateTime = history;
     return(View("~/Views/Table/HistoryTable.cshtml", history));
 }
Ejemplo n.º 2
0
        public static void Initialize(WaterContext context)
        {
            Brand Slavda = new Brand {
                Name = "Slavda", Country = "Russia"
            };
            Brand Swallow = new Brand {
                Name = "Swallow", Country = "Russia"
            };
            Brand Monastry = new Brand {
                Name = "Monastry", Country = "Russia"
            };

            if (!context.Brands.Any())
            {
                context.Brands.AddRange(Slavda, Swallow, Monastry);
                context.SaveChanges();
            }

            if (!context.Waters.Any())
            {
                context.Waters.AddRange(
                    new Water
                {
                    Name   = "Bottle 0.5L",
                    Count  = 10,
                    Price  = 65,
                    Brand  = Swallow,
                    Volume = 0.5,
                },
                    new Water
                {
                    Name   = "Bottle 1L",
                    Count  = 20,
                    Price  = 75,
                    Brand  = Monastry,
                    Volume = 1,
                },
                    new Water
                {
                    Name   = "Bottle 19L",
                    Count  = 5,
                    Price  = 110,
                    Brand  = Slavda,
                    Volume = 19,
                }
                    );
                context.SaveChanges();
            }
        }
Ejemplo n.º 3
0
        public IActionResult AddNewBrand(string submit, string cancel, Brand brand)
        {
            var button = submit ?? cancel;

            if (button == "Cancel")
            {
                return(RedirectToAction("AddNewBrand"));
            }

            if (db.Brands.Any(x => x.Name == brand.Name))
            {
                return(BadRequest());
            }

            db.Brands.Add(brand);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 4
0
        public IActionResult AddNewWater(string sumbit, string cancel, Water water)
        {
            var button = sumbit ?? cancel;

            if (button == "Cancel")
            {
                return(RedirectToAction("AddNewWater"));
            }

            if (db.Waters.Any(x => x.Name == water.Name))
            {
                return(BadRequest());
            }

            db.Waters.Add(water);
            db.SaveChanges();
            return(Redirect("~/Home/Index"));
        }