예제 #1
0
 public IActionResult HistoryNew(History history)
 {
     db.Histories.Add(history);
     db.SaveChanges();
     ViewBag.DateTime = history;
     return(View("~/Views/Table/HistoryTable.cshtml", history));
 }
예제 #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();
            }
        }
예제 #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"));
        }
예제 #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"));
        }