public ActionResult Create(AlbumAdd newItem)
 {
     if (!ModelState.IsValid)
     {
         return(RedirectToAction("error"));
     }
     else
     {
         var addedItem = m.AddAlbum(newItem);
         return(RedirectToAction("index"));
     }
 }
        public ActionResult Create(AlbumAdd newItem)
        {
            if (ModelState.IsValid)
            {
                AlbumBase addItem = m.AddAlbum(newItem);

                return(RedirectToAction("Index"));
            }
            else
            {
                return(RedirectToAction("Create"));
            }
        }
예제 #3
0
        // Add album
        public AlbumBase AddAlbum(AlbumAdd newItem)
        {
            // Validate the incoming data
            var artist = ds.Artists.Find(newItem.ArtistId);

            if (artist == null)
            {
                return null;
            }
            else
            {
                var addedItem = ds.Albums.Add(Mapper.Map<Album>(newItem));
                addedItem.Artist = artist;
                ds.SaveChanges();

                return (addedItem == null) ? null : Mapper.Map<AlbumBase>(addedItem);
            }
        }
예제 #4
0
        public AlbumBase AddAlbum(AlbumAdd newItem)
        {
            var fetchedObject = ds.Artists.Find(newItem.ArtistId);

            if (fetchedObject == null)
            {
                return(null);
            }
            else
            {
                var addItem = Mapper.Map <Album>(newItem);
                addItem.Artist = fetchedObject;
                ds.Albums.Add(addItem);
                ds.SaveChanges();

                return(Mapper.Map <AlbumBase>(addItem));
            }
        }
예제 #5
0
        public AlbumBase AddAlbum(AlbumAdd newItem)
        {
            AlbumBase result;

            var addedItem = new Album();

            addedItem = Mapper.Map <Album>(newItem);
            //validate artistId
            if (ds.Artists.Find(newItem.ArtistId) != null)
            {
                addedItem.Artist = ds.Artists.Find(newItem.ArtistId);
                ds.Albums.Add(addedItem);
                ds.SaveChanges();
            }
            result = Mapper.Map <AlbumBase>(addedItem);

            // Return the result
            return(result);
        }
        public ActionResult Create(AlbumAdd newItem)
        {
            if (ModelState.IsValid)
            {
                // Attempt to add the item
                var addedItem = m.AddAlbum(newItem);

                if (addedItem == null)
                {
                    return RedirectToAction("Index");
                }
                else
                {
                    return RedirectToAction("Index");
                }
            }
            else
            {
                return View();
            }
        }