コード例 #1
0
        public ActionResult AddMediaItem(MediaItemAdd newItem)
        {
            if (!ModelState.IsValid)
            {
                return(View(newItem));
            }
            var addedItem = m.MediaItemAdd(newItem);

            if (addedItem == null)
            {
                return(View(newItem));
            }
            else
            {
                return(RedirectToAction("details", new { id = addedItem.Id }));
            }
        }
コード例 #2
0
        public ArtistWithDetail MediaItemAdd(MediaItemAdd newItem)
        {
            var artist = ds.Artists.SingleOrDefault(a => a.Id == newItem.ArtistId);

            if (artist == null)
            {
                return(null);
            }

            var addedItem = ds.MediaItem.Add(mapper.Map <MediaItemAdd, MediaItem>(newItem));

            addedItem.Artist = artist;
            byte[] fileBytes = new byte[newItem.FileUpload.ContentLength];
            newItem.FileUpload.InputStream.Read(fileBytes, 0, newItem.FileUpload.ContentLength);
            addedItem.Content     = fileBytes;
            addedItem.ContentType = newItem.FileUpload.ContentType;

            ds.SaveChanges();
            return((addedItem == null) ? null : ArtistGetByIdWithDetail(artist.Id));
        }