Ejemplo n.º 1
0
        public async Task <Question> UpdateQuestionAsync(int loggedUser, UpdateQuestionRequest question)
        {
            // not found poll?
            var pd = await _uow.QuestionRepository.GetAll().Where(p => p.Id == question.Id)
                     .Include(q => q.Answers)
                     .FirstOrDefaultAsync();

            if (pd == null)
            {
                throw new NotFoundException(ExceptionConstants.NOT_FOUND, "Question");
            }

            // validate admin user
            var user = await _uow.UserRepository.FindByAsync(u => u.Id == loggedUser && u.Role == RoleEnum.ADMIN);

            if (user.Count == 0)
            {
                throw new NotAllowedException(ExceptionConstants.NOT_ALLOWED);
            }

            pd.ModifiedAt = DateTime.UtcNow;
            pd.Order      = question.Order;
            pd.Title      = question.Title;

            _uow.QuestionRepository.Update(pd);
            await _uow.CommitAsync();

            return(pd);
        }
 public async Task Update(int id, [FromBody] QuestionDto question)
 {
     question.Id = id;
     var request = new UpdateQuestionRequest
     {
         Question = question
     };
     await _mediator.ExecuteAsync(request).ConfigureAwait(false);
 }
Ejemplo n.º 3
0
        public async Task <IActionResult> Update([FromBody] UpdateQuestionRequest question)
        {
            var loggedUser = User.GetUserIdFromToken();
            var result     = await _questionService.UpdateQuestionAsync(loggedUser, question);

            var mapped = _mapper.Map <QuestionResponse>(result);

            return(Ok(new ApiOkResponse(mapped)));
        }
Ejemplo n.º 4
0
        public Question Put(int id, [FromBody] UpdateQuestionRequest question)
        {
            var existingQuestion = _questionsRepository.Get(id);

            existingQuestion.Text = question.Text ?? existingQuestion.Text;

            _questionsRepository.Update(existingQuestion);

            return(existingQuestion);
        }
        public Task UpdateAsync(UpdateQuestionRequest request)
        {
            return(transactionService.CommitAsync(new[] { TransactionContextScope.Main }, async() =>
            {
                await questionsRepository.SoftDeleteAsync(request.QuestionId);

                var question = mapper.Map <Question>(request);
                await AddAsync(question, request.Answers);
                await examinationsService.UpdateModificationTimeAsync(question.ExaminationId);
            }));
        }
Ejemplo n.º 6
0
        public IHttpActionResult UpdateQuestion(UpdateQuestionRequest request)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                var response = RequestServiceFactory.Instance.Resolve <UpdateQuestionService>().ProcessRequest(request);
                return(Ok(response));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
Ejemplo n.º 7
0
 public async Task UpdateQuestion([FromBody] UpdateQuestionRequest request)
 => await questionsService.UpdateAsync(request);