Beispiel #1
0
        private async Task <Guid?> UpdateMedia(UpdateMediaModel mediaElementModel)
        {
            if (mediaElementModel == null)
            {
                return(null);
            }

            var updateMediaDto = new UpdateMediaRequestDto()
            {
                Id               = mediaElementModel.Id,
                Name             = mediaElementModel.Name,
                ContentType      = mediaElementModel.ContentType,
                Tags             = mediaElementModel.Tags,
                OriginalFileName = mediaElementModel.OriginalFileName
            };

            if (!string.IsNullOrEmpty(mediaElementModel.FileName))
            {
                var fileContent = this.GetFileFromTempFolder(mediaElementModel.FileName);
                if (fileContent != null && fileContent.Length > 0)
                {
                    var fileContentBase64 = Convert.ToBase64String(fileContent);
                    updateMediaDto.Content          = fileContentBase64;
                    updateMediaDto.OriginalFileName = mediaElementModel.FileName;
                }
            }

            var token = this.authDataStorage.GetToken();

            await this.healthLibraryService.UpdateMediaElement(updateMediaDto, this.customerContext.Customer.Id, token);

            return(mediaElementModel.Id);
        }
        public async Task <IHttpActionResult> UpdateMedia(
            int customerId,
            Guid mediaId,
            UpdateMediaRequestDto request
            )
        {
            var updateResult = await controllerHelper.UpdateMedia(customerId, mediaId, request);

            if (updateResult == UpdateMediaStatus.NotFound)
            {
                return(Content(
                           HttpStatusCode.NotFound,
                           new ErrorResponseDto()
                {
                    Error = ErrorCode.InvalidRequest,
                    Message = ErrorCode.InvalidRequest.Description(),
                    Details = UpdateMediaStatus.NotFound.Description()
                }));
            }

            if (updateResult != UpdateMediaStatus.Success)
            {
                return(Content(
                           HttpStatusCode.BadRequest,
                           new ErrorResponseDto()
                {
                    Error = ErrorCode.InvalidRequest,
                    Message = ErrorCode.InvalidRequest.Description(),
                    Details = updateResult.Description()
                }));
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Beispiel #3
0
        /// <summary>
        /// Updates the specified identifier.
        /// </summary>
        /// <param name="customerId"></param>
        /// <param name="mediaId">The identifier.</param>
        /// <param name="updateMediaDto">The update media dto.</param>
        /// <returns></returns>
        public async Task <UpdateMediaStatus> UpdateMedia(
            int customerId,
            Guid mediaId,
            UpdateMediaRequestDto updateMediaDto
            )
        {
            var media = await mediaService.Get(customerId, mediaId);

            if (media == null)
            {
                return(UpdateMediaStatus.NotFound);
            }

            if (!string.IsNullOrEmpty(updateMediaDto.Content) ||
                !string.IsNullOrEmpty(updateMediaDto.SourceContentUrl))
            {
                var contentModel = Mapper.Map <UpdateMediaRequestDto, ContentModel>(updateMediaDto);

                var uploadResult = await contentStorage.UploadContent(contentModel);

                if (uploadResult == null)
                {
                    return(UpdateMediaStatus.InvalidContentOrSourceContentUrlProvided);
                }

                media.OriginalStorageKey  = uploadResult.OriginalStorageKey;
                media.ThumbnailStorageKey = uploadResult.ThumbnailStorageKey;
                media.ContentLength       = uploadResult.OriginalContentLength;
                media.OriginalFileName    = uploadResult.OriginalFileName;
            }

            media.Name        = updateMediaDto.Name;
            media.Description = updateMediaDto.Description;
            media.ContentType = updateMediaDto.ContentType;

            media.Tags.RemoveRange(media.Tags.ToList());

            var newElementTags = await tagsService.BuildTagsList(customerId, updateMediaDto.Tags);

            media.Tags.AddRange(newElementTags);

            await mediaService.Update(media);

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

            var unusedTags = await tagsService.RemoveUnusedTags(customerId);

            await tagsSearchCacheHelper.RemoveTags(customerId, unusedTags);

            return(UpdateMediaStatus.Success);
        }
Beispiel #4
0
        public async Task UpdateMediaElement(UpdateMediaRequestDto updateMediaDto, int customerId, string token)
        {
            var url = string.Format("/api/{0}/medias/{1}", customerId, updateMediaDto.Id);

            await this.apiClient.SendRequestAsync <MediaResponseDto>(url, updateMediaDto, Method.PUT, null, token);
        }
 public async Task UpdateMediaElement(UpdateMediaRequestDto updateMediaDto, int customerId, string token)
 {
     await this.healthLibraryDataProvider.UpdateMediaElement(updateMediaDto, customerId, token);
 }