Example #1
0
        public ActionResult TinTuc()
        {
            BaiVietListAcion1 CommandAction = new BaiVietListAcion1();

            this.ViewBag.Result = CommandAction.Execute();
            return(View());
        }
Example #2
0
        public ActionResult SuaBaiViet(ThemBaiVietAction1 CommandAction, BaiVietHelper abc, HttpPostedFileBase anh, string editFlag = "M")
        {
            CommandAction.EditFlag = editFlag;

            if (anh != null)
            {
                var fileName = Path.GetFileName(anh.FileName);
                var rondom   = Guid.NewGuid() + fileName;
                var path     = Path.Combine(HttpContext.Server.MapPath("~/img/blog/"), rondom);
                if (!Directory.Exists(HttpContext.Server.MapPath("~/img/blog/")))
                {
                    Directory.CreateDirectory(HttpContext.Server.MapPath("~/img/blog/"));
                }
                anh.SaveAs(path);
                abc.anh = rondom;
                //return rondom;
            }
            else
            {
                abc.anh = "none-avatar.jpg";
            }

            /* cách này cũng đúng
             * if (Request.Files.Count > 0)
             * {
             *  var file = Request.Files[0];
             *
             *  if (file != null && file.ContentLength > 0)
             *  {
             *      var fileName = Path.GetFileName(file.FileName);
             *      var path = Path.Combine(Server.MapPath("~/img/blog"), fileName);
             *      file.SaveAs(path);
             *  }
             *  abc.anh = file.FileName.ToString();
             * }
             * else
             * {
             *  abc.anh = "none-avatar.jpg";
             * }
             */


            CommandAction.baiviet = abc;
            this.ViewBag.Result   = CommandAction.Execute();

            BaiVietListAcion1 hau = new BaiVietListAcion1();

            this.ViewBag.Result = hau.Execute();
            return(View("Index"));
        }
Example #3
0
 // GET: BaiViet
 //show bài viết
 public ActionResult Index(BaiVietListAcion1 CommandAction)
 {
     this.ViewBag.Result = CommandAction.Execute();
     return(View());
 }