Esempio n. 1
0
        public async Task <IActionResult> Answer(CreateTopicAnswerModel model)
        {
            var userId = User.FindFirstValue(ClaimTypes.NameIdentifier);

            var topic = _groupsService.GetTopic(model.TopicId);

            if (topic == null)
            {
                return(BadRequest());
            }

            if (!ModelState.IsValid || !_groupsService.IsMember(topic.GroupId, userId))
            {
                return(BadRequest());
            }

            var answer = _groupsService.CreateAnswer(userId, model.TopicId, model.Content);

            //_groupsService.UpdateLastVisitedTopic(userId, topic.Id);

            await _groupsHubContext.Clients.Group(topic.GroupId.ToString()).SendAsync("AnswerCreated", topic.GroupId, topic.Id, answer.Id, userId);

            return(Ok());
        }