Exemple #1
0
 public IActionResult Update([FromBody] Dish dish)
 {
     if (dish == null)
     {
         return(BadRequest());
     }
     db.Update(dish);
     db.Save();
     return(Ok(dish));
 }
Exemple #2
0
        public ActionResult Update(DishInfo model)
        {
            Employee em = (Employee)Session[CommonConstants.USER_SESSION];

            model.ModifyBy = em.id;
            model.DishCode = model.DishCode.ToUpper(); //Chuyển trường mã thành dạng chữ in hoa
            var result = _dishRepo.Update(model);

            if (result == 1)
            {
                return(Json(new { status = 1, message = "Cập nhật thành công" }, JsonRequestBehavior.AllowGet));
            }
            return(Json(new { status = 0, message = "Cập nhật thất bại" }, JsonRequestBehavior.AllowGet));
        }
Exemple #3
0
        private void btnSaveEntity_Click(object sender, EventArgs e)
        {
            if (txtBoxName.Text.Length == 0)
            {
                txtBoxName.Focus();
                return;
            }

            var dishRepo = new DishRepository(_connectionString);
            var unitRepo = new UnitRepository(_connectionString);

            try
            {
                if (_entity != null && _entity.GetType() == typeof(Dish))
                {
                    var dish = _entity as Dish;
                    dish.DishName = txtBoxName.Text;

                    if (dish.DishID == 0)
                    {
                        dishRepo.Create(dish);
                    }
                    else
                    {
                        dishRepo.Update(dish);
                    }
                }
            }
            catch (SqlException sqlException)
            {
                if (sqlException.Number == 2627)
                {
                    MessageBox.Show("Наименование блюда должно быть уникальным", "Предупреждение", MessageBoxButtons.OK);
                }
            }

            try
            {
                if (_entity != null && _entity.GetType() == typeof(Unit))
                {
                    var unit = _entity as Unit;
                    unit.UnitName = txtBoxName.Text;

                    if (unit.UnitID == 0)
                    {
                        unitRepo.Create(unit);
                    }
                    else
                    {
                        unitRepo.Update(unit);
                    }
                }
            }
            catch (SqlException sqlException)
            {
                if (sqlException.Number == 2627)
                {
                    MessageBox.Show("Наименование единицы измерения должно быть уникальным", "Предупреждение", MessageBoxButtons.OK);
                }
            }

            DialogResult = DialogResult.OK;
            Close();
        }
 public void Put(string DishName, [FromBody] Dish dish)
 {
     DishRepository.Update(DishName, dish);
 }