Exemple #1
0
        public ArtistBase ArtistMediaItemAdd(MediaItemAdd newItem)
        {
            var a = ds.Artists.Find(newItem.ArtistId);

            if (a == null)
            {
                return(null);
            }
            else
            {
                var addedItem = new MediaItem();
                ds.MediaItems.Add(addedItem);

                addedItem.Caption = newItem.Caption;
                addedItem.Artist  = a;

                byte[] mediaItemBytes = new byte[newItem.MediaItemUpload.ContentLength];
                newItem.MediaItemUpload.InputStream.Read(mediaItemBytes, 0, newItem.MediaItemUpload.ContentLength);


                addedItem.Content     = mediaItemBytes;
                addedItem.ContentType = newItem.MediaItemUpload.ContentType;

                ds.SaveChanges();

                return((addedItem == null) ? null : mapper.Map <Artist, ArtistBase>(a));
            }
        }
Exemple #2
0
        public ActionResult AddMediaItem(int?id, MediaItemAdd newItem)
        {
            // Validate the input
            // Two conditions must be checked
            if (!ModelState.IsValid && id.GetValueOrDefault() == newItem.ArtistId)
            {
                return(View(newItem));
            }

            // Process the input
            var addedItem = m.ArtistMediaItemAdd(newItem);

            if (addedItem == null)
            {
                return(View(newItem));
            }
            else
            {
                return(RedirectToAction("details", new { id = addedItem.Id }));
            }
        }