Beispiel #1
0
        public virtual async Task <JsonResult> UpdateTitleImage(long titleId)
        {
            JsonResult jsonResult;
            Guid?      imageId;

            try
            {
                if (this.Request.Files.Count <= 0 || this.Request.Files[0] == null)
                {
                    throw new UserFriendlyException(this.L("TitleImage_Change_Error"));
                }
                HttpPostedFileBase item = this.Request.Files[0];
                if (item.ContentLength > 512000)
                {
                    throw new UserFriendlyException(this.L("TitleImage_Warn_SizeLimit"));
                }
                GetTitleForEditOutput titleForEdit = await this._titleAppService.GetTitleForEdit(new NullableIdInput <long>(new long?(titleId)));

                GetTitleForEditOutput nullable = titleForEdit;
                if (nullable.Title.ImageId.HasValue)
                {
                    IBinaryObjectManager binaryObjectManager = this._binaryObjectManager;
                    imageId = nullable.Title.ImageId;
                    await binaryObjectManager.DeleteAsync(imageId.Value);
                }
                BinaryObject binaryObject = new BinaryObject(item.InputStream.GetAllBytes());
                await this._binaryObjectManager.SaveAsync(binaryObject);

                nullable.Title.ImageId = new Guid?(binaryObject.Id);
                UpdateTitleImageInput updateTitleImageInput = new UpdateTitleImageInput()
                {
                    TitleId = nullable.Title.Id.Value
                };
                imageId = nullable.Title.ImageId;
                updateTitleImageInput.ImageId = new Guid?(imageId.Value);
                await this._titleAppService.SaveTitleImageAsync(updateTitleImageInput);

                jsonResult = this.Json(new MvcAjaxResponse());
            }
            catch (UserFriendlyException userFriendlyException1)
            {
                UserFriendlyException userFriendlyException = userFriendlyException1;
                jsonResult = this.Json(new MvcAjaxResponse(new ErrorInfo(userFriendlyException.Message), false));
            }
            return(jsonResult);
        }
Beispiel #2
0
        public async Task SaveTitleImageAsync(UpdateTitleImageInput input)
        {
            Title async = await this._titleRepository.GetAsync(input.TitleId);

            Guid?imageId = input.ImageId;

            if (!imageId.HasValue)
            {
                imageId       = null;
                async.ImageId = imageId;
            }
            else
            {
                imageId       = input.ImageId;
                async.ImageId = new Guid?(imageId.Value);
            }
            await this._titleRepository.UpdateAsync(async);
        }