Пример #1
0
        /// <summary>
        /// Updates question element with provided dto.
        /// </summary>
        /// <param name="customerId">The customer identifier.</param>
        /// <param name="questionElementId">The question element identifier.</param>
        /// <param name="dto">The dto.</param>
        /// <returns></returns>
        public async Task <ServiceActionResult <QuestionElementActionStatus, QuestionElementResponseDto> > Update(
            int customerId,
            Guid questionElementId,
            UpdateQuestionElementRequestDto dto
            )
        {
            var entity = Mapper.Map <QuestionElement>(dto);

            entity.LocalizedStrings.Add(await MapAnswerString(dto.QuestionElementString));

            entity.Tags = await this.tagsService.BuildTagsList(customerId, dto.Tags);

            if (dto.AnswerChoiceIds != null)
            {
                MapAnswerChoiceIds(entity, dto.AnswerChoiceIds);
            }

            var result = await this.questionElementService.Update(customerId, questionElementId, entity);

            if (result.Status != QuestionElementActionStatus.Success)
            {
                return(result.Clone <QuestionElementResponseDto>());
            }

            await globalSearchCacheHelper.AddOrUpdateEntry(customerId, Mapper.Map <QuestionElement, SearchEntryDto>(result.Content));

            await tagsSearchCacheHelper.AddOrUpdateTags(customerId, result.Content.Tags.Select(t => t.Name).ToList());

            var unusedTags = await tagsService.RemoveUnusedTags(customerId);

            await tagsSearchCacheHelper.RemoveTags(customerId, unusedTags);

            return(result.CloneWithMapping(new QuestionElementResponseDto()));
        }
Пример #2
0
        public async Task <IHttpActionResult> UpdateQuestionElement(
            int customerId,
            Guid questionElementId,
            UpdateQuestionElementRequestDto model
            )
        {
            var result = await questionElementHelper.Update(customerId, questionElementId, model);

            switch (result.Status)
            {
            case QuestionElementActionStatus.NotFound:
                return(NotFound(GlobalStrings.QuestionElement_NotFoundError));

            case QuestionElementActionStatus.AnswerSetNotExists:
                return(BadRequest(GlobalStrings.AnswerSet_NotFoundError));

            case QuestionElementActionStatus.AnswerSetCannotBeUsed:
                return(BadRequest(GlobalStrings.QuestionElement_AnswerSetCannotBeUsedError));

            case QuestionElementActionStatus.AnswerChoiceCannotBeUsed:
                return(BadRequest(GlobalStrings.QuestionElement_AnswerChoiceCannotBeUsedError));

            case QuestionElementActionStatus.InvalidScaleValueRange:
                return(BadRequest(GlobalStrings.QuestionElement_InvalidScaleRange));

            default:
                return(StatusCode(HttpStatusCode.NoContent));
            }
        }
        /// <summary>
        /// Updates data of existed question element.
        /// </summary>
        /// <param name="updateQuestionElementDto"></param>
        /// <param name="customerId"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        public async Task UpdateQuestionElement(UpdateQuestionElementRequestDto updateQuestionElementDto, int customerId,
                                                string token)
        {
            updateQuestionElementDto.AnswerChoiceIds =
                updateQuestionElementDto.AnswerChoiceIds.Where(a => !a.IsEmpty()).ToList();

            await this.healthLibraryDataProvider.UpdateQuestionElement(updateQuestionElementDto, customerId, token);
        }
Пример #4
0
        public async Task UpdateQuestionElement(UpdateQuestionElementRequestDto updateQuestionElementDto, int customerId, string token)
        {
            var url = string.Format("/api/{0}/question-elements/{1}", customerId, updateQuestionElementDto.Id);

            await this.apiClient.SendRequestAsync(url, updateQuestionElementDto, Method.PUT, null, token);
        }