Пример #1
0
        public async Task <IGame> AddAnswer([FromBody] AddAnswerModel model)
        {
            var game = await _gameService.GetGame(model.GameId);

            if (game == null)
            {
                throw new GameDoesNotExistException(model.GameId);
            }

            var participant = game.CurrentRound.Participants.FirstOrDefault(p => p.Player.Id == model.PlayerId);

            if (participant == null)
            {
                throw new PlayerDoesNotExistException(model.PlayerId);
            }

            participant.Answer = model.Word;

            var savedGame = await _gameService.SaveGame(game);

            if (game.CurrentRound.AllAnswered)
            {
                await _gameNotifier.SendAllAnswered(savedGame);
            }
            else
            {
                await _gameNotifier.SendGameUpdated(savedGame);
            }

            return(savedGame);
        }
Пример #2
0
        public IActionResult Answer(int id, AddAnswerModel newAnswer)
        {
            int    userId        = int.Parse(HttpContext.User.FindFirstValue("Id"));
            string imageFileName = newAnswer.Image?.FileName;

            using Stream imageStream = newAnswer.Image?.OpenReadStream();
            string image = imageFileName == null ? null : _storageService.Save(imageFileName, imageStream);

            _answersService.Add(userId, id, newAnswer.Message, image);
            return(RedirectToAction("Details", new { id }));
        }
        //AddAnswer Method uses AddAnswerModel and allows to post answer for the question posted on plant with giving QuestionID.
        public bool AddAnswer(AddAnswerModel model)
        {
            Answers answers = new Answers
            {
                QuestionID  = model.QuestionID,
                Answer      = model.Answer,
                UserID      = _userID,
                CreatedDate = DateTimeOffset.UtcNow
            };

            ctx.Answers.Add(answers);
            return(ctx.SaveChanges() == 1);
        }
        public IHttpActionResult AddAnswer(AddAnswerModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var service = CreateSocialInteractionsService();

            if (!service.AddAnswer(model))
            {
                return(InternalServerError());
            }
            return(Ok("Answer Added"));
        }
Пример #5
0
        public IActionResult Edit(int id, AddAnswerModel newAnswer)
        {
            int    userId        = int.Parse(HttpContext.User.FindFirstValue("Id"));
            string imageFileName = newAnswer.Image?.FileName;

            using Stream imageStream = newAnswer.Image?.OpenReadStream();
            string image = imageFileName == null ? null : _storageService.Save(imageFileName, imageStream);

            try
            {
                _answersService.Update(userId, id, newAnswer.Message, image);
            }
            catch (AskMateNotAuthorizedException)
            {
                return(Forbid());
            }
            return(RedirectToAction("Details", "Questions", new { id = newAnswer.QuestionId }));
        }
Пример #6
0
 public AddNewAnswerCommand(Guid questionId, string email, AddAnswerModel model)
 {
     QuestionId = questionId;
     Email      = email;
     Model      = model;
 }
Пример #7
0
        public IActionResult AddAnswer([FromRoute] Guid questionId, [FromBody] AddAnswerModel model)
        {
            var result = DispatchCommand(new AddNewAnswerCommand(questionId, User.GetUserEmail().Value, model));

            return(result.AsActionResult(() => Created("api/questions/answers", new { questionId })));
        }