public IActionResult Index([FromQuery] SearchArticles dto) { int TotalItems = 0; string ControllerName = this.ControllerContext.RouteData.Values["controller"].ToString() + "_" + HttpContext.Request.Headers["UserName"]; dto.IdCoQuan = int.Parse(HttpContext.Request.Headers["IdCoQuan"]); ArticlesModel data = new ArticlesModel() { SearchData = dto }; data.ListItems = ArticlesService.GetListPagination(data.SearchData, API.Models.Settings.SecretId + ControllerName); data.ListItemsDanhMuc = CategoriesArticlesService.GetListItems(); data.ListItemsAuthors = API.Areas.Admin.Models.USUsers.USUsersService.GetListItemsAuthor(4); data.ListItemsCreatedBy = API.Areas.Admin.Models.USUsers.USUsersService.GetListItemsAuthor(3); data.ListItemsStatus = ArticlesService.GetListItemsStatus(); if (data.ListItems != null && data.ListItems.Count() > 0) { TotalItems = data.ListItems[0].TotalRows; } HttpContext.Session.SetString("STR_Action_Link_" + ControllerName, Request.QueryString.ToString()); data.Pagination = new Models.Partial.PartialPagination() { CurrentPage = data.SearchData.CurrentPage, ItemsPerPage = data.SearchData.ItemsPerPage, TotalItems = TotalItems, QueryString = Request.QueryString.ToString() }; return(View(data)); }
public IActionResult SaveItem(string Id = null) { ArticlesModel data = new ArticlesModel(); string ControllerName = this.ControllerContext.RouteData.Values["controller"].ToString() + "_" + HttpContext.Request.Headers["UserName"]; int IdDC = Int32.Parse(MyModels.Decode(Id, API.Models.Settings.SecretId + ControllerName).ToString()); data.SearchData = new SearchArticles() { CurrentPage = 0, ItemsPerPage = 10, Keyword = "" }; data.ListItemsDanhMuc = CategoriesArticlesService.GetListItems(); data.ListItemsAuthors = API.Areas.Admin.Models.USUsers.USUsersService.GetListItemsAuthor(4); data.ListItemType = ArticlesService.GetListItemsType(); Articles Item = new Articles() { PublishUp = DateTime.Now, PublishUpShow = DateTime.Now.ToString("dd/MM/yyyy"), Status = true }; if (IdDC > 0) { Item = ArticlesService.GetItem(IdDC, API.Models.Settings.SecretId + ControllerName); } data.Item = Item; return(View(data)); }
public ActionResult UpdateStatus([FromQuery] string Ids, Boolean Status) { string ControllerName = this.ControllerContext.RouteData.Values["controller"].ToString(); CategoriesArticles item = new CategoriesArticles() { Id = Int32.Parse(MyModels.Decode(Ids, API.Models.Settings.SecretId + ControllerName).ToString()), Status = Status }; try { if (item.Id > 0) { item.CreatedBy = int.Parse(HttpContext.Request.Headers["Id"]); item.ModifiedBy = int.Parse(HttpContext.Request.Headers["Id"]); dynamic UpdateStatus = CategoriesArticlesService.UpdateStatus(item); TempData["MessageSuccess"] = "Cập nhật Trạng Thái thành công"; return(Json(new MsgSuccess())); } else { TempData["MessageError"] = "Cập nhật Trạng Thái Không thành công"; return(Json(new MsgError())); } } catch { TempData["MessageSuccess"] = "Cập nhật Trạng Thái không thành công"; return(Json(new MsgError())); } }
public ActionResult DeleteItem(string Id) { string ControllerName = this.ControllerContext.RouteData.Values["controller"].ToString(); CategoriesArticles model = new CategoriesArticles() { Id = Int32.Parse(MyModels.Decode(Id, API.Models.Settings.SecretId + ControllerName).ToString()) }; try { if (model.Id > 0) { model.CreatedBy = int.Parse(HttpContext.Request.Headers["Id"]); model.ModifiedBy = int.Parse(HttpContext.Request.Headers["Id"]); CategoriesArticlesService.DeleteItem(model); TempData["MessageSuccess"] = "Xóa thành công"; return(Json(new MsgSuccess())); } else { TempData["MessageError"] = "Xóa Không thành công"; return(Json(new MsgError())); } } catch { TempData["MessageSuccess"] = "Xóa không thành công"; return(Json(new MsgError())); } }
public IActionResult SaveItem(string Id = null, int IdCoQuan = 1) { MenusModel data = new MenusModel(); string ControllerName = this.ControllerContext.RouteData.Values["controller"].ToString(); int IdDC = Int32.Parse(MyModels.Decode(Id, API.Models.Settings.SecretId + ControllerName).ToString()); data.SearchData = new SearchMenus() { CurrentPage = 0, ItemsPerPage = 10, Keyword = "", IdCoQuan = IdCoQuan }; data.ListItemsArticle = ArticlesService.GetListStaticArticle(); data.ListType = MenusService.GetListType(); data.ListCategoriesArticles = CategoriesArticlesService.GetList(); data.ListCategoriesProducts = ProductsCategoriesService.GetList(); data.ListItemsMenus = MenusService.GetListItems(true, IdCoQuan); if (IdDC == 0) { data.Item = new Menus(); } else { data.Item = MenusService.GetItem(IdDC, API.Models.Settings.SecretId + ControllerName); } return(View(data)); }
public async Task <ActionResult> SaveItem(Articles data) { ArticlesModel model = new ArticlesModel() { Item = data }; string ControllerName = this.ControllerContext.RouteData.Values["controller"].ToString() + "_" + HttpContext.Request.Headers["UserName"]; int IdDC = Int32.Parse(MyModels.Decode(model.Item.Ids, API.Models.Settings.SecretId + ControllerName).ToString()); if (ModelState.IsValid) { if (data.Alias == null || data.Alias == "") { model.Item.Alias = API.Models.MyHelper.StringHelper.UrlFriendly(data.Title); } if (model.Item.Icon != null) { var Image = await FileHelpers.ProcessFormFile(model.Item.Icon, ModelState); if (Image.Length > 0) { model.Item.Images = Image; } } if (model.Item.Id == IdDC) { model.Item.CreatedBy = int.Parse(HttpContext.Request.Headers["Id"]); model.Item.ModifiedBy = int.Parse(HttpContext.Request.Headers["Id"]); model.Item.IdCoQuan = int.Parse(HttpContext.Request.Headers["IdCoQuan"]); try { ArticlesService.SaveItem(model.Item); TempData["MessageSuccess"] = "Cập nhật thành công"; string Str_Url = HttpContext.Session.GetString("STR_Action_Link_" + ControllerName); if (Str_Url != null && Str_Url != "") { return(Redirect("/Admin/" + this.ControllerContext.RouteData.Values["controller"].ToString() + "/Index" + Str_Url)); } else { return(RedirectToAction("Index")); } } catch { } } } model.SearchData = new SearchArticles() { CurrentPage = 0, ItemsPerPage = 10, Keyword = "" }; model.ListItemsDanhMuc = CategoriesArticlesService.GetListItems(); model.ListItemsAuthors = API.Areas.Admin.Models.USUsers.USUsersService.GetListItemsAuthor(4); model.ListItemType = ArticlesService.GetListItemsType(); return(View(model)); }
public IActionResult KHCNDS() { int TotalItems = 0; int IdCoQuan = 1; if (HttpContext.Session.GetString("IdCoQuan") != null && HttpContext.Session.GetString("IdCoQuan") != "") { IdCoQuan = int.Parse(HttpContext.Session.GetString("IdCoQuan")); } string ControllerName = this.ControllerContext.RouteData.Values["controller"].ToString(); CategoriesArticles categories = CategoriesArticlesService.GetItem(296, API.Models.Settings.SecretId + ControllerName); ArticlesModel data = new ArticlesModel() { Categories = categories }; return(View(data)); }
public IActionResult Index([FromQuery] SearchCategoriesArticles dto) { int TotalItems = 0; string ControllerName = this.ControllerContext.RouteData.Values["controller"].ToString(); CategoriesArticlesModel data = new CategoriesArticlesModel() { SearchData = dto }; data.ListItems = CategoriesArticlesService.GetListPagination(data.SearchData, API.Models.Settings.SecretId + ControllerName); if (data.ListItems != null && data.ListItems.Count() > 0) { TotalItems = data.ListItems[0].TotalRows; } data.Pagination = new Models.Partial.PartialPagination() { CurrentPage = data.SearchData.CurrentPage, ItemsPerPage = data.SearchData.ItemsPerPage, TotalItems = TotalItems, QueryString = Request.QueryString.ToString() }; return(View(data)); }
public IActionResult GetListChildCat(string alias, int id, [FromQuery] SearchArticles dto) { int IdCoQuan = 1; if (HttpContext.Session.GetString("IdCoQuan") != null && HttpContext.Session.GetString("IdCoQuan") != "") { IdCoQuan = int.Parse(HttpContext.Session.GetString("IdCoQuan")); } string ControllerName = this.ControllerContext.RouteData.Values["controller"].ToString(); CategoriesArticles categories = CategoriesArticlesService.GetItem(id, API.Models.Settings.SecretId + ControllerName); dto.CatId = id; dto.IdCoQuan = IdCoQuan; dto.ShowStartDate = "01/01/2010"; ArticlesModel data = new ArticlesModel() { SearchData = dto, Categories = categories }; return(View(data)); }
public IActionResult GetByCat(string alias, int id, [FromQuery] SearchArticles dto) { int TotalItems = 0; int IdCoQuan = 1; if (HttpContext.Session.GetString("IdCoQuan") != null && HttpContext.Session.GetString("IdCoQuan") != "") { IdCoQuan = int.Parse(HttpContext.Session.GetString("IdCoQuan")); } string ControllerName = this.ControllerContext.RouteData.Values["controller"].ToString(); CategoriesArticles categories = CategoriesArticlesService.GetItem(id, API.Models.Settings.SecretId + ControllerName); dto.CatId = id; dto.IdCoQuan = IdCoQuan; dto.ShowStartDate = "01/01/2000"; dto.Status = 1; dto.ItemsPerPage = 15; ArticlesModel data = new ArticlesModel() { SearchData = dto, Categories = categories }; data.ListItems = ArticlesService.GetListPagination(data.SearchData, API.Models.Settings.SecretId + ControllerName); //data.ListItemsDanhMuc = CategoriesArticlesService.GetListItems(); if (data.ListItems != null && data.ListItems.Count() > 0) { TotalItems = data.ListItems[0].TotalRows; } data.Pagination = new Areas.Admin.Models.Partial.PartialPagination() { CurrentPage = data.SearchData.CurrentPage, ItemsPerPage = data.SearchData.ItemsPerPage, TotalItems = TotalItems, QueryString = Request.QueryString.ToString() }; return(View(data)); }
public IActionResult Detail(string alias, int id) { ArticlesModel data = new ArticlesModel(); string ControllerName = this.ControllerContext.RouteData.Values["controller"].ToString(); data.SearchData = new SearchArticles() { CurrentPage = 0, ItemsPerPage = 10, Keyword = "" }; data.ListItemsDanhMuc = CategoriesArticlesService.GetListItems(); data.Item = ArticlesService.GetItem(id, API.Models.Settings.SecretId + ControllerName); CategoriesArticles categories = CategoriesArticlesService.GetItem(data.Item.CatId); var hit = ArticlesService.UpdateHit(id); data.Categories = categories; if (categories.Id != 0) { data.ListItems = ArticlesService.GetListRelativeNews(alias, categories.Id); } return(View(data)); }
public IActionResult SaveItem(string Id = null) { CategoriesArticlesModel data = new CategoriesArticlesModel(); string ControllerName = this.ControllerContext.RouteData.Values["controller"].ToString(); int IdDC = Int32.Parse(MyModels.Decode(Id, API.Models.Settings.SecretId + ControllerName).ToString()); data.ListItemsDanhMuc = CategoriesArticlesService.GetListItems(); data.SearchData = new SearchCategoriesArticles() { CurrentPage = 0, ItemsPerPage = 10, Keyword = "" }; if (IdDC == 0) { data.Item = new CategoriesArticles(); } else { data.Item = CategoriesArticlesService.GetItem(IdDC, API.Models.Settings.SecretId + ControllerName); } return(View(data)); }
public async Task <ActionResult> SaveItem(CategoriesArticlesModel model) { string ControllerName = this.ControllerContext.RouteData.Values["controller"].ToString(); int IdDC = Int32.Parse(MyModels.Decode(model.Item.Ids, API.Models.Settings.SecretId + ControllerName).ToString()); CategoriesArticlesModel data = model; if (ModelState.IsValid) { if (model.Item.Icon != null) { var Image = await FileHelpers.ProcessFormFile(model.Item.Icon, ModelState); if (Image.Length > 0) { model.Item.Images = Image; } } if (model.Item.Id == IdDC) { model.Item.CreatedBy = int.Parse(HttpContext.Request.Headers["Id"]); model.Item.ModifiedBy = int.Parse(HttpContext.Request.Headers["Id"]); var Obj = CategoriesArticlesService.SaveItem(model.Item); if (Obj.N == -2) { TempData["MessageError"] = "Chọn danh mục cha không hợp lệ"; data.ListItemsDanhMuc = CategoriesArticlesService.GetListItems(); return(View(data)); } TempData["MessageSuccess"] = "Cập nhật thành công"; return(RedirectToAction("Index")); } } data.ListItemsDanhMuc = CategoriesArticlesService.GetListItems(); return(View(data)); }
public IActionResult Index([FromQuery] SearchArticles dto, string btn = "search") { int TotalItems = 0; string ControllerName = this.ControllerContext.RouteData.Values["controller"].ToString() + "_" + HttpContext.Request.Headers["UserName"]; dto.IdCoQuan = int.Parse(HttpContext.Request.Headers["IdCoQuan"]); ArticlesModel data = new ArticlesModel() { SearchData = dto }; data.SearchData.ItemsPerPage = 50; data.ListItems = ArticlesService.GetListReport(data.SearchData, API.Models.Settings.SecretId + ControllerName); data.ListItemsDanhMuc = CategoriesArticlesService.GetListItems(); data.ListItemsAuthors = API.Areas.Admin.Models.USUsers.USUsersService.GetListItemsAuthor(4); data.ListItemsCreatedBy = API.Areas.Admin.Models.USUsers.USUsersService.GetListAll(); data.ListItemType = ArticlesService.GetListItemsType(true); if (data.ListItems != null && data.ListItems.Count() > 0) { TotalItems = data.ListItems[0].TotalRows; } HttpContext.Session.SetString("STR_Action_Link_" + ControllerName, Request.QueryString.ToString()); data.Pagination = new Models.Partial.PartialPagination() { CurrentPage = data.SearchData.CurrentPage, ItemsPerPage = data.SearchData.ItemsPerPage, TotalItems = TotalItems, QueryString = Request.QueryString.ToString() }; //--Xuất excel if (btn == "excel") { try { // var l = ThongKeRepository.GetList(page, 50000, ArticleCatId, login.Role, ListCheck, tungay, denngay); var workbook = new XLWorkbook(); var ws = workbook.Worksheets.Add("DanhSach"); int i = 1; ws.Cell("A1").Value = "STT"; ws.Cell("B1").Value = "Tên bài viết"; ws.Cell("C1").Value = "Ngày đăng"; ws.Cell("D1").Value = "Người đăng"; ws.Cell("E1").Value = "Loại tin bài"; ws.Cell("F1").Value = "Danh mục"; ws.Cell("G1").Value = "Nguồn"; var rngTable = ws.Range("A1:G1"); rngTable.Style.Font.Bold = true; var search2 = data.SearchData; search2.ItemsPerPage = 100000; var l = ArticlesService.GetListReport(search2, API.Models.Settings.SecretId + ControllerName); foreach (var item in l) { i++; ws.Cell("A" + i).Value = i - 1;; ws.Cell("B" + i).Value = item.Title; ws.Cell("C" + i).Value = "Ngày: " + DateTime.Parse(item.CreatedDate.ToString()).ToString("dd/MM/yyyy HH:mm:ss"); ws.Cell("D" + i).Value = item.CreatedByName; ws.Cell("E" + i).Value = (item.TypeId == 1 ? "Tin tự biên tập" : "Tin đăng lại"); ws.Cell("F" + i).Value = item.Category; ws.Cell("G" + i).Value = item.SourceLink; } ws.Columns().AdjustToContents(); var path = Path.Combine(_hostingEnvironment.WebRootPath, "CMS"); var filename = "ThongKe_" + DateTime.Now.Ticks + ".xlsx"; workbook.SaveAs(System.IO.Path.Combine(path, filename)); string filepath = Path.Combine(path, filename); FileInfo file = new FileInfo(filepath); if (file.Exists) { byte[] fileBytes = System.IO.File.ReadAllBytes(filepath); return(File(fileBytes, "application/x-msdownload", filename)); //System.IO.File.Delete(filepath); } } catch (Exception e) { return(View(data)); } } return(View(data)); }
public IActionResult Index(int Category_Id = 0) { string ControllerName = this.ControllerContext.RouteData.Values["controller"].ToString(); ImportDBOldModel data = new ImportDBOldModel() { }; if (Category_Id == 1) { data.ListItems = ImportDBOldService.GetList(); if (data.ListItems != null && data.ListItems.Count() > 0) { for (int i = 0; i < data.ListItems.Count(); i++) { string Alias = API.Models.MyHelper.StringHelper.UrlFriendly(data.ListItems[i].Title); var k = API.Areas.Admin.Models.Articles.ArticlesService.UpdateAlias(data.ListItems[i].Id, Alias); } } } if (Category_Id == 4) { data.ListItems = ImportDBOldService.GetList(); if (data.ListItems != null && data.ListItems.Count() > 0) { for (int i = 0; i < data.ListItems.Count(); i++) { string Introtext = API.Models.StringUtilities.Truncate(API.Models.StringUtilities.RemoveHtmlTags(data.ListItems[i].Content), 250); var k = API.Areas.Admin.Models.Articles.ArticlesService.UpdateIntrotext(data.ListItems[i].Id, Introtext); } } } else if (Category_Id == 2) { List <CategoriesArticles> listCat = CategoriesArticlesService.GetList(); if (listCat != null && listCat.Count() > 0) { for (int i = 0; i < listCat.Count(); i++) { string Alias = API.Models.MyHelper.StringHelper.UrlFriendly(listCat[i].Title); var k = API.Areas.Admin.Models.CategoriesArticles.CategoriesArticlesService.UpdateAlias(listCat[i].Id, Alias); } } } else if (Category_Id == 3) { data.ListItems = ImportDBOldService.GetList(); if (data.ListItems != null && data.ListItems.Count() > 0) { for (int i = 0; i < data.ListItems.Count(); i++) { List <Articles> ListFileName = ArticlesService.GetListArticle_Files(data.ListItems[i].Id); if (ListFileName != null && ListFileName.Count() > 0) { List <FileArticle> tmpListFile = new List <FileArticle>(); for (int j = 0; j < ListFileName.Count(); j++) { FileArticle tmp_file_article = new FileArticle() { FilePath = "/CMS/Content/TaiLieu/" + ListFileName[j].Images }; tmpListFile.Add(tmp_file_article); } if (tmpListFile != null && tmpListFile.Count() > 0) { ArticlesService.UpdateUpdateStr_ListFile(data.ListItems[i].Id, JsonConvert.SerializeObject(tmpListFile)); } } else { } } } } return(View(data)); }