/// <summary> /// Updates the status catalog. /// </summary> /// <param name="id">The identifier.</param> /// <param name="status">The status.</param> /// <param name="type">The type.</param> /// <returns>update status catalog</returns> public ActionResult Update_status_catalog(string id, string status, string type) { CatalogModels cateModels = new CatalogModels(); C_Catalog cate = new C_Catalog(); bool isOk = false; if (UserModels.CheckPermission(this.Session["mem"] != null ? this.Session["mem"].ToString() : string.Empty, "change_catalog", "adminCatalog", CommonGlobal.Edit, type)) { isOk = true; } else { isOk = false; } if (!string.IsNullOrEmpty(id)) { if (int.Parse(id) > 0) { cate = cateModels.GetbyID(int.Parse(id)); } if (cate != null) { try { if (bool.Parse(status) == true) { cate.Show = true; } else { cate.Show = false; } if (isOk) { cateModels.Edit(cate); } } catch (Exception) { } } } var jsonSerialiser = new JavaScriptSerializer(); var results = Convert.ToDateTime(DateTime.Now).ToString("dd/MM/yyyy") + "|" + cate.Show; return(this.Json(results)); }
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)); }