public async Task <ServiceResponse <GetPostDto> > AddPostCategory(AddPostCategoryDto newPostCategory) { ServiceResponse <GetPostDto> response = new ServiceResponse <GetPostDto>(); try { Post post = await _context.Posts .FirstOrDefaultAsync(c => c.PostId == newPostCategory.PostId); if (post == null) { response.Success = false; response.Message = "Post not found."; return(response); } Category category = await _context.Categories .FirstOrDefaultAsync(s => s.CategoryId == newPostCategory.CategoryId); if (category == null) { response.Success = false; response.Message = "Category not found."; return(response); } PostCategories postCategory = new PostCategories { Post = post, Category = category }; await _context.PostCategories.AddAsync(postCategory); await _context.SaveChangesAsync(); response.Data = _mapper.Map <GetPostDto>(post); } catch (Exception ex) { response.Success = false; response.Message = ex.Message; } return(response); }
public Task <ServiceResponse <GetPostDto> > AddCategoryToAPost(AddPostCategoryDto newPostCategory) { throw new NotImplementedException(); }