public ActionResult UpdateFeatured([FromQuery] string Ids, Boolean Featured) { string ControllerName = this.ControllerContext.RouteData.Values["controller"].ToString(); CategoriesAblums item = new CategoriesAblums() { Id = Int32.Parse(MyModels.Decode(Ids, API.Models.Settings.SecretId + ControllerName).ToString()), Featured = Featured }; try { if (item.Id > 0) { item.CreatedBy = int.Parse(HttpContext.Request.Headers["Id"]); item.ModifiedBy = int.Parse(HttpContext.Request.Headers["Id"]); dynamic UpdateFeatured = CategoriesAblumsService.UpdateFeatured(item); TempData["MessageSuccess"] = "Cập nhật Nổi bật thành công"; return(Json(new MsgSuccess())); } else { TempData["MessageError"] = "Cập nhật Nổi bật Không thành công"; return(Json(new MsgError())); } } catch { TempData["MessageSuccess"] = "Cập nhật Nổi bật không thành công"; return(Json(new MsgError())); } }
public ActionResult DeleteItem(string Id) { string ControllerName = this.ControllerContext.RouteData.Values["controller"].ToString(); CategoriesAblums model = new CategoriesAblums() { 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"]); CategoriesAblumsService.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 async Task <IActionResult> SaveItem(IList <IFormFile> files, CategoriesAblums model) { string ControllerName = this.ControllerContext.RouteData.Values["controller"].ToString(); int IdDC = Int32.Parse(MyModels.Decode(model.Ids, API.Models.Settings.SecretId + ControllerName).ToString()); CategoriesAblumsModel data = new CategoriesAblumsModel() { Item = model }; if (ModelState.IsValid) { if (model.Id == IdDC) { model.CreatedBy = int.Parse(HttpContext.Request.Headers["Id"]); model.ModifiedBy = int.Parse(HttpContext.Request.Headers["Id"]); var Cat = CategoriesAblumsService.SaveItem(model); foreach (IFormFile source in files) { string filename = ContentDispositionHeaderValue.Parse(source.ContentDisposition).FileName.Trim('"'); filename = this.EnsureCorrectFilename(filename); using (FileStream output = System.IO.File.Create(this.GetPathAndFilename(filename))) { await source.CopyToAsync(output); Ablums alb = new Ablums() { CatId = Convert.ToInt32(Cat.N), CreatedBy = model.CreatedBy, ModifiedBy = model.ModifiedBy, Images = this.GetPathAndFilename(filename) }; AblumsService.SaveItem(alb); } } if (model.Id > 0) { TempData["MessageSuccess"] = "Cập nhật thành công"; } else { TempData["MessageSuccess"] = "Thêm mới thành công"; } return(RedirectToAction("Index")); } } return(View(data)); }
public IActionResult Index([FromQuery] SearchCategoriesAblums dto) { int TotalItems = 0; string ControllerName = this.ControllerContext.RouteData.Values["controller"].ToString(); CategoriesAblumsModel data = new CategoriesAblumsModel() { SearchData = dto }; data.ListItems = CategoriesAblumsService.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)); }
//add a comment //second comment public IActionResult Index([FromQuery] SearchCategoriesAblums dto) { int TotalItems = 0; string ControllerName = this.ControllerContext.RouteData.Values["controller"].ToString(); CategoriesAblumsModel data = new CategoriesAblumsModel() { SearchData = dto }; data.ListItemsAlbums = AblumsService.GetListPagination(new SearchAblums()); List <CategoriesAblums> ListCatAblum = new List <CategoriesAblums>(); ListCatAblum = CategoriesAblumsService.GetList(); for (int i = 0; i < ListCatAblum.Count(); i++) { List <Ablums> tmp = new List <Ablums>(); for (int j = 0; j < data.ListItemsAlbums.Count(); j++) { if (ListCatAblum[i].Id == data.ListItemsAlbums[j].CatId) { tmp.Add(data.ListItemsAlbums[j]); } } ListCatAblum[i].ListItemsAblums = tmp; } data.ListItems = ListCatAblum; 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 SaveItem(string Id = null) { CategoriesAblumsModel data = new CategoriesAblumsModel(); string ControllerName = this.ControllerContext.RouteData.Values["controller"].ToString(); int IdDC = Int32.Parse(MyModels.Decode(Id, API.Models.Settings.SecretId + ControllerName).ToString()); data.SearchData = new SearchCategoriesAblums() { CurrentPage = 0, ItemsPerPage = 10, Keyword = "" }; data.ListItemsParents = CategoriesAblumsService.GetListItems(); if (IdDC == 0) { data.Item = new CategoriesAblums(); } else { data.Item = CategoriesAblumsService.GetItem(IdDC, API.Models.Settings.SecretId + ControllerName); data.ListItemsAlbums = AblumsService.GetList(IdDC, API.Models.Settings.SecretId + ControllerName); } return(View(data)); }
public async Task <IActionResult> UPloadFiles() { var form = Request.Form; CategoriesAblums model = new CategoriesAblums() { Id = Convert.ToInt32(form["id"]), Ids = form["ids"], Status = Convert.ToBoolean(form["status"]), Description = form["desc"], Title = form["ten"], Images = form["Images"], Alias = form["Alias"], Featured = Boolean.Parse(form["Featured"]), ParentId = int.Parse(form["ParentId"]), }; //ICollection<string> col = form.Keys; var datafiles = JsonConvert.DeserializeObject <List <Ablums> >(form["data"]); string ControllerName = this.ControllerContext.RouteData.Values["controller"].ToString(); int IdDC = Int32.Parse(MyModels.Decode(model.Ids, API.Models.Settings.SecretId + ControllerName).ToString()); //CategoriesAblumsModel data = new CategoriesAblumsModel() { Item = model }; if (ModelState.IsValid) { if (model.Id == IdDC) { model.CreatedBy = int.Parse(HttpContext.Request.Headers["Id"]); model.ModifiedBy = int.Parse(HttpContext.Request.Headers["Id"]); var Cat = CategoriesAblumsService.SaveItem(model); foreach (IFormFile source in form.Files) { string filename = ContentDispositionHeaderValue.Parse(source.ContentDisposition).FileName.Trim('"'); filename = this.EnsureCorrectFilename(filename); using (FileStream output = System.IO.File.Create(this.GetPathAndFilename(filename))) { await source.CopyToAsync(output); Ablums alb = new Ablums(); alb.CatId = Convert.ToInt32(Cat.N); alb.CreatedBy = model.CreatedBy; alb.ModifiedBy = model.ModifiedBy; alb.Images = filename; AblumsService.SaveItem(alb); } } if (datafiles != null) { for (var i = 0; i != datafiles.Count(); i++) { var item = datafiles[i]; if (item.Deleted == true) { var fullPath = GetPathAndFilename(item.Images.ToString()); if (System.IO.File.Exists(fullPath)) { System.IO.File.Delete(fullPath); } Ablums alb = new Ablums() { Id = Convert.ToInt32(item.Id), ModifiedBy = model.ModifiedBy }; AblumsService.DeleteItem(alb); } } } TempData["MessageSuccess"] = "Cập nhật thành công"; return(RedirectToAction("Index")); } } return(Json("asdfsd")); }