public ActionResult Change_catalog(int?parent, int?cate_id, string type, string act, string ctrl, string lang, string type_act) { CatalogModels cateModels = new CatalogModels(); C_Catalog cate = new C_Catalog(); StringBuilder sb = new StringBuilder(); List <SelectListItem> list_select_catalog = new List <SelectListItem>(); var catalog_view = new Web.Areas.Admin.ViewModels.Catalog_view(); int level = 0; if (string.IsNullOrEmpty(type)) { type = Request.QueryString["type"] != null ? Request.QueryString["type"].ToString() : CommonGlobal.CateProduct; } if (string.IsNullOrEmpty(act)) { act = Request.QueryString["act"] != null ? Request.QueryString["act"].ToString() : "change_catalog"; } if (string.IsNullOrEmpty(ctrl)) { ctrl = Request.QueryString["ctrl"] != null ? Request.QueryString["ctrl"].ToString() : "adminCatalog"; } if (cate_id == null) { cate_id = RouteData.Values["id"] != null?Convert.ToInt32(RouteData.Values["id"].ToString()) : 0; } if (parent == null) { parent = string.IsNullOrEmpty(Request.QueryString["parent"]) ? 0 : Convert.ToInt32(Request.QueryString["parent"].ToString()); } 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 (cate_id == 0) { type_act = CommonGlobal.Add; } else { type_act = CommonGlobal.Edit; } } if (type_act == CommonGlobal.Edit) { cate = cateModels.GetbyID((int)cate_id); cateModels.List_catalog_parent(0, level, cate.ParentID ?? 0, type, cate.Lang ?? lang, ref list_select_catalog); var link_catalog = Url.Action("index", "dashboard", new { act = "list_catalog", ctrl = "adminCatalog", type_act = CommonGlobal.View, type = type, page = "1", parent = parent, lang = cate.Lang ?? lang }); sb.Append("<li><a class=\"active\" href=\"" + link_catalog + "\"><span><span>Danh mục " + CommonGlobal.GetCatalogTypeName(type) + "</span></span></a></li>"); sb.Append("<li class=\"active\"><a href=\"#\"><span><span>" + cate.CategoryName + "</span></span></a></li>"); catalog_view.Lang = cate.Lang ?? lang; catalog_view.Cate_id = cate.CatalogID; catalog_view.Category_name = cate.CategoryName; catalog_view.ImagePath = cate.ImagePath; catalog_view.Intro = cate.Intro; catalog_view.MoreInfo = cate.MoreInfo; catalog_view.Keyword = cate.Keyword; catalog_view.Description = cate.Description; catalog_view.Title = cate.Title; catalog_view.Link = cate.Link; catalog_view.Parent = cate.ParentID ?? 0; if ((cate.Show ?? false) == true) { catalog_view.Show = true; catalog_view.Show_text = "checked='checked'"; } else { catalog_view.Show = false; catalog_view.Show_text = string.Empty; } catalog_view.List_language = this.List_select_language(cate.Lang ?? this.Lang); catalog_view.OrderDisplay = (int)cate.OrderDisplay; } else { cateModels.List_catalog_parent(0, level, (int)parent, type, lang, ref list_select_catalog); var link_catalog = Url.Action("index", "dashboard", new { act = "list_catalog", ctrl = "adminCatalog", type = type, page = "1", parent = parent, lang = lang }); sb.Append("<li><a class=\"active\" href=\"" + link_catalog + "\"><span><span>Danh mục " + CommonGlobal.GetCatalogTypeName(type) + "</span></span></a></li>"); sb.Append("<li class=\"active\"><a href=\"#\"><span><span>Thêm danh mục</span></span></a></li>"); catalog_view.Lang = lang; catalog_view.List_language = this.List_select_language(this.Lang); catalog_view.OrderDisplay = cateModels.GetMaxOrderDisplay(type); catalog_view.Parent = (int)parent; } catalog_view.List_parent = list_select_catalog; catalog_view.Html_link_tab = sb.ToString(); catalog_view.Type = type; catalog_view.Type_act = type_act; ////action and parent action catalog_view.Act = act; catalog_view.Ctrl = ctrl; catalog_view.Parent_action = HttpContext.Request.RequestContext.RouteData.Values["action"].ToString(); catalog_view.Parent_controller = HttpContext.Request.RequestContext.RouteData.Values["controller"].ToString(); return(this.PartialView("../control/change_catalog", catalog_view)); }
public ActionResult Change_catalog(FormCollection collection, HttpPostedFileBase file_image) { CatalogModels cateModels = new CatalogModels(); C_Catalog cate = new C_Catalog(); StringBuilder sb = new StringBuilder(); int rt = 0; bool is_valid = true; int level = 0; List <SelectListItem> list_select_catalog = new List <SelectListItem>(); var catalog_view = new Web.Areas.Admin.ViewModels.Catalog_view(); this.TryUpdateModel(catalog_view); if (catalog_view.Cate_id > 0) { cate = cateModels.GetbyID(catalog_view.Cate_id); } ////validation server if (string.IsNullOrEmpty(catalog_view.Category_name)) { is_valid = false; catalog_view.Message = "Bạn cần nhập tên danh mục"; } ////action catalog_view.Parent_action = HttpContext.Request.RequestContext.RouteData.Values["action"].ToString(); catalog_view.Parent_controller = HttpContext.Request.RequestContext.RouteData.Values["controller"].ToString(); if (catalog_view.Cate_id != 0 && catalog_view.Type_act == CommonGlobal.Edit) { ////tab var link_catalog = Url.Action("index", "dashboard", new { act = "list_catalog", ctrl = "adminCatalog", type_act = CommonGlobal.View, type = catalog_view.Type, page = "1", parent = catalog_view.Parent, lang = catalog_view.Lang }); sb.Append("<li><a href=\"" + link_catalog + "\"><span><span>Danh sách " + CommonGlobal.GetCatalogTypeName(catalog_view.Type) + "</span></span></a></li>"); sb.Append("<li class=\"active\"><a href=\"#\"><span><span>" + cate.CategoryName + "</span></span></a></li>"); ////list parent cateModels.List_catalog_parent(0, level, cate.ParentID ?? 0, catalog_view.Type, cate.Lang, ref list_select_catalog); catalog_view.List_parent = list_select_catalog; ////list lang catalog_view.List_language = this.List_select_language(cate.Lang); catalog_view.Cate_id = cate.CatalogID; } else { ////tab sb.Append("<li><a href=\"" + Url.Action("index", "dashboard", new { act = "list_catalog", ctrl = "adminCatalog", type_act = CommonGlobal.View, type = catalog_view.Type, page = "1", parent = catalog_view.Parent, lang = catalog_view.Lang }) + "\"><span><span>Danh sách " + CommonGlobal.GetCatalogTypeName(catalog_view.Type) + "</span></span></a></li>"); sb.Append("<li class=\"active\"><a href=\"#\"><span><span>Thêm danh mục</span></span></a></li>"); ////list parent cateModels.List_catalog_parent(0, level, 0, catalog_view.Type, catalog_view.Lang, ref list_select_catalog); catalog_view.List_parent = list_select_catalog; ////list lang catalog_view.List_language = this.List_select_language(catalog_view.Lang); } catalog_view.Html_link_tab = sb.ToString(); if (!is_valid) { return(this.PartialView("../control/change_catalog", catalog_view)); } cate.CategoryName = catalog_view.Category_name; cate.Description = string.IsNullOrEmpty(catalog_view.Description) == false ? catalog_view.Description : string.Empty; cate.Keyword = string.IsNullOrEmpty(catalog_view.Keyword) == false ? catalog_view.Keyword : string.Empty; if (!string.IsNullOrEmpty(catalog_view.Title)) { cate.Title = catalog_view.Title; } else { cate.Title = catalog_view.Category_name; catalog_view.Title = cate.Title; } cate.Intro = string.IsNullOrEmpty(catalog_view.Intro) == false ? catalog_view.Intro : string.Empty; cate.MoreInfo = string.IsNullOrEmpty(catalog_view.MoreInfo) == false ? catalog_view.MoreInfo : string.Empty; cate.Lang = catalog_view.Lang; cate.OrderDisplay = catalog_view.OrderDisplay; cate.ParentID = catalog_view.Parent; cate.Show = catalog_view.Show; if ((cate.Show ?? false) == true) { catalog_view.Show = true; catalog_view.Show_text = "checked='checked'"; } else { catalog_view.Show = false; catalog_view.Show_text = string.Empty; } cate.Link = CommonGlobal.CompleteLink(catalog_view.Category_name); cate.Type = catalog_view.Type; var imgPathTemp = "images/catalog/" + 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.SavephotoCategory(cate.ImagePath, file_image, imgPathTemp, image_small, image_lager); ////save image and delete old file this.SavephotoOriginal(cate.ImagePath, file_image, imgPathTemp, image_lager); ////set image thumb to link catalog cate.ImagePath = "/" + image_lager; catalog_view.ImagePath = "/" + image_lager; } else if (string.IsNullOrEmpty(cate.ImagePath)) { cate.ImagePath = "0"; } else { cate.ImagePath = catalog_view.ImagePath; } if (catalog_view.Cate_id != 0 && catalog_view.Type_act == "edit") { rt = cateModels.Edit(cate); } else { rt = cateModels.Add(cate); } if (rt > 0) { catalog_view.Message = "Cập nhật thành công!"; catalog_view.Cate_id = rt; catalog_view.Cate_type = CommonGlobal.Edit; } else { catalog_view.Message = "Cập nhật không thành công!"; } return(this.PartialView("../control/change_catalog", catalog_view)); }
public ActionResult List_catalog(int?parent, int?cate_id, string act, string ctrl, string type, string type_act, string lang, string search, int?page, int?page_size, string order_by, string order_type) { CatalogModels cateModels = new CatalogModels(); C_Catalog cate = new C_Catalog(); StringBuilder sb = new StringBuilder(); List <SelectListItem> list_select_catalog = new List <SelectListItem>(); var list_catalog_view = new Web.Areas.Admin.ViewModels.List_catalog_view(); int total_record = 0; int level = 0; /////type is get type catalog /////ex : SP - product ///// : TT - news ///// : CL - collection ///// : LB - lookbook ///// : GL - gallery /////parent is parent id if (string.IsNullOrEmpty(type)) { type = Request.QueryString["type"] != null ? Request.QueryString["type"].ToString() : CommonGlobal.CateProduct; } if (string.IsNullOrEmpty(act)) { act = Request.QueryString["act"] != null ? Request.QueryString["act"].ToString() : "list_catalog"; } if (string.IsNullOrEmpty(ctrl)) { ctrl = Request.QueryString["ctrl"] != null ? Request.QueryString["ctrl"].ToString() : "adminCatalog"; } 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")); } if (string.IsNullOrEmpty(order_by) || string.IsNullOrEmpty(order_type)) { order_by = "OrderDisplay"; order_type = "asc"; } ////type act delete if (cate_id != null && 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)) { cate = cateModels.GetbyID((int)cate_id); if (cate != null) { ////delete old image if (!string.IsNullOrEmpty(cate.ImagePath)) { string strImg = cate.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 category bool rt = cateModels.Delete((int)cate_id); if (rt) { list_catalog_view.Message = "Bạn đã xóa danh mục " + cate_id; } else { list_catalog_view.Message = "Xóa không thành công"; } } else { list_catalog_view.Message = "Không tìm thấy danh mục : " + cate_id; } } else { list_catalog_view.Message = " Bạn không có quyền thực thi hành động xóa cho danh mục này "; } } if (parent != 0) { cate = cateModels.GetbyID((int)parent); list_catalog_view.Category_name = cate.CategoryName; } list_catalog_view.Type = type; list_catalog_view.Cate_type = CommonGlobal.GetCatalogTypeName(type); list_catalog_view.Parent = (int)parent; list_catalog_view.Lang = lang; list_catalog_view.Type_act = type_act; ////tab var link_dashboard = Url.Action("index", "dashboard", new { act = "list_catalog", ctrl = "adminCatalog", type_act = CommonGlobal.View, type = type, page = "1", parent = parent, lang = lang }); var link_change_catalog = Url.Action("index", "dashboard", new { act = "change_catalog", ctrl = "adminCatalog", type_act = CommonGlobal.Add, type = type, parent = parent, lang = lang }); sb.Append("<li class=\"active\"><a class=\"active\" href=\"" + link_dashboard + "\"><span><span>Danh sách " + CommonGlobal.GetCatalogTypeName(type) + "</span></span></a></li>"); sb.Append("<li><a href=\"" + link_change_catalog + "\"><span><span>Thêm mới</span></span></a></li>"); list_catalog_view.Html_link_tab = sb.ToString(); ////list language list_catalog_view.List_language = this.List_select_language(this.Lang); ////list category cateModels.List_catalog_parent(0, level, (int)parent, type, lang, ref list_select_catalog); list_catalog_view.List_parent = list_select_catalog; ////list page size and paging list_catalog_view.List_page_size = this.GetSizePagingPublic((int)page_size); list_catalog_view.Page = (int)page; list_catalog_view.Page_size = (int)page_size; ////list catalog list_catalog_view.Page_list_catalog = cateModels.GetAllCatalogByParentID((int)parent, type, lang, search, (int)page, (int)page_size, order_by, order_type, out total_record); list_catalog_view.Search = search; list_catalog_view.Order_by = order_by; list_catalog_view.Order_type = order_type; list_catalog_view.Total_record = total_record; ////acton and parent action list_catalog_view.Act = act; list_catalog_view.Ctrl = ctrl; list_catalog_view.Parent_action = HttpContext.Request.RequestContext.RouteData.Values["action"].ToString(); list_catalog_view.Parent_controller = HttpContext.Request.RequestContext.RouteData.Values["controller"].ToString(); return(this.PartialView("../control/list_catalog", list_catalog_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)); }
public ActionResult List_album_images(FormCollection collection) { CatalogModels cateModels = new CatalogModels(); GalleryModels galleryModels = new GalleryModels(); C_Catalog cate = new C_Catalog(); ImageAlbum imgPro = new ImageAlbum(); StringBuilder sb = new StringBuilder(); List <SelectListItem> list_select_catalog = new List <SelectListItem>(); var list_album_images_view = new Web.Areas.Admin.ViewModels.List_album_images_view(); this.TryUpdateModel(list_album_images_view); int total_record = 0; int level = 0; bool rt = true; bool is_valid = true; list_album_images_view.Cate_type = CommonGlobal.GetCatalogTypeName(list_album_images_view.Type); ////tab sb.Append("<li class=\"active\"><a class=\"active\" href=\"" + Url.Action("index", "dashboard", new { act = "list_catalog", ctrl = "adminCatalog", type = list_album_images_view.Type, page = "1", parent = list_album_images_view.Parent }) + "\"><span><span>Danh sách " + CommonGlobal.GetCatalogTypeName(list_album_images_view.Type) + "</span></span></a></li>"); list_album_images_view.Html_link_tab = sb.ToString(); ////list page size and paging list_album_images_view.List_page_size = this.GetSizePagingPublic(list_album_images_view.Page_size); ////acton and parent action list_album_images_view.Act = "list_album_images"; list_album_images_view.Ctrl = "adminLink"; list_album_images_view.Parent_action = HttpContext.Request.RequestContext.RouteData.Values["action"].ToString(); list_album_images_view.Parent_controller = HttpContext.Request.RequestContext.RouteData.Values["controller"].ToString(); ////delete image if (list_album_images_view.Id > 0 && list_album_images_view.Type_act == CommonGlobal.Delete) { ////check permission delete if (UserModels.CheckPermission(this.Session["mem"] != null ? this.Session["mem"].ToString() : string.Empty, list_album_images_view.Act, list_album_images_view.Ctrl, list_album_images_view.Type_act, list_album_images_view.Type)) { imgPro = galleryModels.GetImageById(list_album_images_view.Id); if (imgPro != null) { ////delete old image if (!string.IsNullOrEmpty(imgPro.Images)) { string strImg = imgPro.Images; 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 image product rt = galleryModels.Delete_Images(list_album_images_view.Id); if (rt) { list_album_images_view.Message = "Bạn đã xóa ảnh " + list_album_images_view.Id; } else { list_album_images_view.Message = "Xóa không thành công"; } } else { list_album_images_view.Message = "Không tìm thấy ảnh : " + list_album_images_view.Id; } } else { list_album_images_view.Message = " Bạn không có quyền thực thi hành động xóa."; } } else { if (list_album_images_view.Type_act == CommonGlobal.Add) { ////check permission add if (UserModels.CheckPermission(this.Session["mem"] != null ? this.Session["mem"].ToString() : string.Empty, list_album_images_view.Act, list_album_images_view.Ctrl, list_album_images_view.Type_act, list_album_images_view.Type)) { ////validation server if (list_album_images_view.Album == 0) { is_valid = false; list_album_images_view.Message = "Bạn cần lựa chọn album"; } if (list_album_images_view.File_image == null) { is_valid = false; list_album_images_view.Message = "Bạn cần chọn ảnh"; } var max_length = 1024 * 1024 * 10; ////10MB var length_all = 0; foreach (HttpPostedFileBase fi in list_album_images_view.File_image) { if (fi != null) { length_all = length_all + fi.ContentLength; } } if (length_all == 0) { is_valid = false; } if (length_all > max_length) { is_valid = false; list_album_images_view.Message = "Bạn đã không thể đăng quá nhiều ảnh (Tổng dung lượng tối đa 10MB)"; } if (is_valid) { ////upload multi images foreach (HttpPostedFileBase fi in list_album_images_view.File_image) { if (fi != null && fi.ContentLength > 0 && CommonGlobal.IsImage(fi) == true) { ////add new image var imgPathTemp = "images/photogallery/" + 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 + DateTime.Now.Second + DateTime.Now.Ticks + string.Empty; imgPro = new ImageAlbum(); string image_small = imgPathTemp + "sc_small_" + name_time + "_" + CommonGlobal.CompleteNamefileImages(fi.FileName); string image_lager = imgPathTemp + "sc_full_" + name_time + "_" + CommonGlobal.CompleteNamefileImages(fi.FileName); //////save images for multi file this.Savephoto(null, fi, imgPathTemp, image_small, image_lager); imgPro.Images = "/" + image_small; imgPro.ImagesFull = "/" + image_lager; imgPro.CatalogID = list_album_images_view.Album; list_album_images_view.ImagePath = "/" + image_small; rt = galleryModels.Add_Images(imgPro); if (rt) { list_album_images_view.Message = "Bạn đã thêm ảnh thành công!"; } else { if (list_album_images_view.Message != string.Empty) { list_album_images_view.Message = "updload ảnh không thành công: " + CommonGlobal.CompleteNamefileImages(fi.FileName); } else { list_album_images_view.Message += "; " + CommonGlobal.CompleteNamefileImages(fi.FileName); } } list_album_images_view.File_image = null; } } } } else { list_album_images_view.Message = " Bạn không có quyền thực thi thêm ảnh cho album "; } } else { list_album_images_view.Message = string.Empty; } } ////list language list_album_images_view.List_language = this.List_select_language(list_album_images_view.Lang); ////list category cateModels.List_catalog_parent(0, level, list_album_images_view.Parent, list_album_images_view.Type, list_album_images_view.Lang, ref list_select_catalog); list_album_images_view.List_parent = list_select_catalog; ////get list product list_album_images_view.Page_list_image = galleryModels.AdminGetAllImageGallery(list_album_images_view.Parent, list_album_images_view.Type, list_album_images_view.Lang, list_album_images_view.Page, list_album_images_view.Page_size, list_album_images_view.Order_by, list_album_images_view.Order_type, out total_record); list_album_images_view.Total_record = total_record; list_album_images_view.Order_by = list_album_images_view.Order_by; list_album_images_view.Order_type = list_album_images_view.Order_type; return(this.PartialView("../control/list_album_images", list_album_images_view)); }
public ActionResult List_album_images(int?parent, int?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 cateModels = new CatalogModels(); GalleryModels galleryModels = new GalleryModels(); C_Catalog cate = new C_Catalog(); ImageAlbum img = new ImageAlbum(); StringBuilder sb = new StringBuilder(); List <SelectListItem> list_select_catalog = new List <SelectListItem>(); var list_album_images_view = new Web.Areas.Admin.ViewModels.List_album_images_view(); int total_record = 0; int level = 0; /////type is get type catalog /////ex : LB - Lookbook ///// : GL - Gallery /////parent is array parent id if (string.IsNullOrEmpty(type)) { type = Request.QueryString["type"] != null ? Request.QueryString["type"].ToString() : CommonGlobal.CateLookBook; } if (string.IsNullOrEmpty(act)) { act = Request.QueryString["act"] != null ? Request.QueryString["act"].ToString() : "list_album_images"; } if (string.IsNullOrEmpty(ctrl)) { ctrl = Request.QueryString["ctrl"] != null ? Request.QueryString["ctrl"].ToString() : "adminLink"; } if (page == null || page == 0) { page = Request.QueryString["page"] != null?Convert.ToInt32(Request.QueryString["page"].ToString()) : 1; } if (page_size == null) { page_size = int.Parse(Util.GetConfigValue("NumberPageSizeAdmin", "30")); } if (parent == null) { parent = Request.QueryString["parent"] != null?Convert.ToInt32(Request.QueryString["parent"].ToString()) : 0; } if (string.IsNullOrEmpty(lang)) { lang = LanguageModels.ActiveLanguage().LangCultureName; } if (id != null && 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)) { img = galleryModels.GetImageById((int)id); if (img != null) { ////delete old image if (!string.IsNullOrEmpty(img.Images)) { string strImg = img.Images; 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 imgage album bool rt = galleryModels.Delete_Images((int)id); if (rt) { list_album_images_view.Message = "Bạn đã xóa ảnh " + id; } else { list_album_images_view.Message = "Xóa không thành công"; } } else { list_album_images_view.Message = "Không tìm thấy ảnh : " + id; } } else { list_album_images_view.Message = " Bạn không có quyền thực thi hành động xóa."; } } if (string.IsNullOrEmpty(order_by) || string.IsNullOrEmpty(order_type)) { order_by = "ID"; order_type = "asc"; } if (parent != 0) { cate = cateModels.GetbyID((int)parent); list_album_images_view.Category_name = cate.CategoryName; } list_album_images_view.Type = type; list_album_images_view.Cate_type = CommonGlobal.GetCatalogTypeName(type); list_album_images_view.Parent = (int)parent; list_album_images_view.Lang = lang; list_album_images_view.Type_act = type_act; ////tab sb.Append("<li class=\"active\"><a class=\"active\" href=\"" + Url.Action("index", "dashboard", new { act = "list_catalog", ctrl = "adminCatalog", type = type, page = "1", parent = parent }) + "\"><span><span>Danh sách " + CommonGlobal.GetCatalogTypeName(type) + "</span></span></a></li>"); list_album_images_view.Html_link_tab = sb.ToString(); ////list language list_album_images_view.List_language = this.List_select_language(this.Lang); ////list category for filter cateModels.List_catalog_parent(0, level, (int)parent, type, lang, ref list_select_catalog); list_album_images_view.List_parent = list_select_catalog; ////list page size and paging list_album_images_view.List_page_size = this.GetSizePagingPublic((int)page_size); list_album_images_view.Page = (int)page; list_album_images_view.Page_size = (int)page_size; ////list product list_album_images_view.Page_list_image = galleryModels.AdminGetAllImageGallery((int)parent, type, lang, (int)page, (int)page_size, order_by, order_type, out total_record); list_album_images_view.Order_by = order_by; list_album_images_view.Order_type = order_type; list_album_images_view.Total_record = total_record; ////acton and parent action list_album_images_view.Act = act; list_album_images_view.Ctrl = ctrl; list_album_images_view.Parent_action = HttpContext.Request.RequestContext.RouteData.Values["action"].ToString(); list_album_images_view.Parent_controller = HttpContext.Request.RequestContext.RouteData.Values["controller"].ToString(); return(this.PartialView("../control/list_album_images", list_album_images_view)); }