Пример #1
0
 public ActionResult Create(SongAdd newItem)
 {
     if (!ModelState.IsValid)
     {
         return(RedirectToAction("error"));
     }
     else
     {
         var addedItem = m.AddSong(newItem);
         return(RedirectToAction("index"));
     }
 }
Пример #2
0
        public ActionResult Create(SongAdd newItem)
        {
            if (ModelState.IsValid)
            {
                SongBase addedItem = m.AddSong(newItem);

                return(RedirectToAction("Index"));
            }
            else
            {
                return(RedirectToAction("Create"));
            }
        }
Пример #3
0
        // Add song
        public SongBase AddSong(SongAdd newItem)
        {
            // Validate the incoming data
            var album = ds.Albums.Find(newItem.AlbumId);

            if (album == null)
            {
                return null;
            }
            else
            {
                var addedItem = ds.Songs.Add(Mapper.Map<Song>(newItem));
                addedItem.Album = album;
                ds.SaveChanges();

                return (addedItem == null) ? null : Mapper.Map<SongBase>(addedItem);
            }
        }
Пример #4
0
        public SongBase AddSong(SongAdd newItem)
        {
            var fetchedObject = ds.Albums.Find(newItem.AlbumId);

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

                return(Mapper.Map <SongBase>(addItem));
            }
        }
Пример #5
0
        public SongBase AddSong(SongAdd newItem)
        {
            SongBase result;

            var   addedItem = new Song();
            Album temp      = ds.Albums.Include("Artist").SingleOrDefault(i => i.Id == newItem.AlbumId);

            //validate album id
            if (temp != null)
            {
                addedItem       = Mapper.Map <Song>(newItem);
                addedItem.Album = temp;
                ds.Songs.Add(addedItem);
                ds.SaveChanges();
            }
            result = Mapper.Map <SongBase>(addedItem);

            // Return the result
            return(result);
        }
Пример #6
0
        public ActionResult Create(SongAdd newItem)
        {
            if (ModelState.IsValid)
            {
                // Attempt to add the item
                var addedItem = m.AddSong(newItem);

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