/// <summary> /// Edits the specified post. /// </summary> /// <param name="post">post object.</param> /// <returns>identity post Edit</returns> public int Edit(C_Post post) { using (var data = new Entities()) { int rt = 0; try { var c_gen = data.C_Post.Where(p => p.PostID == post.PostID).FirstOrDefault(); c_gen.Title = post.Title; c_gen.Summary = post.Summary; c_gen.PostName = post.PostName; c_gen.PostContent = post.PostContent; c_gen.IsHot = post.IsHot; c_gen.OrderDisplay = post.OrderDisplay; c_gen.ImagePath = post.ImagePath; c_gen.Link = post.Link; c_gen.Lang = post.Lang; c_gen.Keyword = post.Keyword; c_gen.Description = post.Description; c_gen.DateModified = post.DateModified; c_gen.CatelogID = post.CatelogID; c_gen.Approve = post.Approve; data.SaveChanges(); rt = post.PostID; } catch (Exception) { rt = 0; } return(rt); } }
/// <summary> /// Updates the status is hot post. /// </summary> /// <param name="id">The identifier.</param> /// <param name="status">The status.</param> /// <param name="type">The type.</param> /// <returns>update status is hot post</returns> public ActionResult Update_status_is_hot_post(string id, string status, string type) { PostModels postModel = new PostModels(); C_Post objPost = new C_Post(); bool isOk = false; if (UserModels.CheckPermission(this.Session["mem"] != null ? this.Session["mem"].ToString() : string.Empty, "change_post", "adminPost", CommonGlobal.Edit, type)) { isOk = true; } else { isOk = false; } if (!string.IsNullOrEmpty(id)) { if (int.Parse(id) > 0) { objPost = postModel.GetbyID(int.Parse(id)); } if (objPost != null) { try { if (bool.Parse(status) == true) { objPost.IsHot = true; } else { objPost.IsHot = false; } if (isOk) { objPost.DateModified = DateTime.Now; postModel.Edit(objPost); } } catch (Exception) { } } } var jsonSerialiser = new JavaScriptSerializer(); var results = Convert.ToDateTime(DateTime.Now).ToString("dd/MM/yyyy") + "|" + objPost.IsHot; return(this.Json(results)); }
/// <summary> /// Adds the specified post. /// </summary> /// <param name="post">post object.</param> /// <returns>identity post add</returns> public int Add(C_Post post) { using (var data = new Entities()) { int rt = 0; try { data.C_Post.Add(post); data.SaveChanges(); rt = post.PostID; } catch (Exception) { rt = 0; } return(rt); } }
/// <summary> /// Posts the specified identifier. /// </summary> /// <param name="id">The identifier.</param> /// <param name="cate_id">The cate identifier.</param> /// <param name="cate_type">Type of the cate.</param> /// <returns>Posts the specified</returns> public ActionResult Post(int?id, int?cate_id, string cate_type) { /////post detail PostModels postModels = new PostModels(); id = RouteData.Values["id"] != null?Convert.ToInt16(RouteData.Values["id"].ToString()) : 0; var link = RouteData.Values["Link"] != null ? RouteData.Values["Link"].ToString() : string.Empty; cate_id = string.IsNullOrEmpty(Request.QueryString["cate_id"]) ? 0 : Convert.ToInt16(Request.QueryString["cate_id"].ToString()); if (string.IsNullOrEmpty(cate_type)) { cate_type = CommonGlobal.CateNews; } if (id == 0) { return(this.HttpNotFound()); } else { postModels.ClearCache(CommonGlobal.Post + string.Empty + id); C_Post obj = postModels.GetbyID((int)id); if (obj.PostID == 0) { return(this.HttpNotFound()); } ViewBag.Title = obj.Title + " | " + GeneralModels.GetContent(CommonGlobal.PageName, this.Lang); ////breadcrumbs string strbreadcrumbs = string.Empty; CatalogModels catalogModel = new CatalogModels(); C_Catalog cateItem = new C_Catalog(); if (cate_id == 0) { if (obj.CatelogID != null && obj.CatelogID != 0) { cate_id = obj.CatelogID; } } cateItem = catalogModel.GetbyID((int)cate_id); strbreadcrumbs = string.Format("<li><a href=\"" + Url.RouteUrl((cate_type != CommonGlobal.CateService ? "_post_only" : "_service_only"), new { controller = "news", action = "posts" }) + "\">" + (cate_type != CommonGlobal.CateService ? App_GlobalResources.Lang.mnuNews : App_GlobalResources.Lang.mnuService) + "</a></li>"); if (cateItem != null) { strbreadcrumbs += string.Format("<li><a href=\"" + Url.RouteUrl(cate_type == Web.Models.CommonGlobal.CateService ? "_service" : "_post", new { controller = "news", action = "posts", id = cate_id, Link = cateItem.Link != null ? cateItem.Link : string.Empty, cate_type = cate_type }) + "\">" + cateItem.CategoryName + "</a></li>"); ViewBag.cate_name = cateItem.CategoryName; } strbreadcrumbs += string.Format("<li>" + obj.Title + "</li>"); ViewBag.str_breadcrumbs = strbreadcrumbs; ViewBag.back_link = Url.RouteUrl(cate_type == CommonGlobal.CateService ? "_service" : "_post", new { controller = "news", action = "posts", id = cate_id, Link = cateItem.Link, cate_type = cate_type }); ViewBag.heading = obj.Title; this.AddMeta(CommonGlobal.Keyword, obj.Title); this.AddMeta(CommonGlobal.Description, this.ClearHtml(HttpUtility.HtmlDecode(obj.Summary))); ViewBag.id = id; ViewBag.cate_id = cate_id; ViewBag.cate_type = cate_type; ////// Add post cookies HttpCookie mycookie = HttpContext.Request.Cookies["listPostView"]; ArrayList arrListView = new ArrayList(); ////// Lấy danh sách post đã xem từ cookies if (mycookie != null) { var arr = mycookie.Value.Split(','); for (int j = 0; j < arr.Count(); j++) { arrListView.Add(arr[j]); } } else { arrListView = new ArrayList(); } if (obj.PostID != 0) { if (!Util.CheckExistInArray(obj.PostID.ToString(), arrListView)) { arrListView.Add(obj.PostID.ToString()); } ////// Lưu danh sách xuống cookies string[] arrLst = (string[])arrListView.ToArray(typeof(string)); if (mycookie != null) { HttpContext.Response.Cookies.Remove("listPostView"); mycookie.Expires = DateTime.Now.AddMonths(-6); mycookie.Value = null; HttpContext.Response.SetCookie(mycookie); } HttpCookie cookie_new = new HttpCookie("listPostView"); cookie_new.Value = string.Join(",", arrLst); cookie_new.Expires = DateTime.Now.AddMonths(6); HttpContext.Response.Cookies.Add(cookie_new); } return(this.PartialView("../page/post")); } }
public ActionResult Post_detail(int?id, int?cate_id, string back_link, string cate_type) { string url = Request.Url.ToString(); RatingModels ratingModels = new RatingModels(); PostModels postModels = new PostModels(); id = RouteData.Values["id"] != null?Convert.ToInt16(RouteData.Values["id"].ToString()) : 0; var post_view = new ViewModels.Post_detail_view(); if (id == 0) { return(this.HttpNotFound()); } else { postModels.ClearCache(CommonGlobal.Post + string.Empty + id); C_Post obj = postModels.GetbyID((int)id); if (obj.PostID == 0) { return(this.HttpNotFound()); } ////post_view.listRating = ratingModels.GetListRatingByItem(obj.PostID); ////StringBuilder _html5 = new StringBuilder(); ////for (int j = 0; j < post_view.listRating.Count; j++) ////{ //// _html5.Append("<div class=\"review-header\">"); //// _html5.Append(" <h5>" + HttpUtility.HtmlDecode(post_view.listRating[j].name) + "</h5>"); //// _html5.Append(" <div class=\"product-rating\">"); //// _html5.Append(" <div class=\"stars\">"); //// var start = post_view.listRating[j].Rating ?? 0; //// var other = 5 - start; //// for (int jj = 0; jj < other; jj++) //// { //// _html5.Append("<span class=\"star\"></span>"); //// } //// for (int ii = 0; ii < start; ii++) //// { //// _html5.Append("<span class=\"star active\"></span>"); //// } //// _html5.Append(" </div>"); //// _html5.Append(" </div>"); //// _html5.Append("</div>"); //// _html5.Append("<div class=\"review-body\">"); //// _html5.Append(" <p>" + HttpUtility.HtmlDecode(post_view.listRating[j].contents) + "</p>"); //// _html5.Append("</div>"); //// _html5.Append("<hr>"); ////} ////post_view.ltrRating = _html5.ToString(); ////post_view.ratingSum = ratingModels.GetRatingSumforItem(obj.PostID); ////post_view.ratingTotal = ratingModels.GetRatingTotalforItem(obj.PostID); ////StringBuilder _html6 = new StringBuilder(); ////var start_no = post_view.ratingTotal != 0 ? (post_view.ratingSum / post_view.ratingTotal) : 0; ////var other_no = 5 - start_no; ////for (int jj = 0; jj < other_no; jj++) ////{ //// _html6.Append("<span class=\"star\"></span>"); ////} ////for (int ii = 0; ii < start_no; ii++) ////{ //// _html6.Append("<span class=\"star active\"></span>"); ////} ////post_view.ratingStart = _html6.ToString(); post_view.ListOther = postModels.GetOthers(obj.PostID, obj.CatelogID ?? 0, LanguageModels.ActiveLanguage().LangCultureName, int.Parse(Util.GetConfigValue("NumberOtherNews", "3"))); CatalogModels catalogModel = new CatalogModels(); C_Catalog cateItem = new C_Catalog(); if (cate_id == 0) { if (obj.CatelogID != null && obj.CatelogID != 0) { cate_id = obj.CatelogID; } } cateItem = catalogModel.GetbyID((int)cate_id); post_view.PostID = obj.PostID; post_view.PostName = obj.PostName; post_view.Title = obj.Title; post_view.Summary = CommonGlobal.CutString(obj.Summary, 500); post_view.CatalogID = obj.CatelogID; post_view.ImagePath = obj.ImagePath; post_view.Link = obj.Link; post_view.PostContent = obj.PostContent; post_view.DateModified = obj.DateModified; post_view.IsHot = obj.IsHot; post_view.Lang = obj.Lang; post_view.Keyword = obj.Keyword; post_view.Description = obj.Description; post_view.OrderDisplay = obj.OrderDisplay; post_view.Approve = obj.Approve; post_view.Cate_id = cate_id ?? 0; post_view.Cate_type = cate_type; post_view.Url = url; } return(this.PartialView("../control/post_detail", post_view)); }
public ActionResult List_post(int?parent, int?cate_id, int?post_id, string type, string act, string ctrl, string type_act, string lang, string search, int?page, int?page_size, string order_by, string order_type) { CatalogModels cataModel = new CatalogModels(); PostModels postModel = new PostModels(); C_Post post = new C_Post(); List <SelectListItem> list_select_catalog = new List <SelectListItem>(); var list_post_view = new Web.Areas.Admin.ViewModels.List_post_view(); StringBuilder sb = new StringBuilder(); int total_record = 0; int level = 0; if (string.IsNullOrEmpty(type)) { type = Request.QueryString["type"] != null ? Request.QueryString["type"].ToString() : CommonGlobal.CateNews; } if (string.IsNullOrEmpty(act)) { act = Request.QueryString["act"] != null ? Request.QueryString["act"].ToString() : "list_post"; } if (string.IsNullOrEmpty(ctrl)) { ctrl = Request.QueryString["ctrl"] != null ? Request.QueryString["ctrl"].ToString() : "adminPost"; } if (page == null || page == 0) { page = Request.QueryString["page"] != null?Convert.ToInt32(Request.QueryString["page"].ToString()) : 1; } if (parent == null) { parent = Request.QueryString["parent"] != null?Convert.ToInt32(Request.QueryString["parent"].ToString()) : 0; } if (string.IsNullOrEmpty(lang)) { lang = LanguageModels.ActiveLanguage().LangCultureName; } if (page_size == null) { page_size = int.Parse(Util.GetConfigValue("NumberPageSizeAdmin", "30")); } list_post_view.Page = (int)page; list_post_view.Page_size = (int)page_size; list_post_view.Cate_type = CommonGlobal.GetCatalogTypeName(type); ////list category cataModel.List_catalog_parent(0, level, (int)parent, type, lang, ref list_select_catalog); list_post_view.List_parent = list_select_catalog; ////list language list_post_view.List_language = this.List_select_language(lang); ////tab sb.Append("<li class=\"active\"><a class=\"active\" href=\"" + Url.Action("index", "dashboard", new { act = "list_post", ctrl = "adminPost", type = type, page = "1", parent = parent, lang = lang }) + "\"><span><span>Danh mục " + CommonGlobal.GetCatalogTypeName(type) + "</span></span></a></li>"); sb.Append("<li><a href=\"" + Url.Action("index", "dashboard", new { act = "change_post", ctrl = "adminPost", type = type, type_act = "add", parent = parent, lang = lang }) + "\"><span><span>Thêm bài viết</span></span></a></li>"); list_post_view.Html_link_tab = sb.ToString(); if (post_id != null && post_id != 0 && type_act != null && type_act == CommonGlobal.Delete) { ////check permission delete if (UserModels.CheckPermission(this.Session["mem"] != null ? this.Session["mem"].ToString() : string.Empty, act, ctrl, type_act, type)) { post = postModel.GetbyID((int)post_id); if (post != null) { ////delete old image if (!string.IsNullOrEmpty(post.ImagePath)) { string strImg = post.ImagePath; strImg = "~" + strImg; string fileDelete = Server.MapPath(strImg); if (System.IO.File.Exists(fileDelete)) { System.IO.File.Delete(fileDelete); } string fileDelete2 = Server.MapPath(strImg.Replace("sc_small_", "sc_full_")); if (System.IO.File.Exists(fileDelete2)) { System.IO.File.Delete(fileDelete2); } } ////delete post bool rt = postModel.Delete((int)post_id); if (rt) { list_post_view.Message = "Bạn đã xóa bài viết: " + post_id; } else { list_post_view.Message = "Xóa không thành công"; } } else { list_post_view.Message = "Không tìm thấy bài viết : " + post_id; } } else { list_post_view.Message = " Bạn không có quyền thực thi hành động xóa."; } } ////list post list_post_view.List_page_size = this.GetSizePagingPublic((int)page_size); list_post_view.Page_list_post = postModel.GetListPostAll(lang, type, (int)parent, search, (int)page, (int)page_size, order_by, order_type, out total_record); list_post_view.Total_record = total_record; list_post_view.Search = search; list_post_view.Type_act = type_act; list_post_view.Type = type; ////action list_post_view.Act = act; list_post_view.Ctrl = ctrl; list_post_view.Parent_action = HttpContext.Request.RequestContext.RouteData.Values["action"].ToString(); list_post_view.Parent_controller = HttpContext.Request.RequestContext.RouteData.Values["controller"].ToString(); ////end action return(this.PartialView("../control/list_post", list_post_view)); }
public ActionResult Change_post(int?post_id, string type, string act, string ctrl, string type_act, string lang) { CatalogModels cateModels = new CatalogModels(); PostModels postModel = new PostModels(); C_Catalog cate = new C_Catalog(); C_Post objPost = new C_Post(); List <SelectListItem> list_select_catalog = new List <SelectListItem>(); var post_view = new Web.Areas.Admin.ViewModels.Post_view(); StringBuilder sb = new StringBuilder(); int level = 0; if (string.IsNullOrEmpty(type)) { type = Request.QueryString["type"] != null ? Request.QueryString["type"].ToString() : CommonGlobal.CateNews; } if (string.IsNullOrEmpty(act)) { act = Request.QueryString["act"] != null ? Request.QueryString["act"].ToString() : "change_post"; } if (string.IsNullOrEmpty(ctrl)) { ctrl = Request.QueryString["ctrl"] != null ? Request.QueryString["ctrl"].ToString() : "adminPost"; } if (post_id == null) { post_id = RouteData.Values["id"] != null?Convert.ToInt32(RouteData.Values["id"].ToString()) : 0; } if (string.IsNullOrEmpty(lang)) { lang = LanguageModels.ActiveLanguage().LangCultureName; } if (string.IsNullOrEmpty(type_act)) { type_act = Request.QueryString["type_act"] != null ? Request.QueryString["type_act"].ToString() : CommonGlobal.Add; if (post_id == 0) { type_act = CommonGlobal.Add; } else { type_act = CommonGlobal.Edit; } } if (type_act == CommonGlobal.Edit) { objPost = postModel.GetbyID((int)post_id); post_view.PostID = objPost.PostID; post_view.PostName = objPost.PostName; post_view.PostContent = objPost.PostContent; post_view.ImagePath = objPost.ImagePath; post_view.Title = objPost.Title; post_view.Keyword = objPost.Keyword; post_view.Description = objPost.Description; post_view.Summary = objPost.Summary; post_view.Lang = objPost.Lang; post_view.CatalogID = (int)objPost.CatelogID; post_view.OrderDisplay = (int)objPost.OrderDisplay; post_view.Parent = (int)objPost.CatelogID; post_view.CreateDate = objPost.CreateDate ?? DateTime.Now; if ((objPost.IsHot ?? false) == true) { post_view.IsHot = true; post_view.Is_short_text = "checked='checked'"; } else { post_view.IsHot = false; post_view.Is_short_text = string.Empty; } if ((objPost.Approve ?? false) == true) { post_view.Approve = true; post_view.Show_text = "checked='checked'"; } else { post_view.Approve = false; post_view.Show_text = string.Empty; } cateModels.List_catalog_parent(0, level, (int)objPost.CatelogID, type, cate.Lang ?? objPost.Lang, ref list_select_catalog); ////Link tab sb.Append("<li><a href=\"" + Url.Action("index", "dashboard", new { act = "list_post", ctrl = "adminPost", type = type, page = "1", lang = objPost.Lang }) + "\"><span><span>Danh sách tin tức</span></span></a></li>"); sb.Append("<li class=\"active\"><a href=\"#\"><span><span>Cập nhật</span></span></a></li>"); post_view.List_language = this.List_select_language(cate.Lang ?? objPost.Lang); } else { ////Link tab sb.Append("<li><a href=\"" + Url.Action("index", "dashboard", new { act = "list_post", ctrl = "adminPost", type = type, page = "1", lang = lang }) + "\"><span><span>Danh sách tin tức</span></span></a></li>"); sb.Append("<li class=\"active\"><a href=\"#\"><span><span>Thêm mới</span></span></a></li>"); cateModels.List_catalog_parent(0, level, 0, type, lang, ref list_select_catalog); post_view.List_language = this.List_select_language(lang); } post_view.List_category = list_select_catalog; post_view.Type = type; post_view.Type_act = type_act; post_view.Html_link_tab = sb.ToString(); ////action post_view.Act = act; post_view.Ctrl = ctrl; post_view.Parent_action = HttpContext.Request.RequestContext.RouteData.Values["action"].ToString(); post_view.Parent_controller = HttpContext.Request.RequestContext.RouteData.Values["controller"].ToString(); ////end action return(this.PartialView("../control/change_post", post_view)); }
public ActionResult Change_post(FormCollection collection, HttpPostedFileBase file_image) { CatalogModels cateModels = new CatalogModels(); PostModels postModel = new PostModels(); C_Post objPost = new C_Post(); StringBuilder sb = new StringBuilder(); int rt = 0; bool is_valid = true; int level = 0; List <SelectListItem> list_select_catalog = new List <SelectListItem>(); var post_view = new Web.Areas.Admin.ViewModels.Post_view(); this.TryUpdateModel(post_view); if (post_view.PostID > 0) { objPost = postModel.GetbyID(post_view.PostID); } ////validation server if (string.IsNullOrEmpty(post_view.PostName)) { is_valid = false; post_view.Message = "Bạn cần nhập tên danh mục"; } ////validation server if (post_view.Parent == 0) { is_valid = false; post_view.Message = "Bạn cần lựa chọn danh mục"; } ////action ////post_view.act = "change_post"; ////post_view.ctrl = "adminPost"; post_view.Parent_action = HttpContext.Request.RequestContext.RouteData.Values["action"].ToString(); post_view.Parent_controller = HttpContext.Request.RequestContext.RouteData.Values["controller"].ToString(); if (post_view.PostID != 0 && post_view.Type_act == CommonGlobal.Edit) { ////Link tab sb.Append("<li><a class=\"active\" href=\"" + Url.Action("index", "dashboard", new { act = "list_post", ctrl = "adminPost", type = post_view.Type, page = "1" }) + "\"><span><span>Danh sách tin tức</span></span></a></li>"); sb.Append("<li class=\"active\"><a href=\"#\"><span><span>Cập nhật</span></span></a></li>"); ////list parent cateModels.List_catalog_parent(0, level, objPost.CatelogID ?? 0, post_view.Type, objPost.Lang, ref list_select_catalog); post_view.List_category = list_select_catalog; ////list language post_view.List_language = this.List_select_language(objPost.Lang); } else { ////Link tab sb.Append("<li><a class=\"active\" href=\"" + Url.Action("index", "dashboard", new { act = "list_post", ctrl = "adminPost", type = post_view.Type, page = "1" }) + "\"><span><span>Danh sách tin tức</span></span></a></li>"); sb.Append("<li class=\"active\"><a href=\"#\"><span><span>Thêm mới</span></span></a></li>"); ////list parent cateModels.List_catalog_parent(0, level, 0, post_view.Type, post_view.Lang, ref list_select_catalog); post_view.List_category = list_select_catalog; ////list language post_view.List_language = this.List_select_language(post_view.Lang); } post_view.Html_link_tab = sb.ToString(); if (!is_valid) { return(this.PartialView("../control/change_post", post_view)); } ////Post info objPost.CatelogID = post_view.Parent; objPost.PostName = post_view.PostName; var imgPathTemp = "images/newspost/" + DateTime.Now.Year.ToString() + "/" + DateTime.Now.Month.ToString() + "/"; var name_time = DateTime.Now.Day + DateTime.Now.Month + DateTime.Now.Year + DateTime.Now.Hour + DateTime.Now.Minute + string.Empty; if (file_image != null && file_image.ContentLength > 0 && CommonGlobal.IsImage(file_image) == true) { string image_small = imgPathTemp + "sc_small_" + name_time + "_" + CommonGlobal.CompleteNamefileImages(file_image.FileName); string image_lager = imgPathTemp + "sc_full_" + name_time + "_" + CommonGlobal.CompleteNamefileImages(file_image.FileName); ////save image and delete old file this.Savephoto(objPost.ImagePath, file_image, imgPathTemp, image_small, image_lager); ////set image thumb to link catalog objPost.ImagePath = "/" + image_small; post_view.ImagePath = "/" + image_small; } else if (string.IsNullOrEmpty(objPost.ImagePath)) { objPost.ImagePath = "0"; } else { objPost.ImagePath = post_view.ImagePath; } objPost.Link = CommonGlobal.CompleteLink(post_view.PostName); objPost.Summary = post_view.Summary; objPost.PostContent = post_view.PostContent; objPost.DateModified = DateTime.Now; objPost.IsHot = post_view.IsHot; if (objPost.IsHot == true) { post_view.IsHot = true; post_view.Is_short_text = "checked='checked'"; } else { post_view.IsHot = false; post_view.Is_short_text = string.Empty; } objPost.Approve = post_view.Approve; if (objPost.Approve == true) { post_view.Approve = true; post_view.Show_text = "checked='checked'"; } else { post_view.Approve = false; post_view.Show_text = string.Empty; } objPost.Lang = post_view.Lang; objPost.Title = post_view.Title; objPost.Keyword = post_view.Keyword; objPost.Description = post_view.Description; objPost.OrderDisplay = post_view.OrderDisplay; if (post_view.PostID != 0 && post_view.Type_act == CommonGlobal.Edit) { objPost.CreateDate = post_view.CreateDate; rt = postModel.Edit(objPost); } else { objPost.CreateDate = DateTime.Now; rt = postModel.Add(objPost); } if (rt > 0) { post_view.Message = "Cập nhật thành công!"; post_view.PostID = rt; post_view.Type_act = CommonGlobal.Edit; } else { post_view.Message = "Cập nhật không thành công!"; } return(this.PartialView("../control/change_post", post_view)); }