Пример #1
0
        public ActionResult Create(TrackAdd newTrack)
        {
            //validate the input
            if (!ModelState.IsValid)
            {
                return(View(newTrack));
            }

            //Process the input
            var addedTrack = m.TrackAdd(newTrack);

            if (addedTrack == null)
            {
                return(View(newTrack));
            }
            else
            {
                return(RedirectToAction("TrackWithDetails", new { id = addedTrack.TrackId }));
            }
        }
Пример #2
0
        //Add new track
        public TrackBase TrackAdd(TrackAdd newItem)
        {
            //Attempt to add new Track
            var album      = ds.Albums.Find(newItem.AlbumId);
            var mediaType  = ds.MediaTypes.Find(newItem.MediaTypeId);
            var addedTrack = ds.Tracks.Add(mapper.Map <TrackAdd, Track>(newItem));

            if (album == null || mediaType == null)
            {
                return(null);
            }
            else
            {
                addedTrack.Album     = album;
                addedTrack.MediaType = mediaType;

                ds.SaveChanges();

                //If successful, return the added item, mapped to a view model object
                return((addedTrack == null) ? null : mapper.Map <Track, TrackBase>(addedTrack));
            }
        }