예제 #1
0
        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 PartialViewResult ChangeTruckImage(TruckImageUploadModel model)
 {
     return(this.PartialView("_ChangeTruckImageModal", model));
 }