public async Task <IActionResult> CreateFromFile(AddMediaObjectSettings settings)
        {
            try
            {
                settings.CurrentUserName = _userController.UserName;

                var fileExt = Path.GetExtension(settings.FileName);

                if (fileExt != null && fileExt.Equals(".zip", StringComparison.OrdinalIgnoreCase))
                {
                    _galleryObjectController.AddMediaObject(settings);

                    //Task.Factory.StartNew(async () =>
                    //{
                    //    var results = await _galleryObjectController.AddMediaObject(settings);

                    //    // Since we don't have access to the user's session here, let's create a log entry.
                    //    //LogUploadZipFileResults(results, settings);
                    //});

                    return(new JsonResult(new List <Business.ActionResult>
                    {
                        new Business.ActionResult
                        {
                            Title = settings.FileName,
                            Status = ActionResultStatus.Async.ToString()
                        }
                    }));
                }
                else
                {
                    var results = await _galleryObjectController.AddMediaObject(settings);

                    //Utils.AddResultToSession(results);

                    return(new JsonResult(results));
                }
            }
            catch (GallerySecurityException)
            {
                AppEventController.LogEvent(String.Format(CultureInfo.InvariantCulture, "Unauthorized access detected. The security system prevented a user from adding a media object."), null, EventType.Warning);

                return(Forbid());
            }
            catch (Exception ex)
            {
                AppEventController.LogError(ex);

                return(StatusCode(500, _exController.GetExString(ex)));
            }
        }
Example #2
0
        /// <summary>
        /// Adds a media file to an album. Prior to calling this method, the file should exist in the
        /// temporary upload directory (<see cref="GlobalConstants.TempUploadDirectory" />) in the
        /// App_Data directory with the name <see cref="AddMediaObjectSettings.FileNameOnServer" />. The
        /// file is copied to the destination album and given the name of
        /// <see cref="AddMediaObjectSettings.FileName" /> (instead of whatever name it currently has, which
        /// may contain a GUID).
        /// </summary>
        /// <param name="settings">The settings that contain data and configuration options for the media file.</param>
        /// <returns>List{ActionResult}.</returns>
        /// <exception cref="System.Web.Http.HttpResponseException">Thrown when the user does not have permission to add media
        /// objects or some other error occurs.</exception>
        public List <ActionResult> CreateFromFile(AddMediaObjectSettings settings)
        {
            try
            {
                settings.CurrentUserName = Utils.UserName;

                var fileExt = Path.GetExtension(settings.FileName);

                if (fileExt != null && fileExt.Equals(".zip", StringComparison.OrdinalIgnoreCase))
                {
                    Task.Factory.StartNew(() =>
                    {
                        var results = GalleryObjectController.AddMediaObject(settings);

                        // Since we don't have access to the user's session here, let's create a log entry.
                        LogUploadZipFileResults(results, settings);
                    });

                    return(new List <ActionResult>
                    {
                        new ActionResult
                        {
                            Title = settings.FileName,
                            Status = ActionResultStatus.Async.ToString()
                        }
                    });
                }
                else
                {
                    var results = GalleryObjectController.AddMediaObject(settings);

                    Utils.AddResultToSession(results);

                    return(results);
                }
            }
            catch (GallerySecurityException)
            {
                AppEventController.LogEvent(String.Format(CultureInfo.InvariantCulture, "Unauthorized access detected. The security system prevented a user from adding a media object."), null, EventType.Warning);

                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.Forbidden));
            }
            catch (Exception ex)
            {
                AppEventController.LogError(ex);

                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError)
                {
                    Content      = Utils.GetExStringContent(ex),
                    ReasonPhrase = "Server Error"
                });
            }
        }
 public List <ActionResult> AddMediaObject(AddMediaObjectSettings settings)
 {
     try
     {
         return(GalleryObjectController.AddMediaObject(settings));
     }
     catch (Exception ex)
     {
         AppErrorController.LogError(ex);
         throw;
     }
 }