Пример #1
0
        public AlbumBase AlbumAdd(AlbumAdd newItem)
        {
            var addedItem = ds.Albums.Add(Mapper.Map <AlbumAdd, Album>(newItem));

            var addGenre = ds.Genres.Find(newItem.GenreId);

            foreach (var item in newItem.TrackIds)
            {
                var a = ds.Tracks.Find(item);

                addedItem.Tracks.Add(a);
            }

            foreach (var item in newItem.ArtistIds)
            {
                var a = ds.Artists.Find(item);

                addedItem.Artists.Add(a);
            }

            addedItem.Genre = addGenre.Name;

            ds.SaveChanges();

            return((addedItem == null) ? null : Mapper.Map <Album, AlbumBase>(addedItem));
        }
Пример #2
0
        public ActionResult Create(AlbumAdd newItem)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(View(newItem));
                }

                var addedItem = m.AlbumAdd(newItem);

                if (addedItem == null)
                {
                    return(HttpNotFound());
                }
                else
                {
                    return(RedirectToAction("details", new { id = addedItem.Id }));
                }
            }
            catch
            {
                return(View());
            }
        }
Пример #3
0
        public Album AlbumAddNew(AlbumAdd newItem)
        {
            var addeditem = ds.Albums.Add(Mapper.Map <Album>(newItem));

            addeditem.Genre       = newItem.Genre;
            addeditem.Coordinator = userAccount.Name;

            ds.SaveChanges();

            return((addeditem == null) ? null : Mapper.Map <Album>(addeditem));
        }
        public ActionResult Create(AlbumAdd album)
        {
            if (!ModelState.IsValid)
            {
                return(View(album));
            }

            var addedAlbum = m.AlbumAdd(album);

            if (addedAlbum != null)
            {
                return(RedirectToAction("Details", new { id = addedAlbum.Id }));
            }
            else
            {
                return(View());
            }
        }
Пример #5
0
        public AlbumWithDetail AlbumAdd(AlbumAdd newItem)
        {
            var o = ds.Albums.Add(mapper.Map <Album>(newItem));

            foreach (var item in newItem.ArtistIds)
            {
                var a = ds.Artists.Find(item);
                o.Artists.Add(a);
            }

            foreach (var item in newItem.TrackIds)
            {
                var b = ds.Tracks.Find(item);
                o.Tracks.Add(b);
            }

            ds.SaveChanges();

            return((o == null) ? null : mapper.Map <AlbumWithDetail>(o));
        }
Пример #6
0
        public ActionResult AddAlbum(AlbumAdd newItem)
        {
            //Validate
            if (!ModelState.IsValid)
            {
                return(View(newItem));
            }

            // Process
            var addedItem = m.AlbumAdd(newItem);

            if (addedItem == null)
            {
                return(View(newItem));
            }
            else
            {
                return(RedirectToAction("details", "album", new { id = addedItem.Id }));
            }
        }
Пример #7
0
        public ActionResult Create(AlbumAdd collection)
        {
            collection.Coordinator = HttpContext.User.Identity.Name;
            ModelState.Clear();

            if (!ModelState.IsValid)
            {
                return(View(collection));
            }

            var addedItem = m.AlbumAdd(collection);

            if (addedItem == null)
            {
                return(View(collection));
            }
            else
            {
                return(RedirectToAction("details", new { id = addedItem.Id }));
            }
        }
Пример #8
0
        public AlbumWithDetails AlbumAdd(AlbumAdd album)
        {
            var addedAlbum = ds.Albums.Add(mapper.Map <AlbumAdd, Album>(album));


            foreach (var item in album.ArtistIds)
            {
                var a = ds.Artists.Find(item);
                addedAlbum.Artists.Add(a);
            }

            foreach (var item in album.TrackIds)
            {
                var a = ds.Tracks.Find(item);
                addedAlbum.Tracks.Add(a);
            }

            ds.SaveChanges();

            return(addedAlbum == null ? null : mapper.Map <Album, AlbumWithDetails>(addedAlbum));
        }
Пример #9
0
        public ActionResult AddAlbum(AlbumAdd newItem)
        {
            // Validate the input
            if (!ModelState.IsValid)
            {
                return(View(newItem));
            }

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

            if (addedItem == null)
            {
                return(View(newItem));
            }
            else
            {
                // Attention - Must redirect to the Vehicles controller
                return(RedirectToAction("details", "Albums", new { id = addedItem.Id }));
            }
        }
Пример #10
0
        public ActionResult AddAlbum(AlbumAdd newItem)
        {
            newItem.Coordinator = HttpContext.User.Identity.Name;

            // Validate the input
            if (!ModelState.IsValid)
            {
                return(View(newItem));
            }

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

            if (addedItem == null)
            {
                return(View(newItem));
            }
            else
            {
                return(RedirectToAction("../album/details", new { id = addedItem.Id }));
            }
        }
Пример #11
0
        public AlbumWithDetail AlbumAdd(AlbumAdd newItem)
        {
            var a = ds.Artists.Include("Albums").FirstOrDefault(ar => ar.Id == newItem.ArtistId);

            if (a == null)
            {
                return(null);
            }
            else
            {
                foreach (var item in newItem.TrackIds)
                {
                    var b = ds.Tracks.Find(item);
                    ds.Tracks.Add(b);
                }

                var addedItem = ds.Albums.Add(mapper.Map <AlbumAdd, Album>(newItem));
                addedItem.Artists.Add(a);
                //addedItem.Tracks.Add(b);
                ds.SaveChanges();

                return((addedItem == null) ? null : mapper.Map <Album, AlbumWithDetail>(addedItem));
            }
        }
Пример #12
0
        public AlbumAdd AlbumAdd(AlbumAdd newItem)
        {
            // Attempt to add the new item
            var addedItem = ds.Albums.Add(Mapper.Map <AlbumAdd, Album>(newItem));
            var findGenre = ds.Genres.Find(newItem.GenreId);

            foreach (var item in newItem.TrackIds)
            {
                var a = ds.Tracks.Find(item);
                addedItem.Tracks.Add(a);
            }

            foreach (var item in newItem.ArtistIds)
            {
                var a = ds.Artists.Find(item);
                addedItem.Artists.Add(a);
            }

            // Set the associated item property
            addedItem.Genre = findGenre.Name;
            ds.SaveChanges();

            return((addedItem == null) ? null : Mapper.Map <Album, AlbumAdd>(addedItem));
        }