Exemplo n.º 1
0
        public TrackWithDetails TrackAdd(TrackAdd newItem)
        {
            var album     = ds.Albums.Find(newItem.AlbumId);
            var mediaType = ds.MediaTypes.Find(newItem.MediaTypeId);

            if (album == null || mediaType == null)
            {
                return(null);
            }
            else
            {
                var addedItem = ds.Tracks.Add(Mapper.Map <TrackAdd, Track>(newItem));
                addedItem.Album     = album;
                addedItem.MediaType = mediaType;
                ds.SaveChanges();
                return((addedItem == null) ? null : Mapper.Map <Track, TrackWithDetails>(addedItem));
            }
        }
Exemplo n.º 2
0
        public ActionResult Create(TrackAdd newItem)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToAction("create"));
            }

            var addedItem = m.TrackAdd(newItem);

            if (addedItem == null)
            {
                return(RedirectToAction("create"));
            }
            else
            {
                return(RedirectToAction("details", new { id = addedItem.TrackId }));
            }
        }