Esempio n. 1
0
        public static HttpResponseMessage GetParticipants([HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "participant/{surveyId:int=10}")] HttpRequestMessage req, int surveyId, TraceWriter log)
        {
            log.Info("C# HTTP Get Participants trigger function processed a request.");
            var participantService = new ParticipantService();

            try
            {
                return(JsonHelpers.CreateResponse(participantService.GetAllParticipants(surveyId)));
            }
            catch (Exception e)
            {
                log.Error(e.Message);
                return(JsonHelpers.CreateResponse(e, HttpStatusCode.InternalServerError));
            }
        }
Esempio n. 2
0
        public static async Task <HttpResponseMessage> GetQuestions([HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "questions/list")] HttpRequestMessage req, TraceWriter log)
        {
            log.Info("C# HTTP Get Questions trigger function processed a request.");

            try
            {
                var questionRequest = await req.Content.ReadAsAsync <QuestionRequestDTO>();

                var questionService = new QuestionService();
                return(JsonHelpers.CreateResponse(questionService.GetQuestions(questionRequest.Number, questionRequest.Categories)));
            }
            catch (Exception e)
            {
                log.Error(e.Message);
                return(JsonHelpers.CreateResponse(e, HttpStatusCode.InternalServerError));
            }
        }
Esempio n. 3
0
        public static async Task <HttpResponseMessage> AddParticipant([HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "participant")] HttpRequestMessage req, TraceWriter log, ExecutionContext context)
        {
            log.Info("C# HTTP Add Participant trigger function processed a request.");
            var participantService = new ParticipantService();

            try
            {
                var newTestResult = await req.Content.ReadAsAsync <TestDTO>();

                var result = await participantService.InsertNewTestResults(newTestResult);

                try
                {
                    if (result.CorrectAnswers >= AppSettings.CorrectAnswersForMail)
                    {
                        var mailHelper = new MailHelper(log, context.FunctionAppDirectory);
                        mailHelper.SendMail(newTestResult.Participant.Email.Trim(), newTestResult.Participant.Name);
                    }
                }
                catch (Exception e)
                {
                    log.Error(e.Message);
                }

                return(JsonHelpers.CreateResponse(result));
            }
            catch (ParticipantAlreadyPlayedException pe)
            {
                return(JsonHelpers.CreateResponse(pe, HttpStatusCode.BadRequest));
            }
            catch (Exception e)
            {
                log.Error(e.Message);
                return(JsonHelpers.CreateResponse(e, HttpStatusCode.InternalServerError));
            }
        }