Exemplo n.º 1
0
        public GetQuestionsResponse GetQuestions(GetQuestionsRequest request)
        {
            GetQuestionsResponse response = new GetQuestionsResponse();

            AuthToken authToken = null;

            try
            {
                Common.Helpers.ValidationHelper.ValidateRequiredField(request.AuthToken, "Auth Token");

                if (!UserController.ValidateSession(request.AuthToken, out authToken))
                {
                    throw new AuthenticationException("Authentication failed.");
                }

                DbContext context = DataController.CreateDbContext();

                IQueryable <E::Question> questions = context.Questions;

                if (!string.IsNullOrEmpty(request.Name))
                {
                    questions = questions.Where(q => q.Name.Contains(request.Name));
                }

                response.TotalCount = questions.Count();

                questions = questions.OrderByDescending(a => a.CreatedDate)
                            .Skip(request.StartAt)
                            .Take(InitialRound.Web.Properties.Settings.Default.PageSize);

                response.Results = questions.AsEnumerable().Select(a => new GetQuestionsResponseItem
                {
                    ID              = a.ID,
                    Name            = a.Name,
                    LastUpdatedBy   = a.LastUpdatedBy,
                    LastUpdatedDate = a.LastUpdatedDate.ToShortDateString(),
                    CreatedBy       = a.CreatedBy,
                    CreatedDate     = a.CreatedDate.ToShortDateString()
                }).ToArray();
            }
            catch (AuthenticationException ex)
            {
                throw new WebFaultException <string>(ex.Message, System.Net.HttpStatusCode.BadRequest);
            }
            catch (Common.Exceptions.ValidationException ex)
            {
                throw new WebFaultException <string>(ex.Message, System.Net.HttpStatusCode.BadRequest);
            }
            catch (Exception ex)
            {
                ExceptionHelper.Log(ex, authToken == null ? null : authToken.Username);
                throw new WebFaultException <string>("An unknown error has occurred.", System.Net.HttpStatusCode.InternalServerError);
            }

            return(response);
        }
Exemplo n.º 2
0
        public async Task <PagedResult <Question> > GetQuestions(GetQuestionsRequest request,
                                                                 CancellationToken cancellationToken = default)
        {
            var questionsQueryResult = await _questionsRepository.GetQuestions(new GetQuestionsQuery
            {
                QuestionnaireId = request.QuestionnaireId,
                Locale          = request.Locale,
                Limit           = request.Limit,
                Offset          = request.Offset
            }, cancellationToken);

            return(questionsQueryResult.ToPagedResult());
        }