Ejemplo n.º 1
0
 public ActionResult Create(tbl_TinTuc obj, string txtId)
 {
     if (ModelState.IsValid)
     {
         obj.LuotXem = 0;
         var path = (string)null;
         obj.id_nhanvien = Convert.ToInt64(txtId);
         var dao = new TinTucDao();
         if (Request.Files.Count > 0)
         {
             var file = Request.Files[0];
             if (file != null && file.ContentLength > 0)
             {
                 var fileName = Path.GetFileName(file.FileName);
                 path = Path.Combine(Server.MapPath("~/asset/client/Audio_Video/Audio/TinTuc"), fileName);
                 file.SaveAs(path);
             }
         }
         obj.Url_BaiHat = path;
         long id = dao.Insert(obj);
         if (id > 0)
         {
             return(RedirectToAction("Index", "TinTuc"));
         }
         else
         {
             ModelState.AddModelError("", "Thêm nhân viên thành công!");
         }
     }
     return(RedirectToAction("Index"));
 }
Ejemplo n.º 2
0
        public ActionResult Create(TinTuc collection)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    // TODO: Add insert logic here
                    //var dao = new TinTucDao();
                    //long id = dao.Insert(collection);
                    //if (id > 0)
                    //{
                    //    return RedirectToAction("Index", "TinTuc");
                    //}
                    //else
                    //{
                    //    ModelState.AddModelError("", "Thêm không thành công");
                    //}


                    var dao = new TinTucDao();

                    var user = new TinTuc();
                    user.tieude   = collection.tieude;
                    user.hinhanh  = collection.hinhanh;
                    user.noidung  = collection.noidung;
                    user.ngaydang = DateTime.Now;


                    var res = dao.Insert(user);
                    if (res > 0)
                    {
                        SetAlert("Thêm thành công", "success");
                        return(RedirectToAction("Index", "TinTuc"));
                    }
                    else
                    {
                        ModelState.AddModelError("", "Đăng Ký Khong Thành Công");
                    }
                }



                return(View(collection));
            }
            catch
            {
                return(View("Index"));
            }
        }