Exemple #1
0
 public ActionResult AddNew()
 {
     IEnumerable<T_Tag> CatList = _tagServices.GetByTaxonomyForDisplay(Utilities.Constants.TAXONOMY_CATEGORY);
     NewsViewModel model = new NewsViewModel();
     model.CategoryList = CatList.ToList();
     return View("AddNew", model);
 }
Exemple #2
0
        public ActionResult AddNew(FormCollection form, string Published)
        {
            // Upload Image
            HttpPostedFileBase file = Request.Files["ImageData"];
            string AvataURL = UploadAvatar(file);
            // Insert News
            T_News AddNews = new T_News();
            AddNews.Title = form["Title"].ToString();
            AddNews.Slug = form["Slug"].ToString();
            AddNews.ContentNews = form["ContentNews"];
            AddNews.CreatedDate = DateTime.Now;

            if(!string.IsNullOrEmpty(Published)) AddNews.Status = Constants.NEWS_STATUS_PUBLIC;
            else AddNews.Status = form["Status"].ToString();
            AddNews.AvataImageUrl = AvataURL;
            AddNews.CreatedBy = User.Identity.Name;
            AddNews.Author = form["Author"];
            if (string.IsNullOrEmpty(form["Title"].ToString()) || string.IsNullOrEmpty(form["Slug"].ToString()))
            {
                IEnumerable<T_Tag> CatList = _tagServices.GetByTaxonomyForDisplay(Utilities.Constants.TAXONOMY_CATEGORY);

                NewsViewModel model = new NewsViewModel(AddNews);
                model.CategoryList = CatList.ToList();
                model.MyCategoryList = new List<T_Tag>();
                // Get Slide_List again
                ModelState.AddModelError("Error", "Tiêu đề, Slug không được để trống");
                return View(model);
            }

            T_News MyNews = _newsServices.AddNewNewsAndReturn(AddNews);

            // Set News Category
            int SelectedCate = Convert.ToInt16(form["Category"]);
            _news_TagServices.AddNewNews_Tag(MyNews.ID, SelectedCate);

            // Insert Tag and News_Tags
            AddListTag(form["tags"].ToString(), MyNews.ID);

            return RedirectToAction("List", "News");
        }
Exemple #3
0
        public ActionResult Edit(FormCollection form, string Published)
        {
            T_News EditNews = _newsServices.GetByID(Convert.ToInt32(form["ID"]));
            if (User.IsInRole(Utilities.Constants.ROLE_PUBLISHER) && EditNews.CreatedBy != User.Identity.Name)
            {
                return RedirectToAction("AccessDenied", "Start");
            }

            // Upload avata if it have
            HttpPostedFileBase file = Request.Files["ImageData"];
            string AvataURL = UploadAvatar(file);

            // Update News infomation
            EditNews.Title = form["Title"].ToString();
            EditNews.Slug = form["Slug"].ToString();
            EditNews.ContentNews = form["ContentNews"];
            EditNews.Author = form["Author"];
            EditNews.ModifiedBy =  User.Identity.Name;
            if (!string.IsNullOrEmpty(Published)) EditNews.Status = Constants.NEWS_STATUS_PUBLIC;
            else EditNews.Status = form["Status"].ToString();
            if (!String.IsNullOrEmpty(AvataURL))
            {
                EditNews.AvataImageUrl = AvataURL;
            }
            EditNews.ModifiedDate = DateTime.Now;
            EditNews.ModifiedBy = User.Identity.Name;
            if (string.IsNullOrEmpty(form["Title"].ToString()) || string.IsNullOrEmpty(form["Slug"].ToString()))
            {
                IEnumerable<T_Tag> MyTagList = _news_TagServices.GetTagByNewsID(EditNews.ID, Constants.TAXONOMY_TAG);
                IEnumerable<T_Tag> MyCategoryList = _news_TagServices.GetTagByNewsID(EditNews.ID, Constants.TAXONOMY_CATEGORY);
                IEnumerable<T_Tag> CatList = _tagServices.GetByTaxonomyForDisplay(Utilities.Constants.TAXONOMY_CATEGORY);

                NewsViewModel model = new NewsViewModel(EditNews);
                model.CategoryList = CatList.ToList();
                model.MyTagList = MyTagList.ToList();
                model.MyCategoryList = MyCategoryList.ToList();
                ViewData["TagList"] = BuildTagList(MyTagList.ToList());
                // Get Slide_List again
                ModelState.AddModelError("Error", "Tiêu đề, Slug không được để trống");
                ModelState.AddModelError("Error", "Phải chọn chuyên mục");
                return View(model);
            }
            ReturnValue<bool> result = _newsServices.UpdateNews(EditNews);

            // Delete all tags, category of this News
            _news_TagServices.DeleteAllTagByNewsID(EditNews.ID);

            // Set News Category
            int SelectedCate = Convert.ToInt16(form["Category"]);
            _news_TagServices.AddNewNews_Tag(EditNews.ID, SelectedCate);

            // Insert Tag and News_Tags
            AddListTag(form["Tags"].ToString(), EditNews.ID);
            return RedirectToAction("List", "News");
        }
Exemple #4
0
        public ActionResult Edit(int? id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }

            T_News News = _newsServices.GetByID((int)id);

            IEnumerable<T_Tag> MyTagList = _news_TagServices.GetTagByNewsID(News.ID, Constants.TAXONOMY_TAG);
            IEnumerable<T_Tag> MyCategoryList = _news_TagServices.GetTagByNewsID(News.ID, Constants.TAXONOMY_CATEGORY);
            IEnumerable<T_Tag> CatList = _tagServices.GetByTaxonomyForDisplay(Utilities.Constants.TAXONOMY_CATEGORY);

            NewsViewModel model = new NewsViewModel(News);
            model.CategoryList = CatList.ToList();
            model.MyTagList = MyTagList.ToList();
            model.MyCategoryList = MyCategoryList.ToList();
            ViewData["TagList"] = BuildTagList(MyTagList.ToList());
            return View("Edit", model);
        }