public async Task AddToCategoryAsync(CategoryTopicModel categoryTopicModel) { var jsonData = JsonConvert.SerializeObject(categoryTopicModel); var content = new StringContent(jsonData, Encoding.UTF8, "application/json"); await _httpClient.PostAsync("AddToCategory", content); }
public IActionResult Topic(int id) { var category = _categoryImplementation.GetById(id); var questions = new List <Question>(); questions = _questionImplementation.GetFilteredQuestions(category).ToList(); var questionListings = questions.Select(question => new QuestionListingModel { QuestionId = question.QuestionId, AuthorName = question.User.UserName, QuestionTitle = question.QuestionTitle, QuestionContent = question.QuestionContent, QuestionCreated = question.QuestionCreated.ToString(), AnswerCount = question.Answers.Count(), NumberView = question.NumberViews, Category = BuildCategoryListing(question) }); var model = new CategoryTopicModel { Questions = questionListings, Category = BuildForumListing(category) }; return(View(model)); }
public async Task <IActionResult> AssignCategory(List <AssignCategoryModel> list) { TempData["active"] = "topic"; int id = (int)TempData["topicId"]; foreach (var item in list) { if (item.Exist) { CategoryTopicModel model = new CategoryTopicModel(); model.TopicId = id; model.CategoryId = item.CategoryId; await _topicApiService.AddToCategoryAsync(model); } else { CategoryTopicModel model = new CategoryTopicModel(); model.TopicId = id; model.CategoryId = item.CategoryId; await _topicApiService.RemoveFromCategoryAsync(model); } } return(RedirectToAction("Index")); }
public async Task <CategoryTopicModel> GetCategoryTopicAsync(int categoryId) { var category = await GetCategoryByIdAsync(categoryId); var posts = await postService.GetPostsByCategoryAsync(categoryId); var categoryConcise = mapper .Map <CategoryConciseViewModel>(category); var postListing = mapper .Map <IEnumerable <PostListingViewModel> >(posts); var model = new CategoryTopicModel { Category = categoryConcise, Posts = postListing }; return(model); }
public IActionResult Topic(int id) { var category = _categoryService.GetById(id); var foods = _foodService.GetFoodsByCategoryId(id); var foodListings = foods.Select(food => new FoodListingModel { Id = food.Id, Name = food.Name, InStock = food.InStock, Price = food.Price, ShortDescription = food.ShortDescription, Category = BuildCategoryListing(food) }); var model = new CategoryTopicModel { Category = BuildCategoryListing(category), Foods = foodListings }; return(View(model)); }
public IActionResult Topic(int id, string searchQuery) { var category = _categoryService.GetById(id); var movies = _movieService.GetFilteredMovies(id, searchQuery); var movieListings = movies.Select(movie => new MovieListingModel { Id = movie.Id, Name = movie.Name, InStock = movie.InStock, Price = movie.Price, ShortDescription = movie.ShortDescription, Category = _mapper.MovieToCategoryListing(movie), ImageUrl = movie.ImageUrl }); var model = new CategoryTopicModel { Category = _mapper.CategoryToCategoryListing(category), Movies = movieListings }; return(View(model)); }
public IActionResult Topic(int id, string searchQuery) { var category = _categoryService.GetById(id); var foods = _foodService.GetFilteredFoods(id, searchQuery); var foodListings = foods.Select(food => new FoodListingModel { Id = food.Id, Name = food.Name, InStock = food.InStock, Price = food.Price, ShortDescription = food.ShortDescription, Category = _mapper.FoodToCategoryListing(food), ImageUrl = food.ImageUrl }); var model = new CategoryTopicModel { Category = _mapper.CategoryToCategoryListing(category), Foods = foodListings }; return(View(model)); }
public async Task RemoveFromCategoryAsync(CategoryTopicModel model) { await _httpClient.DeleteAsync($"RemoveFromCategory?" + $"{nameof(CategoryTopicModel.CategoryId)}={model.CategoryId}" + $"&{nameof(CategoryTopicModel.TopicId)}={model.TopicId}"); }