Example #1
0
        public async Task <ActionResult <TblFood> > PostTblFood(TblFood tblFood)
        {
            _context.TblFoods.Add(tblFood);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetTblFood", new { id = tblFood.FoodId }, tblFood));
        }
Example #2
0
        public async Task <IActionResult> PutTblFood(int id, TblFood tblFood)
        {
            if (id != tblFood.FoodId)
            {
                return(BadRequest());
            }

            _context.Entry(tblFood).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!TblFoodExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Example #3
0
        // Sửa món ăn
        public void EditFood(int ID, string Name, int CategoryID, float Price)
        {
            TblFood food = new TblFood();

            food            = data.TblFoods.Single(n => n.ID == ID);
            food.Name       = Name;
            food.CategoryID = CategoryID;
            food.Price      = Price;
            data.SaveChanges();
        }
Example #4
0
        // Thêm món ăn
        public void AddFood(string Name, int IDcategory, float Price)
        {
            TblFood food = new TblFood()
            {
                Name = Name, CategoryID = IDcategory, Price = Price
            };

            data.TblFoods.Add(food);
            data.SaveChanges();
        }