Example #1
0
        public async Task <Guid> Handle(EditQuestionCommand request, CancellationToken cancellationToken)
        {
            var employerId = _currentUserService.GetCurrentUserId();
            var question   = await _store.Questions.Where(x => x.EmployerId == employerId).WithIdAsync(request.Id);

            var questionOptions = await _store.Options.Where(x => x.QuestionId == question.Id).ToListAsync();

            await _store.DeleteEntitiesAsync(questionOptions);

            question.Text        = request.Text;
            question.QuestionTag = request.QuestionTag;

            var options = _mapper.Map <List <Option> >(request.Options);

            foreach (var option in options)
            {
                option.QuestionId = question.Id;
            }

            await _store.AddEntitiesAsync(options);

            await _store.SaveChangesAsync();

            return(request.Id);
        }