示例#1
0
        /// <summary>
        /// Creates instance of SelectionAnswerChoiceString using dto data.
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        private async Task <QuestionElementString> MapAnswerString(CreateLocalizedStringRequestDto dto)
        {
            if (dto == null)
            {
                throw new ArgumentNullException("dto");
            }

            var result = Mapper.Map <QuestionElementString>(dto);

            result.Language = string.IsNullOrEmpty(careElementContext.Language)
                ? careElementContext.DefaultLanguage
                : careElementContext.Language;

            if (dto.AudioFileMedia == null)
            {
                return(result);
            }

            result.AudioFileMedia = await mediaFileHelper.CreateMediaFile(dto.AudioFileMedia);

            if (result.AudioFileMedia != null)
            {
                result.AudioFileMedia.Tags = await tagsService.BuildTagsList(careElementContext.CustomerId, dto.AudioFileMedia.Tags);
            }

            return(result);
        }
示例#2
0
        private async Task <T> MapLabelToLocalizedString <T>(CreateLocalizedStringRequestDto dto, string language)
            where T : LocalizedString
        {
            var label = Mapper.Map <T>(dto);

            label.Language = language;

            if (dto.AudioFileMedia != null)
            {
                label.AudioFileMedia = await mediaFileHelper.CreateMediaFile(dto.AudioFileMedia);
            }

            return(label);
        }
        /// <summary>
        /// Creates instance of SelectionAnswerChoiceString using dto data.
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        private async Task <SelectionAnswerChoiceString> MapSelectionAnswerChoiceString(CreateAnswerStringRequestDto dto)
        {
            if (dto == null)
            {
                throw new ArgumentNullException("dto");
            }

            var result = Mapper.Map <CreateAnswerStringRequestDto, SelectionAnswerChoiceString>(dto);

            result.Language = careElementContext.DefaultLanguage;

            if (dto.AudioFileMedia != null)
            {
                result.AudioFileMedia = await mediaFileHelper.CreateMediaFile(dto.AudioFileMedia);
            }

            return(result);
        }
示例#4
0
        /// <summary>
        /// Creates the specified new text media element dto.
        /// </summary>
        /// <param name="customerId">The customer identifier.</param>
        /// <param name="newTextMediaElementDto">The new text media element dto.</param>
        /// <returns></returns>
        public async Task <OperationResultDto <Guid, CreateTextMediaElementStatus> > Create(
            int customerId,
            CreateTextMediaElementRequestDto newTextMediaElementDto
            )
        {
            var validationResult = await ValidateCreateTextMediaElement(customerId, newTextMediaElementDto);

            if (!validationResult.HasFlag(CreateTextMediaElementStatus.Success))
            {
                return(new OperationResultDto <Guid, CreateTextMediaElementStatus>()
                {
                    Status = validationResult
                });
            }

            var elementTags = await tagsService.BuildTagsList(customerId, newTextMediaElementDto.Tags);

            var mappedTextMediaElement = Mapper.Map <CreateTextMediaElementRequestDto, TextMediaElement>(newTextMediaElementDto);

            mappedTextMediaElement.CustomerId = customerId;
            mappedTextMediaElement.Tags       = elementTags;

            var elementString = Mapper.Map <CreateLocalizedStringRequestDto, TextMediaElementString>(newTextMediaElementDto.Text);

            if (elementString != null)
            {
                elementString.Language = CareElementRequestContext.Current.DefaultLanguage;

                mappedTextMediaElement.TextLocalizedStrings = new List <TextMediaElementString>()
                {
                    elementString
                };

                if (newTextMediaElementDto.Text.AudioFileMedia != null)
                {
                    elementString.AudioFileMedia = await mediaFileHelper.CreateMediaFile(newTextMediaElementDto.Text.AudioFileMedia);
                }
            }

            if (newTextMediaElementDto.MediaId.HasValue)
            {
                mappedTextMediaElement.TextMediaElementsToMedias = new List <TextMediaElementToMedia>()
                {
                    new TextMediaElementToMedia()
                    {
                        MediaId  = newTextMediaElementDto.MediaId.Value,
                        Language = CareElementRequestContext.Current.DefaultLanguage
                    }
                };
            }
            else if (newTextMediaElementDto.Media != null)
            {
                var media = await mediaFileHelper.CreateMediaFile(newTextMediaElementDto.Media);

                if (media != null)
                {
                    mappedTextMediaElement.TextMediaElementsToMedias = new List <TextMediaElementToMedia>()
                    {
                        new TextMediaElementToMedia()
                        {
                            Media    = media,
                            Language = CareElementRequestContext.Current.DefaultLanguage
                        }
                    };
                }
            }

            var result = await textMediaElementsService.Create(mappedTextMediaElement);

            await globalSearchCacheHelper.AddOrUpdateEntry(customerId, Mapper.Map <TextMediaElement, SearchTextAndMediaDto>(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, CreateTextMediaElementStatus>()
            {
                Status = CreateTextMediaElementStatus.Success,
                Content = mappedTextMediaElement.Id
            });
        }