public async Task <IActionResult> AssignCategory(int id, [FromServices] ICategoryApiService categoryApiService) { TempData["active"] = "blog"; var categories = await categoryApiService.GetAllAsync(); var blogCategories = await _blogApiService.GetCategories(id); TempData["blogId"] = id; List <AssignCategoryModel> list = new List <AssignCategoryModel>(); foreach (var category in categories) { AssignCategoryModel model = new AssignCategoryModel(); model.CategoryId = category.Id; model.CategoryName = category.Name; model.Exists = blogCategories.Contains(category); list.Add(model); } return(View(list)); }
public async Task <IActionResult> AssignCategory(int id) { TempData["Active"] = ActivePage.Blog; Response.Cookies.Append( CookieRequestCultureProvider.DefaultCookieName, CookieRequestCultureProvider.MakeCookieValue(new RequestCulture("en-US")), new CookieOptions { Expires = DateTimeOffset.Now.AddDays(10) } ); var categories = await _categoryService.GetAllAsync(); var blogCategories = await _blogService.GetCategoriesAsync(id); TempData["blogId"] = id; var list = new List <AssignCategoryModel>(); foreach (var category in categories) { var model = new AssignCategoryModel { CategoryId = category.Id, CategoryName = category.Name }; foreach (var blogCategory in blogCategories) { if (category.Id == blogCategory.Id) { model.Exists = true; } } list.Add(model); } return(View(list)); }
public async Task <IActionResult> AssignCategory(int id, [FromServices] ICategoryApiService categoryApiService) { TempData["active"] = "blog"; var categories = await categoryApiService.GetAllCategoriesAsync(); var blogCategory = (await _blogApiService.GetAllCategories(id)).Select(i => i.Name).ToList(); TempData["blogid"] = id; List <AssignCategoryModel> models = new List <AssignCategoryModel>(); foreach (var category in categories) { AssignCategoryModel model2 = new AssignCategoryModel(); model2.CategoryId = category.Id; model2.CategoryName = category.Name; model2.Exits = blogCategory.Contains(category.Name); models.Add(model2); } return(View(models)); }
public ActionResult AssignCategory(int id) { if (id <= 0) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } AssignCategoryModel model = new AssignCategoryModel(); try { model.Id = id; model.Categories = CommonHelpers.GetListCategory(); } catch (Exception ex) { var strError = string.Format("Failed when trying load AssignCategory: {0}", ex.ToString()); logger.Error(strError); } return(PartialView("../Post/_AssignCategory", model)); }
public async Task <IActionResult> AssignCategory(int id, [FromServices] ICategoryApiService categoryApiService) { TempData["active"] = "topic"; var categories = await categoryApiService.GetAllAsync(); var topicCategories = (await _topicApiService.GetCategoriesAsync(id)); TempData["topicId"] = id; List <AssignCategoryModel> list = new List <AssignCategoryModel>(); foreach (var item in categories) { AssignCategoryModel model = new AssignCategoryModel(); model.CategoryId = item.Id; model.CategoryName = item.Name; model.Exist = topicCategories.Contains(item); list.Add(model); } return(View(list)); }