public ActionResult Create(Brand brand) { if (ModelState.IsValid) { db.Brands.Add(brand); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(brand)); }
public ActionResult Create(Beer beer) { beer.Brand = db.Brands.Find(beer.Brand.BrandID); //if (ModelState.IsValid) //{ db.Beers.Add(beer); db.SaveChanges(); return(RedirectToAction("Index")); //} //return View(beer); }
public ActionResult Create([Bind(Include = "id,name,pack,price,active")] Beverage beverage) { if (ModelState.IsValid) { db.Beverages.Add(beverage); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(beverage)); }
public IActionResult Create([FromBody] BeverageItem item) { if (item == null) { return(BadRequest()); } _context.BeverageItems.Add(item); _context.SaveChanges(); return(CreatedAtRoute("GetBeverage", new { id = item.Id }, item)); }
public BeverageController(BeverageContext context) { _context = context; if (_context.BeverageItems.Count() == 0) { _context.BeverageItems.Add(new BeverageItem { Name = "Item1" }); _context.SaveChanges(); } }
public ActionResult SendCoin(int coin) { if (coin == 1) { Coin coins = db.Coins.FirstOrDefault(c => c.Id == 1); if (coins == null) { return(HttpNotFound()); } coins.NumberOfCoins1 += 1; db.SaveChanges(); return(new HttpStatusCodeResult(HttpStatusCode.OK)); } if (coin == 2) { Coin coins = db.Coins.FirstOrDefault(c => c.Id == 1); if (coins == null) { return(HttpNotFound()); } coins.NumberOfCoins2 += 1; db.SaveChanges(); return(new HttpStatusCodeResult(HttpStatusCode.OK)); } if (coin == 5) { Coin coins = db.Coins.FirstOrDefault(c => c.Id == 1); if (coins == null) { return(HttpNotFound()); } coins.NumberOfCoins5 += 1; db.SaveChanges(); return(new HttpStatusCodeResult(HttpStatusCode.OK)); } if (coin == 10) { Coin coins = db.Coins.FirstOrDefault(c => c.Id == 1); if (coins == null) { return(HttpNotFound()); } coins.NumberOfCoins10 += 1; db.SaveChanges(); return(new HttpStatusCodeResult(HttpStatusCode.OK)); } return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); }