public async Task <IActionResult> ReplaceWithEditedImage(int mediaAssetId, string fileNameOnServer)
        {
            try
            {
                var filePath = Path.Combine(AppSetting.Instance.ContentRootPath, GlobalConstants.TempUploadDirectory, fileNameOnServer);

                return(new JsonResult(await _galleryObjectController.ReplaceWithEditedImage(mediaAssetId, filePath)));
            }
            catch (InvalidMediaObjectException ex)
            {
                return(new JsonResult(new Business.ActionResult()
                {
                    Status = ActionResultStatus.Error.ToString(),
                    Title = "Cannot Edit Media Asset",
                    Message = ex.Message
                }));
            }
            catch (GallerySecurityException ex)
            {
                return(new JsonResult(new Business.ActionResult()
                {
                    Status = ActionResultStatus.Error.ToString(),
                    Title = "Cannot Edit Media Asset",
                    Message = ex.Message
                }));
            }
            catch (Exception ex)
            {
                AppEventController.LogError(ex);

                return(StatusCode(500, _exController.GetExString(ex)));
            }
        }
Exemple #2
0
        /// <summary>
        /// Replace the original file associated with <paramref name="mediaAssetId" /> with <paramref name="fileNameOnServer" />. Most metadata is copied from
        /// the current file to <paramref name="fileNameOnServer" />. Orientation meta, if present, is removed. Some meta properties are updated (e.g. width, height).
        /// Thumbnail and optimized images are regenerated. Requires the application be running in trial mode or under a license of Home &amp; Nonprofit or higher.
        /// </summary>
        /// <param name="mediaAssetId">The ID of the media asset.</param>
        /// <param name="fileNameOnServer">The full path to the edited file. Ex: "C:\Dev\GS\Dev-Main\Website\App_Data\_Temp\85b74137-d795-40a5-8b93-bf31de0b0ca3.jpg"</param>
        /// <returns>An instance of <see cref="ActionResult" />.</returns>
        /// <exception cref="HttpResponseException">Thrown when an unexpected error occurs.</exception>
        /// <exception cref="HttpResponseMessage">Thrown when an unexpected error occurs.</exception>
        public ActionResult ReplaceWithEditedImage(int mediaAssetId, string fileNameOnServer)
        {
            try
            {
                var filePath = Path.Combine(AppSetting.Instance.PhysicalApplicationPath, GlobalConstants.TempUploadDirectory, fileNameOnServer);

                return(GalleryObjectController.ReplaceWithEditedImage(mediaAssetId, filePath));
            }
            catch (InvalidMediaObjectException ex)
            {
                return(new ActionResult()
                {
                    Status = ActionResultStatus.Error.ToString(),
                    Title = "Cannot Edit Media Asset",
                    Message = ex.Message
                });
            }
            catch (GallerySecurityException ex)
            {
                return(new ActionResult()
                {
                    Status = ActionResultStatus.Error.ToString(),
                    Title = "Cannot Edit Media Asset",
                    Message = ex.Message
                });
            }
            catch (Exception ex)
            {
                AppEventController.LogError(ex);

                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError)
                {
                    Content      = Utils.GetExStringContent(ex),
                    ReasonPhrase = "Server Error"
                });
            }
        }