/// <summary> /// Creates new question element. /// </summary> /// <param name="customerId"></param> /// <param name="dto"></param> /// <returns></returns> public async Task <ServiceActionResult <QuestionElementActionStatus, Guid> > Create( int customerId, CreateQuestionElementRequestDto dto ) { var entity = Mapper.Map <QuestionElement>(dto); entity.CustomerId = customerId; entity.LocalizedStrings.Add(await this.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.Create(entity); if (result.Status != QuestionElementActionStatus.Success) { return(result.Clone <Guid>()); } 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.Clone(result.Content.Id)); }
public async Task <IHttpActionResult> CreateQuestionElement( int customerId, CreateQuestionElementRequestDto model ) { var result = await questionElementHelper.Create(customerId, model); switch (result.Status) { 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(Created( new Uri(Request.RequestUri, result.Content.ToString()), new PostResponseDto <Guid> { Id = result.Content } )); } }
/// <summary> /// Sends request to health library to create new question element. /// </summary> /// <param name="createQuestionDto"></param> /// <param name="customerId"></param> /// <param name="token"></param> /// <returns></returns> public async Task <PostResponseDto <Guid> > CreateQuestion(CreateQuestionElementRequestDto createQuestionDto, int customerId, string token) { createQuestionDto.AnswerChoiceIds = createQuestionDto.AnswerChoiceIds.Where(a => !a.IsEmpty()).ToList(); return(await this.healthLibraryDataProvider.CreateQuestion(createQuestionDto, customerId, token)); }
public async Task <PostResponseDto <Guid> > CreateQuestion(CreateQuestionElementRequestDto createQuestionDto, int customerId, string token) { var url = string.Format("/api/{0}/question-elements", customerId); return(await this.apiClient.SendRequestAsync <PostResponseDto <Guid> >(url, createQuestionDto, Method.POST, null, token)); }