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

                return(new JsonResult(await _galleryObjectController.ReplaceMediaAssetFile(mediaAssetId, filePath, fileName)));
            }
            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 Replace Media Asset",
                    Message = ex.Message
                }));
            }
            catch (Exception ex)
            {
                AppEventController.LogError(ex);

                return(StatusCode(500, _exController.GetExString(ex)));
            }
        }
Example #2
0
        /// <summary>
        /// Replace the original file associated with <paramref name="mediaAssetId" /> with <paramref name="fileNameOnServer" /> and giving it the name
        /// <paramref name="fileName" />. Re-extract relevant metadata such as width, height, orientation, video/audio info, etc. Thumbnail and
        /// optimized images are regenerated. The original file is not modified.
        /// </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>
        /// <param name="fileName">Name the file should be given when it is persisted to the album directory.</param>
        /// <returns>An instance of <see cref="ActionResult" />.</returns>
        /// <exception cref="System.Web.Http.HttpResponseException"></exception>
        /// <exception cref="HttpResponseMessage">Thrown when an unexpected error occurs.</exception>
        /// <exception cref="HttpResponseException">Thrown when an unexpected error occurs.</exception>
        public ActionResult ReplaceMediaAssetFile(int mediaAssetId, string fileNameOnServer, string fileName)
        {
            try
            {
                var filePath = Path.Combine(AppSetting.Instance.PhysicalApplicationPath, GlobalConstants.TempUploadDirectory, fileNameOnServer);

                return(GalleryObjectController.ReplaceMediaAssetFile(mediaAssetId, filePath, fileName));
            }
            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 Replace 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"
                });
            }
        }