public void TrackAPI_TrackExists() { TrackAPIController ctrl = new TrackAPIController(new MockSixteenBarsDb()); Boolean result = ctrl.TrackExists("Light Up", "Thank Me Later", "Drake", new DateTime(2010, 6, 14)); Assert.AreEqual(true, result, "Track 'Light Up' exists"); result = ctrl.TrackExists("Curls", "Doomsday", "MF DOOM", new DateTime(2010, 6, 14)); Assert.AreEqual(false, result, "Track 'Curls' doesn't exists"); }
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)); }
public void TrackAPI_AutoComplete() { TrackAPIController ctrl = new TrackAPIController(new MockSixteenBarsDb()); var result = ctrl.TrackAutoComplete("wet") as JsonResult; List<Track> results = result.Data as List<Track>; Assert.AreEqual(1, results.Count, "Wetter Than Tsunami not found"); Assert.AreEqual("Wetter Than Tsunami", results[0].Title, "Name not Wetter Than Tsunami"); result = ctrl.TrackAutoComplete("thing") as JsonResult; results = result.Data as List<Track>; Assert.AreEqual(0, results.Count, "Incorrect track found"); }
public ActionResult Create(TrackViewModel trackVM) { if (ModelState.IsValid) { Artist artist = _db.Artists.FirstOrDefault(a => a.Name.ToLower() == trackVM.ArtistName.Trim().ToLower()); if (artist == null) { _db.Artists.Add(new Artist() { Name = trackVM.ArtistName.Trim(), DateModified = DateTime.Now }); _db.SaveChanges(); artist = _db.Artists.FirstOrDefault(a => a.Name.ToLower() == trackVM.ArtistName.Trim().ToLower()); } Album album = _db.Albums.FirstOrDefault(a => a.Title.ToLower() == trackVM.AlbumTitle.Trim().ToLower()); if (album == null) { _db.Albums.Add(new Album() { Title = trackVM.AlbumTitle.Trim(), Artist = artist, ReleaseDate = trackVM.ReleaseDate, DateModified = DateTime.Now }); _db.SaveChanges(); album = _db.Albums.FirstOrDefault(a => a.Title.ToLower() == trackVM.AlbumTitle.Trim().ToLower()); } Track track = new Track(); track.Title = trackVM.Title; track.ReleaseDate = trackVM.ReleaseDate; track.Album = album; TrackAPIController api = new TrackAPIController(_db); if (!api.TrackExists(track.Title, track.Album.Title, track.Album.Artist.Name, (DateTime)track.ReleaseDate)) { _db.Tracks.Add(track); _db.SaveChanges(); } else { ViewBag.ErrorMessage = "The track titled '" + track.Title + "' on the album titled '" + track.Album.Title + "' already exists."; return(View(trackVM)); } return(RedirectToAction("Index")); } return(View(trackVM)); }
public ActionResult Create(TrackViewModel trackVM) { if (ModelState.IsValid) { Artist artist = _db.Artists.FirstOrDefault(a => a.Name.ToLower() == trackVM.ArtistName.Trim().ToLower()); if (artist == null) { _db.Artists.Add(new Artist() { Name = trackVM.ArtistName.Trim(), DateModified = DateTime.Now }); _db.SaveChanges(); artist = _db.Artists.FirstOrDefault(a => a.Name.ToLower() == trackVM.ArtistName.Trim().ToLower()); } Album album = _db.Albums.FirstOrDefault(a => a.Title.ToLower() == trackVM.AlbumTitle.Trim().ToLower()); if (album == null) { _db.Albums.Add(new Album() { Title = trackVM.AlbumTitle.Trim(), Artist = artist, ReleaseDate = trackVM.ReleaseDate, DateModified = DateTime.Now }); _db.SaveChanges(); album = _db.Albums.FirstOrDefault(a => a.Title.ToLower() == trackVM.AlbumTitle.Trim().ToLower()); } Track track = new Track(); track.Title = trackVM.Title; track.ReleaseDate = trackVM.ReleaseDate; track.Album = album; TrackAPIController api = new TrackAPIController(_db); if (!api.TrackExists(track.Title, track.Album.Title, track.Album.Artist.Name, (DateTime)track.ReleaseDate)) { _db.Tracks.Add(track); _db.SaveChanges(); } else { ViewBag.ErrorMessage = "The track titled '" + track.Title + "' on the album titled '" + track.Album.Title + "' already exists."; return View(trackVM); } return RedirectToAction("Index"); } return View(trackVM); }
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); }