Beispiel #1
0
        public TrackWithDetail TrackAdd(TrackAdd addTrack)
        {
            var addAlbum     = ds.Albums.Find(addTrack.AlbumId);
            var addMediaType = ds.MediaTypes.Find(addTrack.MediaTypeId);

            var addItem = ds.Tracks.Add(Mapper.Map <TrackAdd, Track>(addTrack));

            addItem.Album     = addAlbum;
            addItem.MediaType = addMediaType;
            ds.SaveChanges();

            return((addItem == null) ? null : Mapper.Map <Track, TrackWithDetail>(addItem));
        }
Beispiel #2
0
        public ActionResult Create(TrackAdd newItem)
        {
            if (!ModelState.IsValid)
            {
                return(View(newItem));
            }

            var addItem = m.TrackAdd(newItem);

            if (addItem == null)
            {
                return(View(newItem));
            }
            return(RedirectToAction("details", new { id = addItem.TrackId }));
        }
Beispiel #3
0
        public ActionResult Create(TrackAdd collection)
        {
            if (!ModelState.IsValid)
            {
                return(View(collection));
            }

            var o = m.TrackAdd(collection);

            if (o == null)
            {
                return(View(o));
            }
            else
            {
                return(RedirectToAction("Details", new { id = o.TrackId }));
            }
        }
Beispiel #4
0
        public ActionResult Create(TrackAdd obj)
        {
            if (!ModelState.IsValid)
            {
                return(View(obj));
            }

            var add = m.TrackAdd(obj);

            if (add != null)
            {
                return(View("Details", m.TrackGetById(add.TrackId)));
            }
            else
            {
                return(RedirectToAction("Create"));
            }
        }
        public TrackBase TrackAdd(TrackAdd obj)
        {
            var media = ds.MediaTypes.SingleOrDefault(p => p.MediaTypeId == obj.MediaTypeId);
            var album = ds.Albums.SingleOrDefault(p => p.AlbumId == obj.AlbumId);

            if (media == null || album == null)
            {
                return(null);
            }

            var forged_track = ds.Tracks.Add(Mapper.Map <TrackAdd, Track>(obj));

            forged_track.MediaType = media;
            forged_track.Album     = album;

            ds.SaveChanges();

            return((forged_track == null) ? null : Mapper.Map <Track, TrackBase>(forged_track));
        }
        public ActionResult Create(TrackAdd newItem)
        {
            // Validate the input
            if (!ModelState.IsValid)
            {
                return(View(newItem));
            }

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

            if (addedItem == null)
            {
                return(View(newItem));
            }
            else
            {
                return(RedirectToAction("details", new { id = addedItem.TrackId }));
            }
        }
        public ActionResult Create(TrackAdd newTrack)
        {
            if (!ModelState.IsValid)
            {
                //Returns invalid track for re-entry.
                return(View(newTrack));
            }

            var addedItem = m.TrackAdd(newTrack);

            // TODO: Add insert logic here
            if (addedItem != null)
            {
                return(View("Details", m.TrackGetById(addedItem.TrackId)));
            }
            else
            {
                return(RedirectToAction("Create"));
            }
        }
Beispiel #8
0
        public TrackWithDetail TrackAdd(TrackAdd newTrack)
        {
            var a = ds.MediaTypes.Find(newTrack.MediaTypeId);
            var b = ds.Albums.Find(newTrack.AlbumId);

            if (a == null || b == null)
            {
                return(null);
            }
            else
            {
                // Attempt to add the new item
                var addedTrack = ds.Tracks.Add(Mapper.Map <TrackAdd, Track>(newTrack));
                addedTrack.MediaType = a;
                addedTrack.Album     = b;
                ds.SaveChanges();

                // If successful, return the added item, mapped to a view model object
                return((addedTrack == null) ? null : Mapper.Map <Track, TrackWithDetail>(addedTrack));
            }
        }
Beispiel #9
0
        // Add

        public TrackWithDetail TrackAdd(TrackAdd newItem)
        {
            var a = ds.Albums.Find(newItem.AlbumId);
            var b = ds.MediaTypes.Find(newItem.MediaTypeId);

            if (a == null || b == null)
            {
                return(null);
            }
            else
            {
                var addedItem = ds.Tracks.Add(Mapper.Map <TrackAdd, Track>(newItem));
                // Set the associated item property
                addedItem.Album     = a;
                addedItem.MediaType = b;
                ds.SaveChanges();

                // If successful, return the added item, mapped to a view model object
                return((addedItem == null) ? null : Mapper.Map <Track, TrackWithDetail>(addedItem));
            }
        }
Beispiel #10
0
        public TrackBase TrackAdd(TrackAdd newTrack)
        {
            // Validate the AlbumId and MediaTypeId
            //if (ds.Albums.Find(newTrack.AlbumId) == null){ return null; }
            var o = ds.MediaTypes.SingleOrDefault(item => item.MediaTypeId == newTrack.MediaTypeId);
            var p = ds.Albums.SingleOrDefault(item => item.AlbumId == newTrack.AlbumId);

            if (o == null || p == null)
            {
                return(null);
            }


            var addedTrack = ds.Tracks.Add(mapper.Map <TrackAdd, Track>(newTrack));

            // Directly modifying the Track database object (Track.cs)
            addedTrack.Album = p; addedTrack.MediaType = o;

            // The association is saved, the Album that is assocatied with the Track.Album is saved.
            ds.SaveChanges();

            return((addedTrack == null) ? null : mapper.Map <Track, TrackBase>(addedTrack));
        }
Beispiel #11
0
        /*Track Add Method*/
        public TrackWithDetail TrackAdd(TrackAdd newItem)
        {
            var a = ds.Albums.Find(newItem.AlbumId);
            var s = ds.MediaTypes.Find(newItem.MediaTypeId);

            if (a == null)
            {
                return(null);
            }
            if (s == null)
            {
                return(null);
            }
            else
            {
                var addItem = ds.Tracks.Add(Mapper.Map <TrackAdd, Track>(newItem));
                addItem.Album     = a;
                addItem.MediaType = s;

                ds.SaveChanges();

                return((addItem == null) ? null : Mapper.Map <Track, TrackWithDetail>(addItem));
            }
        }