public Task <GenericQueryResult> Handle(GetQuestionsFormRequest request, CancellationToken cancellationToken)
        {
            try
            {
                var questions = _questionRepository.Get(request.FormId);
                var form      = _formRepository.Get(request.FormId);

                var result = new
                {
                    FormTitle = form.Title,
                    FormId    = form.Id,
                    Questions = questions.Select(
                        q => new GetQuestionsFormResponse()
                    {
                        QuestionId = q.Id,
                        Text       = q.Text
                    }
                        )
                                .OrderBy(q => q.Text)
                };

                return(Task.FromResult(new GenericQueryResult(200, null, result)));
            }
            catch
            {
                return(Task.FromResult(new GenericQueryResult(500, "Erro no servidor! Desculpe-nos.", null)));
            }
        }
Пример #2
0
        public Form GetForm(string name)
        {
            name = name.ToLower();
            var form = formRepository.Get(f => f.FormName.ToLower() == name, "FormFields");

            return(form);
        }
Пример #3
0
        public IEnumerable <Form> GetFormByID(int id, string lang = "", string active = "")
        {
            //Form form = databasePlaceholder.Get(id, lang, active);
            IEnumerable <Form> formList = databasePlaceholder.Get(id, lang, active);

            if (formList.Count() == 0)
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }
            return(formList);
        }
Пример #4
0
        public Task <GenericQueryResult> Handle(GetAnswersFormRequest request, CancellationToken cancellationToken)
        {
            try
            {
                var questionsAndAnswers = new List <GetAnswersFormResponse>();

                var form = _formRepository.Get(request.FormId);

                if (!form.Answered)
                {
                    return(Task.FromResult(new GenericQueryResult(404, "Este formulário ainda não foi respondido! Que tal ser o primeiro?", null)));
                }

                var questions = _questionRepository.Get(form.Id);

                foreach (var question in questions)
                {
                    var answers = _answerRepository.Get(question.Id);

                    questionsAndAnswers.Add(new GetAnswersFormResponse()
                    {
                        QuestionText = question.Text,
                        Answers      = answers.Select(
                            a => new AnswerResponse()
                        {
                            AnswerText = a.Text,
                            AnsweredAt = a.CreatedAt.ToString("dd/MM/yyyy"),
                            Latitude   = a.Latitude,
                            Longitude  = a.Longitude,
                            AuthorName = _authorRepository.Get(a.AuthorId).Name
                        }
                            ).OrderBy(a => a.AnsweredAt).ToList()
                    });
                }

                var result = new
                {
                    FormTitle           = form.Title,
                    AuthorName          = _authorRepository.Get(form.AuthorId).Name,
                    QuestionsAndAnswers = questionsAndAnswers.OrderBy(qa => qa.QuestionText)
                };

                return(Task.FromResult(new GenericQueryResult(200, null, result)));
            }
            catch
            {
                return(Task.FromResult(new GenericQueryResult(500, "Erro no servidor! Desculpe-nos.", null)));
            }
        }
Пример #5
0
        public Task <GenericCommandResult> Handle(AnswerQuestionsFormRequest request, CancellationToken cancellationToken)
        {
            try
            {
                var author = new Author(request.AuthorName);

                _authorRepository.Create(author);

                foreach (var answer in request.Answers)
                {
                    _answerRepository.Create(
                        new Answer(
                            answer.Text,
                            answer.QuestionId,
                            author.Id,
                            answer.Latitude,
                            answer.Longitude
                            )
                        );
                }

                var form = _formRepository.Get(request.FormId);

                if (!form.Answered)
                {
                    form.TurnAnswered();

                    _formRepository.Update(form);
                }

                return(Task.FromResult(new GenericCommandResult(200, "Respostas ao formulário registrada com sucesso!", null)));
            }
            catch
            {
                return(Task.FromResult(new GenericCommandResult(500, "Erro no servidor! Desculpe-nos.", null)));
            }
        }
Пример #6
0
        public async Task InvokeAsync(HttpContext context)
        {
            Trace.WriteLine($"{context.Request.Method} {context.Request.Path}");

            if (!options.Path.HasValue || context.Request.Path.StartsWithSegments(options.Path))
            {
                if (context.Request.Method == "GET")
                {
                    Form form = formRepository.Get(context.Request.Path);

                    if (form != null)
                    {
                        form.Accept(visitor);

                        string html = visitor.Output;

                        context.Response.StatusCode  = (int)HttpStatusCode.OK;
                        context.Response.ContentType = "text/html";

                        await context.Response.WriteAsync(html);
                    }
                }
                else
                if (context.Request.Method == "POST")
                {
                    if (context.Request.HasFormContentType)
                    {
                        IFormCollection form = await context.Request.ReadFormAsync(); // async

                        string param1 = form["param1"];
                        string param2 = form["param2"];
                    }
                }
            }

            await next(context);
        }
Пример #7
0
 public ResultMessage <Form> Get(Expression <Func <Form, bool> > filter)
 {
     return(_formRepository.Get(filter));
 }