예제 #1
0
        /// <summary>
        /// Creates the media file.
        /// </summary>
        /// <param name="source">The source.</param>
        /// <returns></returns>
        public async Task <Media> CreateMediaFile(BaseMediaRequestDto source)
        {
            var contentModel = Mapper.Map <BaseMediaRequestDto, ContentModel>(source);

            var uploadResult = await contentStorage.UploadContent(contentModel);

            if (uploadResult == null)
            {
                return(await Task.FromResult <Media>(null));
            }

            var media = new Media
            {
                ContentLength       = uploadResult.OriginalContentLength,
                OriginalStorageKey  = uploadResult.OriginalStorageKey,
                ThumbnailStorageKey = uploadResult.ThumbnailStorageKey,
                OriginalFileName    = uploadResult.OriginalFileName,
                CustomerId          = CareElementRequestContext.Current.CustomerId,
                Tags = await tagsService.BuildTagsList(CareElementRequestContext.Current.CustomerId, source.Tags)
            };

            Mapper.Map <BaseMediaRequestDto, Media>(source, media);

            return(media);
        }
예제 #2
0
        /// <summary>
        /// Creates the specified media dto.
        /// </summary>
        /// <param name="customerId">The customer identifier.</param>
        /// <param name="mediaDto">The media dto.</param>
        /// <returns></returns>
        public async Task <OperationResultDto <Guid, CreateMediaStatus> > CreateMedia(int customerId, CreateMediaRequestDto mediaDto)
        {
            var contentModel = Mapper.Map <CreateMediaRequestDto, ContentModel>(mediaDto);

            var uploadResult = await contentStorage.UploadContent(contentModel);

            if (uploadResult == null)
            {
                return(new OperationResultDto <Guid, CreateMediaStatus>()
                {
                    Status = CreateMediaStatus.InvalidContentOrSourceContentUrlProvided
                });
            }

            var media = new Media()
            {
                CustomerId          = customerId,
                Name                = mediaDto.Name,
                Description         = mediaDto.Description,
                ContentType         = mediaDto.ContentType,
                ContentLength       = uploadResult.OriginalContentLength,
                Tags                = await tagsService.BuildTagsList(customerId, mediaDto.Tags),
                OriginalStorageKey  = uploadResult.OriginalStorageKey,
                ThumbnailStorageKey = uploadResult.ThumbnailStorageKey,
                OriginalFileName    = uploadResult.OriginalFileName
            };

            var createdMedia = await mediaService.Create(media);

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

            var unusedTags = await tagsService.RemoveUnusedTags(customerId);

            await tagsSearchCacheHelper.RemoveTags(customerId, unusedTags);

            return(new OperationResultDto <Guid, CreateMediaStatus>()
            {
                Content = createdMedia.Id,
                Status = CreateMediaStatus.Success
            });
        }