public static string NewsLink(this UrlHelper helper, News news) { if(string.IsNullOrEmpty(news.UrlKey)){ return helper.Action("ViewNewsById", "Content", new {id=news.NewsID, area="Content"}); } return helper.RouteUrl("News-View-Route", new { category = news.Category.StaticName, area = "Content" , news=news.UrlKey}); }
public ActionResult Create(CreateNewsModel model, FormCollection collection, HttpPostedFileBase PreviewImage) { try { if (ModelState.IsValid) { News news = new News() { Subject = model.Subject, Headline = model.Headline, Content = model.Content, Author = model.Author, Source = model.Source, News_CategoryID = model.CategoryId, CreatedUserID =SessionManager.UserInfo.UserID, SMSChannel = model.SMSChannel, ViewCount = 0, }; //HttpPostedFileBase file = HttpContext.Request.Files["Image"]; new NewsService().AddNews(news, PreviewImage); return RedirectToAction("Index"); } // TODO: Add insert logic here } catch(Exception ex) { Logger.Log(ex); ModelState.AddModelError("Error500","Không thể cập nhật tin."); } return View(model); }
public ActionResult Edit(int id, EditNewsModel model, FormCollection collection, HttpPostedFileBase PreviewImage) { try { if (ModelState.IsValid) { News ns = new News(); ns.CopyPropertiesFrom(model); ns.News_CategoryID = model.CategoryId; NewsService service = new NewsService(); ns.UpdatedUserID = SessionManager.UserInfo.UserID; service.Edit(ns, PreviewImage); return RedirectToAction("Index"); } } catch (Exception ex) { ModelState.AddModelError("Error500", "Có lỗi hệ thống - không cập nhật được dữ liệu."); } return View(model); }
public static string PageBreadcrum(this HtmlHelper helper, News item) { UrlHelper url = new UrlHelper(helper.ViewContext.RequestContext); StringBuilder sb = new StringBuilder(); Category category = item.Category; List<Category> categories = new List<Category>(); categories.Add(category); while (category.Category1!= null) { category = category.Category1; categories.Insert(0, category); }; sb.AppendFormat("<h3>"); sb.AppendFormat("<a href=\"{0}\">Trang chủ</a>",url.Home()); sb.AppendFormat("<span class=\"space\"><img src=\"/Content/images/next.gif\"></span>"); foreach (var cat in categories) { sb.AppendFormat(" <a href=\"{0}\">{1}</a><span class=\"space\"><img src=\"/Content/images/next.gif\"></span>",url.CategoryLink(cat), cat.CategoryName); } sb.AppendFormat("<span class=\"current\">{0}</span>", item.Subject); sb.AppendFormat("</h3>"); return sb.ToString(); }
/// <summary> /// Deprecated Method for adding a new object to the News EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToNews(News news) { base.AddObject("News", news); }
/// <summary> /// Create a new News object. /// </summary> /// <param name="newsID">Initial value of the NewsID property.</param> /// <param name="news_CategoryID">Initial value of the News_CategoryID property.</param> /// <param name="stategyType">Initial value of the StategyType property.</param> /// <param name="status">Initial value of the Status property.</param> public static News CreateNews(global::System.Int32 newsID, global::System.Int32 news_CategoryID, global::System.String stategyType, global::System.String status) { News news = new News(); news.NewsID = newsID; news.News_CategoryID = news_CategoryID; news.StategyType = stategyType; news.Status = status; return news; }