Exemple #1
0
        public ActionResult newsCreate(FormCollection form, HttpPostedFileBase fileUpload)
        {
            tbl_new tic          = new tbl_new();
            var     name         = form["name"];
            var     detail       = form["detail"];
            var     detail_short = form["detail_short"];


            var title       = form["title"];
            var description = form["description"];
            var keyword     = form["keyword"];

            tic.title       = title;
            tic.description = description;
            tic.alias       = DataHelper.GeneralHelper.getInstance().getAliasFromNewsName(data, name);


            tic.keyword = keyword;
            bool err = false;

            if (String.IsNullOrEmpty(name))
            {
                err = true;
                ViewData["Error"] += "Vui lòng nhập tên tin tức!\n";
            }
            tic.TieuDe      = name;
            tic.status      = true;
            tic.NgayCapNhat = DateTime.Now;
            tic.NoiDung     = detail;
            tic.TomTat      = detail_short;
            if (form["chkClearImg"] != null)
            {
                tic.UrlHinh = "";
            }
            else if (fileUpload != null)
            {
                var fileName = Path.GetFileName(DateTime.Now.Millisecond + fileUpload.FileName);
                var path     = Path.Combine(Server.MapPath(URLHelper.URL_IMAGE_PATH), fileName);
                if (!System.IO.File.Exists(path))
                {
                    fileUpload.SaveAs(path);
                }
                tic.UrlHinh = fileName;
            }
            else
            {
                tic.UrlHinh = "";
            }
            if (err == false)
            {
                data.tbl_news.InsertOnSubmit(tic);
                data.SubmitChanges();
                return(RedirectToAction("newsView"));
            }
            else
            {
                return(View(URLHelper.URL_ADMIN_NEWS_M, tic));
            }
        }
        public ActionResult NewsSetStatusEnable(int id)
        {
            tbl_new tic = getOneNews(id);

            tic.status = !tic.status;
            UpdateModel(tic);
            data.SubmitChanges();
            return(RedirectToAction("newsView"));
        }
        public ActionResult newsEdit(FormCollection form, HttpPostedFileBase fileUpload)
        {
            var id = form["id"];

            if (id == null)
            {
                return(newsCreate(form, fileUpload));
            }
            else
            {
                tbl_new tic          = getOneNews(Int32.Parse(id));
                var     name         = form["name"];
                var     detail       = form["detail"];
                var     detail_short = form["detail_short"];


                var title       = form["title"];
                var description = form["description"];
                var keyword     = form["keyword"];
                tic.title       = title;
                tic.description = description;
                if (!tic.TieuDe.Equals(name))
                {
                    tic.alias = DataHelper.GeneralHelper.getInstance().getAliasFromNewsName(data, name);
                }


                tic.keyword = keyword;
                bool err = false;
                if (String.IsNullOrEmpty(name))
                {
                    err = true;
                    ViewData["Error"] += "Vui lòng nhập tên danh mục!\n";
                }
                if (form["parent"].ToString().Equals("0"))
                {
                    err = true;
                    ViewData["Error"] += "Vui lòng chọn danh mục!\n";
                }
                else
                {
                    tic.idloaitt = Int32.Parse(form["parent"]);
                }

                tic.TieuDe      = name;
                tic.NgayCapNhat = DateTime.Now;
                tic.NoiDung     = detail;
                tic.TomTat      = detail_short;
                if (form["chkClearImg"] != null)
                {
                    tic.UrlHinh = "";
                }
                else if (fileUpload != null)
                {
                    var fileName = Path.GetFileName(DateTime.Now.Millisecond + fileUpload.FileName);
                    var path     = Path.Combine(Server.MapPath(URLHelper.URL_IMAGE_PATH), fileName);
                    if (!System.IO.File.Exists(path))
                    {
                        fileUpload.SaveAs(path);
                    }
                    String imageOlder = URLHelper.URL_IMAGE_PATH + tic.UrlHinh;
                    if (System.IO.File.Exists(imageOlder))
                    {
                        System.IO.File.Delete(imageOlder);
                    }
                    tic.UrlHinh = fileName;
                }
                else
                {
                    tic.UrlHinh = "";
                }
                if (err == false)
                {
                    UpdateModel(tic);
                    data.SubmitChanges();
                    return(RedirectToAction("newsView"));
                }
                else
                {
                    return(View(URLHelper.URL_ADMIN_NEWS_M, new Tuple <tbl_new, List <tbl_new_type> >(tic, getAllNewsCategories())));
                }
            }
        }
        public ActionResult newsCreate()
        {
            var news = new tbl_new();

            return(View(URLHelper.URL_ADMIN_NEWS_M, new Tuple <tbl_new, List <tbl_new_type> >(news, getAllNewsCategories())));
        }