コード例 #1
0
ファイル: TrucksController.cs プロジェクト: zberg007/fuelwerx
        public virtual async Task <JsonResult> UpdateTruckImage(TruckImageUploadModel model)
        {
            JsonResult jsonResult;
            Guid?      imageId;

            try
            {
                if (this.Request.Files.Count <= 0 || this.Request.Files[0] == null)
                {
                    throw new UserFriendlyException(this.L("TruckImage_Change_Error"));
                }
                HttpPostedFileBase item = this.Request.Files[0];
                if (item.ContentLength > 512000)
                {
                    throw new UserFriendlyException(this.L("TruckImage_Warn_SizeLimit"));
                }
                GetTruckForEditOutput truckForEdit = await this._truckAppService.GetTruckForEdit(new NullableIdInput <long>(new long?((long)model.TruckId)));

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

                nullable.Truck.ImageId = new Guid?(binaryObject.Id);
                model.Id = nullable.Truck.ImageId;
                UpdateTruckImageInput updateTruckImageInput = new UpdateTruckImageInput()
                {
                    TruckId = nullable.Truck.Id.Value
                };
                imageId = nullable.Truck.ImageId;
                updateTruckImageInput.ImageId = new Guid?(imageId.Value);
                await this._truckAppService.SaveImageAsync(updateTruckImageInput);

                jsonResult = this.Json(new MvcAjaxResponse());
            }
            catch (UserFriendlyException userFriendlyException1)
            {
                UserFriendlyException userFriendlyException = userFriendlyException1;
                jsonResult = this.Json(new MvcAjaxResponse(new ErrorInfo(userFriendlyException.Message), false));
            }
            return(jsonResult);
        }
コード例 #2
0
        public async Task SaveImageAsync(UpdateTruckImageInput input)
        {
            Truck async = await this._truckRepository.GetAsync(input.TruckId);

            Guid?imageId = input.ImageId;

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