Пример #1
0
        public async Task <int> CreateSurveyAnswerAsync(SurveyAnswerToAdd command)
        {
            var surveyAnswerId = await CreateAsync(command.SurveyTitle, command.Description, command.SurveyId);

            if (command.Questions == null)
            {
                throw new NullReferenceException("Cannot create empty survey");
            }
            foreach (var questionAnswer in command.Questions)
            {
                await AddChoiceOptionsAnswerAndRowAnswerAsync(command.SurveyId, surveyAnswerId, questionAnswer.Select,
                                                              questionAnswer);
            }
            return(surveyAnswerId);
        }
        public async Task <IActionResult> CreateSurveyAnswer(string email, [FromBody] SurveyAnswerToAdd command)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            try {
                var verification = await _surveyUserIdentifierService.VerifySurveyUser(email, command.SurveyId);

                if (verification == "answered")
                {
                    return(BadRequest("you already answered to that survey"));
                }
                if (verification == "unauthorized")
                {
                    return(Unauthorized());
                }
                await _surveyAnswerService.CreateSurveyAnswerAsync(command);

                return(StatusCode(201));
            } catch (Exception e) {
                return(BadRequest(e.Message));
            }
        }