示例#1
0
        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)));
        }
示例#2
0
        public IActionResult Get(int id)
        {
            Comment comment = _commentRepository.Find(id);

            if (comment != null)
            {
                return(Ok(ConvertToDTO.ToGetResponse(comment)));
            }
            else
            {
                return(NotFound());
            }
        }
示例#3
0
        public IActionResult Get(int id)
        {
            Category cat = _categoryRepository.Find(id);

            if (cat != null)
            {
                return(Ok(ConvertToDTO.ToGetResponse(cat)));
            }
            else
            {
                return(NotFound());
            }
        }
示例#4
0
        public IActionResult Get(int id)
        {
            Thread thread = _threadRepository.Find(id);

            if (thread != null)
            {
                return(Ok(ConvertToDTO.ToGetResponse(thread)));
            }
            else
            {
                return(NotFound());
            }
        }
示例#5
0
        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());
            }
        }
示例#6
0
 public async Task <IActionResult> GetByThread(int threadId)
 {
     return(Ok(ConvertToDTO.ToGetResponse(await _commentRepository.GetByThread(threadId))));
 }
示例#7
0
 public async Task <IActionResult> GetByUser(int userId)
 {
     return(Ok(ConvertToDTO.ToGetResponse(await _commentRepository.GetByUser(userId))));
 }
示例#8
0
        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());
            }
        }
示例#9
0
 public async Task <ActionResult <IEnumerable <TodoItemDTO> > > GetTodoItems()
 {
     return(await _context.TodoItems
            .Select(i => ConvertToDTO.TodoItemDTO(i))
            .ToListAsync());
 }
示例#10
0
 public async Task <IActionResult> GetAll()
 {
     return(Ok(ConvertToDTO.ToGetResponse(await _categoryRepository.GetAll())));
 }
示例#11
0
 public async Task <IActionResult> GetByCategory(int categoryId)
 {
     return(Ok(ConvertToDTO.ToGetResponse(await _threadRepository.GetByCategory(categoryId))));
 }