예제 #1
0
        public bool Update(Thucpham entity)
        {
            try
            {
                var thucpham = db.Thucphams.Find(entity.ID_thucpham);
                thucpham.Image_thucpham     = entity.Image_thucpham;
                thucpham.Ten_thucpham       = entity.Ten_thucpham;
                thucpham.Mota               = entity.Mota;
                thucpham.Total_Fat          = entity.Total_Fat;
                thucpham.Calories           = entity.Calories;
                thucpham.Cholesterol        = entity.Cholesterol;
                thucpham.Sodium             = entity.Sodium;
                thucpham.Total_Carbohydrate = entity.Total_Carbohydrate;
                thucpham.Total_Sugar        = entity.Total_Sugar;
                thucpham.Protein            = entity.Protein;
                thucpham.ID_loaithucpham    = entity.ID_loaithucpham;

                db.SaveChanges();
                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
예제 #2
0
 public ActionResult Edit(Thucpham thucpham)
 {
     if (ModelState.IsValid)
     {
         var dao = new ThucphamDao();
         thucpham.MetaTitle = VietNamChar.ReplaceUnicode(thucpham.Ten_thucpham);
         var result = dao.Update(thucpham);
         if (result)
         {
             return(RedirectToAction("Index", "Thucpham"));
         }
         else
         {
             ModelState.AddModelError("", "Cập nhật không thành công");
         }
     }
     return(View("Index"));
 }
예제 #3
0
        public ActionResult Create(Thucpham thucpham) // Tạo tài khoản
        {
            if (ModelState.IsValid)
            {
                var dao = new ThucphamDao();
                thucpham.MetaTitle = VietNamChar.ReplaceUnicode(thucpham.Ten_thucpham);
                long id = dao.Insert(thucpham);
                if (id > 0)
                {
                    return(RedirectToAction("Index", "Thucpham"));
                }
                else
                {
                    ModelState.AddModelError("", "Thêm không thành công");
                }
            }

            return(View("Index"));
        }
예제 #4
0
 public long Insert(Thucpham entity)
 {
     db.Thucphams.Add(entity);
     db.SaveChanges();
     return(entity.ID_thucpham);
 }