Beispiel #1
0
        /// <summary>
        /// Posts the scale answer set.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <param name="customerId"></param>
        /// <param name="token">The token.</param>
        /// <returns></returns>
        public async Task <PostResponseDto <Guid> > PostScaleAnswerSet(CreateScaleAnswerSetRequestDto request, int customerId, string token)
        {
            var url = string.Format("api/{0}/answer-sets/scale", customerId);

            return(await apiClient.SendRequestAsync <PostResponseDto <Guid> >(
                       url, request, Method.POST, null, token));
        }
Beispiel #2
0
        private CreateScaleAnswerSetStatus ValidateLabels(CreateScaleAnswerSetRequestDto model)
        {
            CreateScaleAnswerSetStatus status = 0;

            if (string.IsNullOrEmpty(model.Labels.HighLabel.Value))
            {
                status |= CreateScaleAnswerSetStatus.HighLabelIsRequired;
            }

            if (string.IsNullOrEmpty(model.Labels.LowLabel.Value))
            {
                status |= CreateScaleAnswerSetStatus.LowLabelIsRequired;
            }

            return(status);
        }
        public async Task <IHttpActionResult> CreateScaleAnswerSet(int customerId, [FromBody] CreateScaleAnswerSetRequestDto model)
        {
            var result = await scaleAnswerSetHelper.Create(customerId, model);

            if (!result.Status.HasFlag(CreateScaleAnswerSetStatus.Success))
            {
                return(Content(
                           HttpStatusCode.BadRequest,
                           new ErrorResponseDto()
                {
                    Error = ErrorCode.InvalidRequest,
                    Message = ErrorCode.InvalidRequest.Description(),
                    Details = result.Status.GetConcatString(),
                }));
            }

            return(Created(new Uri(Request.RequestUri, result.Content.ToString()),
                           new PostResponseDto <Guid> {
                Id = result.Content
            }));
        }
Beispiel #4
0
        /// <summary>
        /// Creates the specified model.
        /// </summary>
        /// <param name="customerId">The customer identifier.</param>
        /// <param name="model">The model.</param>
        /// <returns></returns>
        public async Task <OperationResultDto <Guid, CreateScaleAnswerSetStatus> > Create(int customerId, CreateScaleAnswerSetRequestDto model)
        {
            var status = ValidateLabels(model);

            if (status > 0)
            {
                return(new OperationResultDto <Guid, CreateScaleAnswerSetStatus>()
                {
                    Status = status
                });
            }

            var answerSet = Mapper.Map <ScaleAnswerSet>(model);

            answerSet.CustomerId = customerId;
            answerSet.Tags       = await tagsService.BuildTagsList(customerId, model.Tags);

            var lowLabel = await MapLabelToLocalizedString <LowLabelScaleAnswerSetString>(
                model.Labels.LowLabel, careElementContext.DefaultLanguage);

            answerSet.LowLabelScaleAnswerSetStrings.Add(lowLabel);

            // Mid is optional field.
            if (model.Labels.MidLabel != null)
            {
                var midLabel = await MapLabelToLocalizedString <MidLabelScaleAnswerSetString>
                                   (model.Labels.MidLabel, careElementContext.DefaultLanguage);

                answerSet.MidLabelScaleAnswerSetStrings.Add(midLabel);
            }

            var highLabel = await MapLabelToLocalizedString <
                HighLabelScaleAnswerSetString>(model.Labels.HighLabel,
                                               careElementContext.DefaultLanguage);

            answerSet.HighLabelScaleAnswerSetStrings.Add(highLabel);

            var result = await scaleAnswerSetService.Create(answerSet);

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

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

            var unusedTags = await tagsService.RemoveUnusedTags(customerId);

            await tagsSearchCacheHelper.RemoveTags(customerId, unusedTags);

            return(new OperationResultDto <Guid, CreateScaleAnswerSetStatus>()
            {
                Content = result.Id,
                Status = CreateScaleAnswerSetStatus.Success
            });
        }
 /// <summary>
 /// Creates ScaleAnswerSet.
 /// </summary>
 /// <param name="request">The request.</param>
 /// <param name="customerId">The identifier.</param>
 /// <param name="token">The token.</param>
 /// <returns></returns>
 public async Task <PostResponseDto <Guid> > CreateScaleAnswerSet(CreateScaleAnswerSetRequestDto request, int customerId, string token)
 {
     return(await healthLibraryDataProvider.PostScaleAnswerSet(request, customerId, token));
 }