Пример #1
0
        public ActionResult Create(TinTucModel sp)
        {
            var dao = new TinTucDAO();
            var tk  = dao.GetByTitle(sp.TIEUDE_TINTUC);

            if (tk != null)
            {
                SetAlert("Tin tức đã  tồn tại", "fail");
                return(RedirectToAction("Index", "TinTuc"));
            }

            //string txtContent = ViewBag.GhiChu;

            var txtContent = Request.Unvalidated.Form.Get("txtContent");

            // encode the data
            sp.CREATEBY   = ((UserLogin)Session[CommonStants.USER_SESSION]).userName;
            sp.CREATEDATE = DateTime.Now;
            sp.IDTAIKHOAN = ((UserLogin)Session[CommonStants.USER_SESSION]).userID;

            decimal id = dao.Insert(sp);

            if (id > 0)
            {
                //var LastId = dao.getIDLastChild();
                //string exePath = System.AppContext.BaseDirectory + "\\Data\\Content\\" + namenew + ".html";
                string     exePath = Server.MapPath("\\Data\\Content\\tt" + id + ".cshtml");
                FileStream fs      = new FileStream(exePath, FileMode.Create);
                using (StreamWriter sw = new StreamWriter(fs))
                {
                    foreach (var s in txtContent)
                    {
                        sw.Write(s);
                    }
                    sw.Flush();
                }
                fs.Close();
                string link = "/Data/Content/tt" + id + ".html";
                dao.updatenoidung(link, id);
                SetAlert("Thêm Thành công", "success");
                return(RedirectToAction("Index", "TinTuc"));
            }
            else
            {
                ModelState.AddModelError("", "Thêm không thành công!");
            }


            return(View("Index"));
        }
Пример #2
0
 public ActionResult Create(tblTINTUC tintuc)
 {
     if (ModelState.IsValid)
     {
         var  dao = new TinTucDAO();
         long id  = dao.Insert(tintuc);
         if (id > 0)
         {
             return(RedirectToAction("Index", "TinTuc"));
         }
         else
         {
             ModelState.AddModelError("", "Thêm tin tức không thành công");
         }
     }
     return(View("Create"));
 }