public async Task <IActionResult> PutMetaItem(Entity.MetaItem metaItem)
        {
            try
            {
                return(new JsonResult(await _metadataController.Save(metaItem)));
            }
            catch (InvalidAlbumException)
            {
                return(NotFound($"Could not find album with ID {metaItem.MediaId}"));
            }
            catch (InvalidMediaObjectException)
            {
                return(NotFound($"Media Asset/Metadata Item Not Found: One of the following errors occurred: (1) Could not find meta item with ID {metaItem.Id} (2) Could not find media asset with ID {metaItem.MediaId}"));
            }
            catch (GallerySecurityException)
            {
                return(Forbid());
            }
            catch (Exception ex)
            {
                AppEventController.LogError(ex);

                return(StatusCode(500, _exController.GetExString(ex)));
            }
        }
Пример #2
0
        /// <summary>
        /// Persists the metadata item to the data store. The current implementation requires that
        /// an existing item exist in the data store and only stores the contents of the
        /// <see cref="Entity.MetaItem.Value" /> property.
        /// </summary>
        /// <param name="metaItem">An instance of <see cref="Entity.MetaItem" /> to persist to the data
        /// store.</param>
        /// <returns>Entity.MetaItem.</returns>
        /// <exception cref="System.Web.Http.HttpResponseException">Thrown when an album or media object associated
        /// with the meta item doesn't exist or an error occurs.</exception>
        public Entity.MetaItem PutMetaItem(Entity.MetaItem metaItem)
        {
            try
            {
                return(MetadataController.Save(metaItem));
            }
            catch (InvalidAlbumException)
            {
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.NotFound)
                {
                    Content      = new StringContent(String.Format("Could not find album with ID {0}", metaItem.MediaId)),
                    ReasonPhrase = "Album Not Found"
                });
            }
            catch (InvalidMediaObjectException)
            {
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.NotFound)
                {
                    Content      = new StringContent(String.Format("One of the following errors occurred: (1) Could not find meta item with ID {0} (2) Could not find media object with ID {1} ", metaItem.Id, metaItem.MediaId)),
                    ReasonPhrase = "Media Object/Metadata Item Not Found"
                });
            }
            catch (GallerySecurityException)
            {
                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"
                });
            }
        }
Пример #3
0
        private static Entity.MetaItem GetMetaItemForTag(Entity.MetaItem[] meta, MetadataItemName tagName, Entity.GalleryItem galleryItem)
        {
            var tagMi = meta.FirstOrDefault(m => m.MTypeId == (int)tagName);
            if (tagMi != null)
            {
                return tagMi;
            }
            else
            {
                // Last item doesn't have a tag. Create one. This code path should be pretty rare.
                int galleryId;
                if (galleryItem.IsAlbum)
                    galleryId = AlbumController.LoadAlbumInstance(galleryItem.Id, false).GalleryId;
                else
                    galleryId = Factory.LoadMediaObjectInstance(galleryItem.Id).GalleryId;

                bool isEditable = Factory.LoadGallerySetting(galleryId).MetadataDisplaySettings.Find(tagName).IsEditable;

                tagMi = new Entity.MetaItem
                    {
                        Id = int.MinValue,
                        MediaId = galleryItem.Id,
                        GTypeId = galleryItem.ItemType,
                        MTypeId = (int)tagName,
                        Desc = tagName.ToString(),
                        Value = String.Empty,
                        IsEditable = isEditable
                    };

                Array.Resize(ref meta, meta.Count() + 1);
                meta[meta.Length - 1] = tagMi;

                return tagMi;
            }
        }