示例#1
0
        public async Task <IActionResult> Create(UserRequest.Shared.Topic model)
        {
            ClaimsPrincipal currentUser     = User;
            string          currentUserName = currentUser.FindFirst(ClaimTypes.NameIdentifier).Value;
            ApplicationUser user            = await _userManager.FindByIdAsync(currentUserName);


            Topic topicToCreate = new Topic
            {
                Text    = model.Text,
                Title   = model.Title,
                Created = DateTime.UtcNow,
                Author  = user
            };

            topicToCreate.Votes = new List <TopicVote> {
                new TopicVote
                {
                    Topic = topicToCreate,
                    User  = user
                }
            };

            applicationDbContext.Topics.Add(topicToCreate);
            applicationDbContext.SaveChanges();

            Shared.Topic res = await GetTopic(topicToCreate.Id);

            return(Ok(res));
        }
示例#2
0
        public async Task <IActionResult> CommentTopic(int topicId, string newComment)
        {
            ClaimsPrincipal currentUser     = User;
            string          currentUserName = currentUser.FindFirst(ClaimTypes.NameIdentifier).Value;
            ApplicationUser user            = await _userManager.FindByIdAsync(currentUserName);

            applicationDbContext.TopicComments.Add(new TopicComment
            {
                Author  = user,
                TopicId = topicId,
                Comment = newComment,
                Created = DateTime.UtcNow
            });
            applicationDbContext.SaveChanges();

            Shared.Topic model = await GetTopic(topicId);

            return(Ok(model));
        }
示例#3
0
        public async Task <IActionResult> GetDetails(int topicId)
        {
            Shared.Topic model = await GetTopic(topicId);

            return(Ok(model));
        }