public async Task <IActionResult> Post([FromBody] CategoryRequest categoryRequest) { Category category = ConvertFromDTO.FromCreateRequest(categoryRequest); _categoryRepository.Create(category); await _context.SaveChangesAsync(); return(CreatedAtAction(nameof(Get), new { id = category.Id }, ConvertToDTO.ToCreateResponse(category))); }
public IActionResult Get(int id) { Comment comment = _commentRepository.Find(id); if (comment != null) { return(Ok(ConvertToDTO.ToGetResponse(comment))); } else { return(NotFound()); } }
public IActionResult Get(int id) { Category cat = _categoryRepository.Find(id); if (cat != null) { return(Ok(ConvertToDTO.ToGetResponse(cat))); } else { return(NotFound()); } }
public IActionResult Get(int id) { Thread thread = _threadRepository.Find(id); if (thread != null) { return(Ok(ConvertToDTO.ToGetResponse(thread))); } else { return(NotFound()); } }
public async Task <IActionResult> Create([FromBody] CreateThreadRequest threadRequest) { int id = int.Parse(HttpContext.User.Claims.FirstOrDefault(claim => claim.Type == "Id").Value); if (_categoryRepository.Find(threadRequest.CategoryId) != null) { Thread thread = ConvertFromDTO.FromCreateRequest(threadRequest); thread.UserId = id; _threadRepository.Create(thread); await _context.SaveChangesAsync(); return(CreatedAtAction(nameof(Get), new { id = thread.Id }, ConvertToDTO.ToCreateResponse(thread))); } else { return(NotFound()); } }
public async Task <IActionResult> GetByThread(int threadId) { return(Ok(ConvertToDTO.ToGetResponse(await _commentRepository.GetByThread(threadId)))); }
public async Task <IActionResult> GetByUser(int userId) { return(Ok(ConvertToDTO.ToGetResponse(await _commentRepository.GetByUser(userId)))); }
public async Task <IActionResult> Create([FromBody] CreateCommentRequest commentRequest) { int id = int.Parse(HttpContext.User.Claims.FirstOrDefault(claim => claim.Type == "Id").Value); if (_threadRepository.Find(commentRequest.ThreadId) != null) { Comment comment = ConvertFromDTO.FromCreateRequest(commentRequest); comment.UserId = id; _commentRepository.Create(comment); await _context.SaveChangesAsync(); return(CreatedAtAction(nameof(GetByThread), new { threadId = comment.ThreadId }, ConvertToDTO.ToCreateResponse(comment))); } else { return(NotFound()); } }
public async Task <ActionResult <IEnumerable <TodoItemDTO> > > GetTodoItems() { return(await _context.TodoItems .Select(i => ConvertToDTO.TodoItemDTO(i)) .ToListAsync()); }
public async Task <IActionResult> GetAll() { return(Ok(ConvertToDTO.ToGetResponse(await _categoryRepository.GetAll()))); }
public async Task <IActionResult> GetByCategory(int categoryId) { return(Ok(ConvertToDTO.ToGetResponse(await _threadRepository.GetByCategory(categoryId)))); }