Пример #1
0
        public ActionResult Edit(Track track)
        {
            if (ModelState.IsValid)
            {
                TrackAPIController api = new TrackAPIController(_db);
                if (!api.TrackExists(track.Title, track.Album.Title, track.Album.Artist.Name, (DateTime)track.ReleaseDate))
                {
                    Track edittedTrack = _db.Tracks.Find(track.Id);
                    edittedTrack.Title       = track.Title;
                    edittedTrack.ReleaseDate = track.ReleaseDate;
                    Album  tempAlbum  = _db.Albums.FirstOrDefault(album => album.Title.ToLower() == track.Album.Title.Trim().ToLower() && album.Artist.Name.ToLower() == track.Album.Artist.Name.Trim().ToLower());
                    Artist tempArtist = _db.Artists.FirstOrDefault(artist => artist.Name.ToLower() == track.Album.Artist.Name.Trim().ToLower());
                    if (tempAlbum == null)
                    {
                        if (tempArtist == null)
                        {
                            edittedTrack.Album = new Album()
                            {
                                Title        = track.Album.Title.Trim(),
                                ReleaseDate  = track.ReleaseDate,
                                DateModified = DateTime.Now,
                                Artist       = new Artist()
                                {
                                    Name         = track.Album.Artist.Name.Trim(),
                                    DateModified = DateTime.Now
                                }
                            };
                        }
                        else
                        {
                            edittedTrack.Album = new Album()
                            {
                                Title        = track.Album.Title.Trim(),
                                ReleaseDate  = track.ReleaseDate,
                                DateModified = DateTime.Now,
                                Artist       = tempArtist
                            };
                        }
                    }
                    else
                    {
                        edittedTrack.Album = tempAlbum;
                    }


                    _db.SetModified(edittedTrack);
                    _db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
                else
                {
                    ViewBag.ErrorMessage = "The track titled '" + track.Title + "' on the album titled '" + track.Album.Title + "' already exists.";
                    return(View(track));
                }
            }
            return(View(track));
        }
Пример #2
0
 public ActionResult Edit(Artist artist)
 {
     if (ModelState.IsValid)
     {
         Artist tempArtist = _db.Artists.SingleOrDefault(a => a.Name == artist.Name);
         if (tempArtist == null)
         {
             artist.DateModified = DateTime.Now;
             _db.SetModified(artist);
             _db.SaveChanges();
             return(RedirectToAction("Index"));
         }
         else
         {
             ModelState.AddModelError("", "An artist by that name already exists.");
             return(View(artist));
         }
     }
     return(View(artist));
 }
Пример #3
0
        public ActionResult Edit(Album album)
        {
            if (ModelState.IsValid)
            {
                if (!AlbumExists(album.Title, album.Artist.Name))
                {
                    Album edittedAlbum = _db.Albums.Find(album.Id);
                    edittedAlbum.Title       = album.Title;
                    edittedAlbum.ReleaseDate = album.ReleaseDate;

                    Artist tempArtist = _db.Artists.FirstOrDefault(artist => artist.Name.ToLower() == album.Artist.Name.Trim().ToLower());
                    if (tempArtist == null)
                    {
                        edittedAlbum.Artist = new Artist()
                        {
                            Name         = album.Artist.Name,
                            DateModified = DateTime.Now
                        };
                    }
                    else
                    {
                        edittedAlbum.Artist = tempArtist;
                    }



                    _db.SetModified(edittedAlbum);
                    _db.SaveChanges();
                    return(RedirectToAction("Index"));
                }

                return(View(album));
            }
            else
            {
                ViewBag.ErrorMessage = "The album '" + album.Title + "' by '" + album.Artist.Name + "' already exists.";
                return(View(album));
            }
        }