예제 #1
0
        public ActionResult Create(Brand brand)
        {
            if (ModelState.IsValid)
            {
                db.Brands.Add(brand);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(brand));
        }
예제 #2
0
 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);
 }
예제 #3
0
        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));
        }
예제 #4
0
        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));
        }
예제 #5
0
        public BeverageController(BeverageContext context)
        {
            _context = context;

            if (_context.BeverageItems.Count() == 0)
            {
                _context.BeverageItems.Add(new BeverageItem {
                    Name = "Item1"
                });
                _context.SaveChanges();
            }
        }
예제 #6
0
 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));
 }