public async Task <IActionResult> AssignCategory(List <AssignCategoryModel> list) { TempData["active"] = "blog"; int id = (int)TempData["blogId"]; foreach (var item in list) { if (item.Exists) { CategoryBlogModel model = new CategoryBlogModel(); model.BlogId = id; model.CategoryId = item.CategoryId; await _blogApiService.AddToCategoryAsync(model); } else { CategoryBlogModel model = new CategoryBlogModel(); model.BlogId = id; model.CategoryId = item.CategoryId; await _blogApiService.RemoveFromCategoryAsync(model); } } return(RedirectToAction("Index")); }
public async Task AddToCategoryAsync(CategoryBlogModel model) { var jsonData = JsonConvert.SerializeObject(model); var content = new StringContent(jsonData, Encoding.UTF8, "application/json"); var response = await _httpClient.PostAsync("AddToCategory", content); }
public IActionResult Update(string id, CategoryBlogModel catModel) { if (ModelState.IsValid) { var updateCat = _categoryBlogService.Update(id, base.UserId, catModel); } return(Ok()); }
public IActionResult Create(CategoryBlogModel catModel) { if (ModelState.IsValid) { var newCat = _categoryBlogService.Insert(base.UserId, catModel); } return(Ok()); }
public CategoryBlogModel Insert(string userCurrentId, CategoryBlogModel category) { try { var newCat = _mapper.Map <CategoryBlog>(category); newCat.CreatedBy = userCurrentId; newCat.Slug = StringHelper.ToUrlFriendly(newCat.Name); _categoryBlogRepo.Insert(newCat); return(category); } catch { throw; } }
public CategoryBlogModel Update(string catId, string userCurrentId, CategoryBlogModel category) { try { var updateCat = _categoryBlogRepo.GetById(catId); _mapper.Map(category, updateCat); updateCat.LastUpdatedBy = userCurrentId; _categoryBlogRepo.Update(updateCat); return(category); } catch { throw; } }
public async Task RemoveFromCategoryAsync(CategoryBlogModel model) { var response = await _httpClient.DeleteAsync($"RemoveFromCategory?{nameof(CategoryBlogModel.CategoryId)}={model.CategoryId}&{nameof(CategoryBlogModel.BlogId)}={model.BlogId}"); }
public async Task RemoveFromCategoryAsync(CategoryBlogModel model) { var jsonData = JsonConvert.SerializeObject(model); var content = new StringContent(jsonData, Encoding.UTF8, "application/json"); await _httpClient.DeleteAsync($"RemoveFromCategory?{nameof(CategoryBlogModel.CategoryId)}={model.CategoryId}&{nameof(CategoryBlogModel.BlogId)}={model.BlogId}"); }