コード例 #1
0
        public async Task <IActionResult> OnPost(int questionId)
        {
            var author = await userManager.GetUserAsync(User);

            Answer.Created = DateTime.Now;
            Answer.Edited  = DateTime.Now;

            Answer.QuestionId = questionId;
            Answer.Author     = author;

            context.Answers.Add(Answer);
            context.SaveChanges();

            return(RedirectToPage("../Questions/Details", new { questionId = questionId }));
        }
コード例 #2
0
        public async Task <IActionResult> OnPost()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            Question.Author = await userManager.GetUserAsync(User);

            Question.Created = Question.Edited = DateTime.Now;
            context.Questions.Add(Question);
            context.SaveChanges();

            return(RedirectToPage("./Index"));
        }
コード例 #3
0
        public async Task <IActionResult> OnPost(int questionId)
        {
            Question = context.Questions.FirstOrDefault(q => q.QuestionId == questionId);

            var author = await userManager.GetUserAsync(User);

            if (author.Id != Question.AuthorId)
            {
                return(RedirectToPage("../Shared/ErrorNotAuthorized"));
            }

            context.Questions.Remove(Question);
            context.SaveChanges();

            return(RedirectToPage("./Index"));
        }
コード例 #4
0
        public async Task <IActionResult> OnPost(int questionId)
        {
            Question.Edited = DateTime.Now;

            var author = await userManager.GetUserAsync(User);

            if (author.Id != Question.AuthorId)
            {
                return(RedirectToPage("../Shared/ErrorNotAuthorized"));
            }

            context.Questions.Update(Question);
            context.SaveChanges();

            return(RedirectToPage("./Details", new { questionId = questionId }));
        }
コード例 #5
0
ファイル: Rate.cshtml.cs プロジェクト: douglasstarnes/Quanda
        public async Task <IActionResult> OnPost(int answerId)
        {
            var author = await userManager.GetUserAsync(User);

            var answer         = context.Answers.Include(a => a.Question).FirstOrDefault(a => a.AnswerId == answerId);
            var existingRating = context.Ratings.Where(r => r.Author == author).FirstOrDefault(r => r.QuestionId == answer.QuestionId);

            if (existingRating != null)
            {
                context.Ratings.Remove(existingRating);
            }

            var newRating = new Rating {
                Created  = DateTime.Now,
                Author   = author,
                Answer   = answer,
                Question = answer.Question
            };

            context.Ratings.Add(newRating);
            context.SaveChanges();
            return(RedirectToPage("../Questions/Details", new { questionId = answer.Question.QuestionId }));
        }