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