Exemple #1
0
        public TopicsSearchResult GetAll(int size, int skip)
        {
            TopicsSearchResult res = new TopicsSearchResult()
            {
                Topics      = _topicRepository.GetAll(size, skip),
                TotalTopics = _topicRepository.Count()
            };

            return(res);
        }
Exemple #2
0
        public async Task <IActionResult> CreateTopic([FromBody] TopicForCreateDto topicForCreateDto)
        {
            var userId = int.Parse(HttpContext.GetUserIdFromToken());

            var count = _repository.Count(t => t.OwnerId == userId || t.OwnerId == null);

            if (count >= Constants.MaxUserTopics)
            {
                return(BadRequest(new { Message = "User already has too much topics" }));
            }

            var topic = _mapper.Map <Topic>(topicForCreateDto);

            topic.OwnerId = userId;

            await _repository.Add(topic);

            await _repository.SaveChangesAsync();

            var topicDto = _mapper.Map <TopicDto>(topic);

            return(CreatedAtAction(nameof(GetTopic), new { id = topic.Id }, topicForCreateDto));
        }