public ActionResult AddAnswer(AnswerCreate model) { if (ModelState.IsValid) { var service = new AnswerService(User.Identity.GetUserId()); if (service.CreateAnswer(model)) { return(RedirectToAction(nameof(Index))); } } return(View(model)); }
public bool CreateAnswer(AnswerCreate model) { var entity = new Answer { Text = model.Text, QuestiondId = model.QuestionId, IsCorrectSpelling = model.IsCorrectSpelling, IsUserGenerated = !_userService.ConfirmUserIsAdmin(_userId.ToString()), AuthorId = _userId }; _context.Answers.Add(entity); return(_context.SaveChanges() == 1); }
public ActionResult AddAnswer(int id) { var service = CreateQuestionService(); ViewBag.Detail = service.GetQuestionById(id); var qmodel = service.GetQuestionById(id); var model = new AnswerCreate { QuestionId = id, Question = qmodel.Text }; return(View(model)); }
public async Task <Answer> PutAnswer(int answerId, [FromBody] AnswerCreate model) { Answer answer = await _context.Answers .Where(x => x.User.Id == GetUserId()) .Where(x => x.Id == answerId) .SingleOrDefaultAsync(); if (answer == null) { throw new UserException("Couldn't find a question with the id where you are the owner.", 404); } answer.Comment = model.Comment; await _context.SaveChangesAsync(); answer.Question = null; answer.User = null; return(answer); }
public async Task <Answer> PostAnswer(int questionId, [FromBody] AnswerCreate model) { Question question = await _context.Questions .Where(x => x.Lecture.Course.Members.Any(y => y.MemberId == GetUserId())) .Where(x => x.Id == questionId) .Include(x => x.User) .ThenInclude(x => x.PushTokens) .SingleOrDefaultAsync(); ILAUser user = await _context.Users.FindAsync(GetUserId()); if (question == null || user == null) { throw new UserException(404); } Answer answer = new Answer { Question = question, User = user, Comment = model.Comment, }; await _context.Answers.AddAsync(answer); await _context.SaveChangesAsync(); _fireBaseService.SendPushNotificationMessageToSingleUser(question.User, "New Answer", "Someone answerd your question", new Dictionary <string, string> { { "questionId", question.Id.ToString() }, { "answerId", answer.Id.ToString() } }); question.User = null; question.Lecture = null; return(answer); }