private void buttonUpdatePerformance_Click(object sender, EventArgs e) { if (textBoxPerformanceId.Text == "" || textBoxCircumstancesPerformance.Text == "") { MessageBox.Show("Wrong input!"); return; } ISongsRepository songsRep = new SongsRepository(); bool flag = songsRep.UpdatePSong(Convert.ToInt32(textBoxPerformanceId.Text), textBoxCircumstancesPerformance.Text); if (flag) { MessageBox.Show("Updated!"); } else { MessageBox.Show("Error!"); } textBoxPerformanceId.Text = ""; textBoxCircumstancesPerformance.Text = ""; }
private void Add() { Console.Clear(); Entity.Song song = new Entity.Song(); song.ParentUserId = AuthenticationService.LoggedUser.Id; Console.WriteLine("Add new Song:"); Console.Write("Title: "); song.Title = Console.ReadLine(); Console.Write("Atist Name: "); song.ArtistName = Console.ReadLine(); Console.Write("Year :"); song.Year = Console.ReadLine(); SongsRepository songRepository = new SongsRepository("songs.txt"); songRepository.Save(song); Console.WriteLine("Songs saved successfully."); Console.ReadKey(true); Console.WriteLine("-------------------------------------------"); }
private void buttonInsertPerfomance_Click(object sender, EventArgs e) { if (textBoxAuthorId.Text == "" || textBoxCircumstancesPerformance.Text == "" || textBoxSongName.Text == "") { MessageBox.Show("Wrong input!"); return; } ISongsRepository songsRep = new SongsRepository(); bool flag = songsRep.AddPSong(textBoxSongName.Text, textBoxCircumstancesPerformance.Text, Convert.ToInt32(textBoxAuthorId.Text)); if (flag) { MessageBox.Show("Posted!"); } else { MessageBox.Show("Error!"); } textBoxAuthorId.Text = ""; textBoxCircumstancesPerformance.Text = ""; textBoxSongName.Text = ""; }
private void View() { Console.Clear(); Console.Write("\tPlaylist ID: "); int playlistId = Convert.ToInt32(Console.ReadLine()); IsEmptyValidation(ref playlistId); SongsRepository phonesRepository = new SongsRepository(Properties.Settings.Default.FileSongs); Playlist playlist = _playlistRepository.GetById(playlistId); if (playlist == null || playlist.IsPublic == false) { Console.Clear(); Console.WriteLine("\tPlaylist not found."); Console.ReadKey(true); } else { Console.Clear(); SongsManagerView songManagerView = new SongsManagerView(playlist); songManagerView.Show(); } }
protected override void ViewMoreLogic(int id) { PlaylistsSongsRepository playlistsSongsRepo = new PlaylistsSongsRepository(Constants.PlaylistsSongsDirectory); List <PlaylistsSongs> playlistsSongs = playlistsSongsRepo.GetAll(playlistsong => playlistsong.PlaylistId == id); if (playlistsSongs.Count == 0) { Console.WriteLine("This playlist doesn't have any songs in it!"); return; } List <int> songsIds = new List <int>(); foreach (PlaylistsSongs playlistSong in playlistsSongs) //gets the song ids for the chosen playlist { songsIds.Add(playlistSong.SongId); } SongsRepository songsRepo = new SongsRepository(Constants.SongsDirectory); List <Song> songs = new List <Song>(); foreach (int songId in songsIds) //gets the actual songs from the playlist { songs.Add(songsRepo.GetById(songId)); } Console.WriteLine("Songs"); foreach (Song song in songs) { Console.WriteLine("Song ID: " + song.Id); Console.WriteLine("Song Title: " + song.Title); Console.WriteLine("Song Artist Name: " + song.ArtistName); Console.WriteLine("Song Year: " + song.Year); Console.WriteLine("============================================"); } }
private void View() { Console.Clear(); Console.Write("Song ID: "); int songId = Convert.ToInt32(Console.ReadLine()); SongsRepository songsRepository = new SongsRepository("songs.txt"); Entity.Song song = songsRepository.GetById(songId); if (song == null) { Console.Clear(); Console.WriteLine("Song not found."); Console.ReadKey(true); return; } Console.WriteLine("ID:" + song.Id); Console.WriteLine("Title :" + song.Title); Console.WriteLine("Artist Name :" + song.ArtistName); Console.WriteLine("Year :" + song.Year + "y"); Console.WriteLine("------------------------------------"); Console.WriteLine(); Console.ReadKey(true); }
public void DeleteArtist() { ViewArtists(); Console.WriteLine(); InputId: Console.Write("Enter artist id to delete: "); int deleteId; bool isInt = int.TryParse(Console.ReadLine(), out deleteId); while (isInt == false) { Console.WriteLine("IDs can only be integer numbers. Try again!!"); Console.ReadKey(true); goto InputId; } ArtistsRepository artistsRepo = new ArtistsRepository(Constants.ArtistsPath); Artist artist = artistsRepo.GetAll(a => a.Id == deleteId).FirstOrDefault(); if (artist == null) { Console.WriteLine("No artist with that Id exists in the system yet!"); Console.ReadKey(true); return; } SongsArtistsRepository songsArtistsRepo = new SongsArtistsRepository(Constants.SongsArtistsPath); List <SongsArtists> songsArtistsEntities = songsArtistsRepo.GetAll(sae => sae.ArtistId == deleteId); SongsRepository songsRepo = new SongsRepository(Constants.SongsPath); List <Song> songs = new List <Song>(); foreach (SongsArtists songsArtistsEntity in songsArtistsEntities) { Song song = songsRepo.GetAll(s => s.Id == songsArtistsEntity.SongId).FirstOrDefault(); songs.Add(song); } PlaylistsSongsRepository playlistsSongsRepo = new PlaylistsSongsRepository(Constants.PlaylistsSongsPath); List <PlaylistsSongs> playlistsSongsEntities = new List <PlaylistsSongs>(); foreach (SongsArtists songsArtistsEntity in songsArtistsEntities) { PlaylistsSongs playlistSongEntity = playlistsSongsRepo.GetAll(pse => pse.SongId == songsArtistsEntity.SongId).FirstOrDefault(); playlistsSongsEntities.Add(playlistSongEntity); } foreach (PlaylistsSongs playlistsSongsEntity in playlistsSongsEntities) { playlistsSongsRepo.Delete(playlistsSongsEntity); } foreach (Song song in songs) { songsRepo.Delete(song); } artistsRepo.Delete(artist); Console.WriteLine("Artist deleted successfully!"); Console.ReadKey(true); }
private void Update() { Console.Clear(); Console.Write("Song ID: "); int songId = Convert.ToInt32(Console.ReadLine()); SongsRepository songsRepository = new SongsRepository("songs.txt"); Entity.Song song = songsRepository.GetById(songId); if (song == null) { Console.Clear(); Console.WriteLine("Song not found."); Console.ReadKey(true); return; } Console.WriteLine("Editing Song (" + song.Title + ")"); Console.WriteLine("ID:" + song.Id); Console.WriteLine("Title :" + song.Title); Console.Write("New Title:"); string Title = Console.ReadLine(); Console.WriteLine("Artist Name :" + song.ArtistName); Console.Write("New Artist Name :"); string ArtistName = Console.ReadLine(); Console.WriteLine("Year :" + song.Year); Console.Write("New Year :"); string Year = Console.ReadLine(); if (!string.IsNullOrEmpty(Title)) { song.Title = Title; } if (!string.IsNullOrEmpty(ArtistName)) { song.ArtistName = ArtistName; } if (!string.IsNullOrEmpty(Year)) { song.Year = Year; } songsRepository.Save(song); Console.WriteLine("Song saved successfully."); Console.ReadKey(true); }
protected override void Seed(TestRockstars.DAL.DatabaseContext context) { JSONParser parse = new JSONParser(); SongsRepository songRepository = new SongsRepository(context); ArtistsRepository artistRepository = new ArtistsRepository(context); artistRepository.ClearArtists(); songRepository.ClearSongs(); songRepository.AddSong(parse.GetSongs().ToArray()); artistRepository.AddArtist(parse.GetArtists().ToArray()); }
private void AddSongToPlaylist() { Console.Clear(); SongsRepository songsRepo = new SongsRepository(Constants.SongsDirectory); List <Song> songsDb = songsRepo.GetAll(); foreach (Song song in songsDb) { Console.WriteLine("Song ID: " + song.Id); Console.WriteLine("Song Title: " + song.Title); Console.WriteLine("Song ArtistName: " + song.ArtistName); Console.WriteLine("Song Year: " + song.Year); Console.WriteLine("=================================================="); } Console.Write("Song ID: "); int songIdInput = Int32.Parse(Console.ReadLine()); List <Song> songDb = songsRepo.GetAll((song => song.Id == songIdInput)); if (songDb[0] == null) { Console.WriteLine("Cannot find song"); Console.ReadKey(true); return; } Console.Clear(); PlaylistsRepository playlistsRepo = new PlaylistsRepository(Constants.PlaylistsDirectory); List <Playlist> playlistsDb = playlistsRepo.GetAll(playlist => AuthenticationService.LoggedUser.Id == playlist.ParentUserId); foreach (Playlist playlist in playlistsDb)// user's playlists { Console.WriteLine("Playlist ID: " + playlist.Id); Console.WriteLine("Playlist Name: " + playlist.Name); Console.WriteLine("Playlist Description: " + playlist.Description); Console.WriteLine("Playlist Is public?: " + playlist.IsPublic); Console.WriteLine("===================================================="); } Console.Write("Playlist ID: "); int playlistIdInput = Int32.Parse(Console.ReadLine()); if (playlistsDb.Count == 0) { Console.WriteLine("Playlist not found"); Console.ReadKey(true); return; } playlistsDb = playlistsDb.Where(playlist => playlist.Id == playlistIdInput).ToList(); PlaylistsSongs playlistsSongs = new PlaylistsSongs(songDb[0], playlistsDb[0]); PlaylistsSongsRepository playlistsSongsRepo = new PlaylistsSongsRepository(Constants.PlaylistsSongsDirectory); playlistsSongsRepo.Save(playlistsSongs); Console.WriteLine("Song saved successfully to playlist!"); Console.ReadKey(true); }
public static bool ViewSongs(bool calledFromSongsView = false) { SongsRepository songsRepo = new SongsRepository(Constants.SongsPath); SongsArtistsRepository songsArtistsRepo = new SongsArtistsRepository(Constants.SongsArtistsPath); ArtistsRepository artistsRepo = new ArtistsRepository(Constants.ArtistsPath); List <Song> songs = songsRepo.GetAll(); Console.Clear(); if (songs.Count == 0) { Console.WriteLine("There are no songs in the system yet!"); Console.ReadKey(true); return(false); } foreach (Song song in songs) { Console.WriteLine("********************************"); Console.WriteLine("Id: {0}", song.Id); Console.WriteLine("Song title: {0}", song.Title); Console.WriteLine("Song release year: {0}", song.Year); List <SongsArtists> songsArtists = songsArtistsRepo.GetAll(sa => sa.SongId == song.Id); List <Artist> artists = new List <Artist>(); foreach (SongsArtists songArtistItem in songsArtists) { int artistId = songArtistItem.ArtistId; Artist artist = artistsRepo.GetAll(a => a.Id == songArtistItem.ArtistId).FirstOrDefault(); artists.Add(artist); } if (artists.Count == 1) { Console.WriteLine("Artist: {0}", artists[0].Name); } else { Console.Write("Artists: "); int end = artists.Count - 1; for (int i = 0; i < end; i++) { Console.WriteLine("{0}, ", artists[i].Name); } Console.WriteLine(artists[end]); } Console.WriteLine("********************************"); } if (calledFromSongsView) { Console.ReadKey(true); } return(true); }
public void AddSong() { var mockSet = new Mock <DbSet <Song> >(); var mockContext = new Mock <DatabaseContext>(); mockContext.Setup(m => m.Songs).Returns(mockSet.Object); var service = new SongsRepository(mockContext.Object); service.AddSong(testSong); mockSet.Verify(m => m.Add(testSong), Times.Once()); mockContext.Verify(m => m.SaveChanges(), Times.Once()); }
private void buttonSeePerfomances_Click(object sender, EventArgs e) { ISongsRepository songsRep = new SongsRepository(); List <PerformedSongModel> songs = songsRep.GetAllPSongs().ToList(); listPerfomances.Items.Clear(); foreach (PerformedSongModel song in songs) { string toList = "Performance id:" + song.PerformanceId + ", Song name:" + song.SongName + ", Circumstances of perfomance:" + song.CircumstancesOfPerfomance + ", Author id:" + song.AuthorId; listPerfomances.Items.Add(toList); } }
private void GetAll() { Console.Clear(); SongsRepository songsRepository = new SongsRepository("songs.txt"); List <Entity.Song> songs = songsRepository.GetAll(AuthenticationService.LoggedUser.Id); foreach (Entity.Song song in songs) { Console.WriteLine("ID:" + song.Id); Console.WriteLine("Title :" + song.Title); Console.WriteLine("Artist Name :" + song.ArtistName); Console.WriteLine("Year :" + song.Year + "y"); Console.WriteLine("------------------------------------"); } Console.ReadKey(true); }
private void GetAll() { Console.Clear(); SongsRepository songsRepository = new SongsRepository(Properties.Settings.Default.FileSongs); UsersRepository usersRepository = new UsersRepository(Properties.Settings.Default.FileUsers); List <Playlist> playlist = _playlistRepository.GetAll(); List <Song> songs = songsRepository.GetAll(); List <User> users = usersRepository.GetAll(); foreach (Playlist playlistitem in playlist) { var owners = users.Where(x => playlistitem.UserOwnerId.Equals(x.Id)).ToList(); foreach (User ownerUser in owners) { Console.WriteLine("_______________________________________"); Console.WriteLine("\tOwner Username: "******"\tPlaylist ID : " + playlistitem.Id); Console.WriteLine("\tPlaylist Name : " + playlistitem.Name); Console.WriteLine("\tPlaylist Public : " + playlistitem.IsPublic); Console.WriteLine("_______________________________________"); var songsForThisPlayList = songs.Where(x => playlistitem.SongsIts.Contains(x.Id)).ToList(); foreach (Song songitem in songsForThisPlayList) { Console.WriteLine("---------------------------------------"); Console.WriteLine("\tSong ID : " + songitem.Id); Console.WriteLine("\tSong Name : " + songitem.ArtistName); Console.WriteLine("\tSong Title : " + songitem.Title); Console.WriteLine("\tSong Year : " + songitem.Year); } Console.WriteLine("---------------------------------------"); Console.WriteLine("\n"); } Console.ReadKey(true); }
public void CreateSong() { Console.Clear(); CreateSong: Song newSong = new Song(); Console.Write("Enter new song's title: "); string inputSongTitle = Console.ReadLine(); if (inputSongTitle.Length == 0) { Console.WriteLine("Song title cannot be empty. Try again!!"); Console.ReadKey(true); goto CreateSong; } newSong.Title = inputSongTitle; Console.Write("Enter song release year: "); short inputYear; bool isShort = short.TryParse(Console.ReadLine(), out inputYear); while (isShort == false) { Console.WriteLine("Year should be a digit. Try again!!"); Console.Write("Enter song release year: "); isShort = short.TryParse(Console.ReadLine(), out inputYear); } if ((short)DateTime.Now.Year < inputYear || inputYear < 1850) { Console.WriteLine("Input year cannot be before 1500 or after the current year. Try again!!"); Console.Write("Enter song release year: "); isShort = short.TryParse(Console.ReadLine(), out inputYear); } newSong.Year = inputYear; SongsRepository songsRepo = new SongsRepository(Constants.SongsPath); songsRepo.Save(newSong); Console.WriteLine("Song saved successfully!!"); Console.ReadKey(true); }
public void DeleteSong() { bool hasSongs = ViewSongs(); //TODO: Refactore with do...while loop or simple while loop like in the bookmarked while loop. if (hasSongs == false) { return; } Console.WriteLine(); Console.Write("Enter id to delete: "); int deleteId = Convert.ToInt32(Console.ReadLine()); SongsArtistsRepository songsArtistsRepo = new SongsArtistsRepository(Constants.SongsArtistsPath); List <SongsArtists> songsArtistsEntities = songsArtistsRepo.GetAll(sa => sa.SongId == deleteId); foreach (SongsArtists songArtistEntity in songsArtistsEntities) { songsArtistsRepo.Delete(songArtistEntity); } SongsRepository songsRepo = new SongsRepository(Constants.SongsPath); Song songToDelete = songsRepo.GetAll(s => s.Id == deleteId).FirstOrDefault(); if (songToDelete == null) { Console.WriteLine("There is no song with that Id."); Console.ReadKey(true); return; } PlaylistsSongsRepository playlistsSongsRepo = new PlaylistsSongsRepository(Constants.PlaylistsSongsPath); List <PlaylistsSongs> playlistsSongsEntities = playlistsSongsRepo.GetAll(pse => pse.SongId == deleteId); foreach (PlaylistsSongs playlistSongsEntity in playlistsSongsEntities) { playlistsSongsRepo.Delete(playlistSongsEntity); } songsRepo.Delete(songToDelete); Console.WriteLine("Song deleted successfully!"); Console.ReadKey(true); }
private void Delete() { SongsRepository songsRepository = new SongsRepository("songs.txt"); Console.Clear(); Console.WriteLine("Delete Task:"); Console.Write("Task Id: "); int taskId = Convert.ToInt32(Console.ReadLine()); Entity.Song song = songsRepository.GetById(taskId); if (song == null) { Console.WriteLine("Song not found!"); } else { songsRepository.Delete(song); Console.WriteLine("Song deleted successfully."); } Console.ReadKey(true); }
private void Add() { Console.Clear(); Entity.Playlist playlist = new Entity.Playlist(); playlist.ParentUserId = AuthenticationService.LoggedUser.Id; PlaylistRepository playlistRepository = new PlaylistRepository("playlist.txt"); Console.WriteLine("Add new Playlist:"); Console.Write("Name: "); playlist.Name = Console.ReadLine(); Console.Write("Description: "); playlist.Description = Console.ReadLine(); Console.Write("Add Song by Song ID :"); int songId = Convert.ToInt32(Console.ReadLine()); SongsRepository songsRepository = new SongsRepository("songs.txt"); Entity.Song song = songsRepository.GetById(songId); if (song == null) { Console.Clear(); Console.WriteLine("Song not found."); Console.ReadKey(true); return; } playlist.Songs = song.Title + ", " + song.ArtistName + ", " + song.Year + " y."; Console.Write("IsPublic: "); playlist.IsPublic = Convert.ToBoolean(Console.ReadLine()); playlistRepository.Save(playlist); Console.WriteLine("Playlist saved successfully."); Console.ReadKey(true); Console.WriteLine("-------------------------------------------"); }
private void buttonDeletePerformance_Click(object sender, EventArgs e) { if (textBoxDeleteId.Text == "") { MessageBox.Show("Wrong input!"); return; } ISongsRepository songsRep = new SongsRepository(); bool flag = songsRep.DeletePSong(Convert.ToInt32(textBoxDeleteId.Text)); if (flag) { MessageBox.Show("Deleted!"); } else { MessageBox.Show("Error!"); } textBoxDeleteId.Text = ""; }
public void GetSongs() { var data = new List <Song> { testSong }.AsQueryable(); var mockSet = new Mock <DbSet <Song> >(); mockSet.As <IQueryable <Song> >().Setup(m => m.Provider).Returns(data.Provider); mockSet.As <IQueryable <Song> >().Setup(m => m.Expression).Returns(data.Expression); mockSet.As <IQueryable <Song> >().Setup(m => m.ElementType).Returns(data.ElementType); mockSet.As <IQueryable <Song> >().Setup(m => m.GetEnumerator()).Returns(data.GetEnumerator()); var mockContext = new Mock <DatabaseContext>(); mockContext.Setup(c => c.Songs).Returns(mockSet.Object); var service = new SongsRepository(mockContext.Object); var blogs = service.GetSongs(); Assert.AreEqual(1, blogs.Count()); }
public App(string dbPath, ISQLitePlatform sqlitePlatform) { InitializeComponent(); SongRepo = new SongsRepository(sqlitePlatform, dbPath); if (UseMockDataStore) { DependencyService.Register <MockDataStore>(); } else { DependencyService.Register <CloudDataStore>(); } if (Device.RuntimePlatform == Device.iOS) { MainPage = new MainPage(); } else { MainPage = new NavigationPage(new MainPage()); } }
private void Update() { Console.Clear(); Console.Write("Playlist ID: "); int playlistId = Convert.ToInt32(Console.ReadLine()); PlaylistRepository playlistRepository = new PlaylistRepository("playlist.txt"); Entity.Playlist playlist = playlistRepository.GetById(playlistId); if (playlist == null) { Console.Clear(); Console.WriteLine("Playlist not found."); Console.ReadKey(true); return; } Console.WriteLine("Editing Playlist (" + playlist.Name + ")"); Console.WriteLine("ID:" + playlist.Id); Console.WriteLine("Name :" + playlist.Name); Console.Write("New Name:"); string Name = Console.ReadLine(); Console.WriteLine("Description :" + playlist.Description); Console.Write("New Description :"); string Description = Console.ReadLine(); Console.WriteLine("IsPublic :" + playlist.IsPublic); Console.Write("New IsPublic :"); string IsPublic = Console.ReadLine(); Console.WriteLine("Add or Remove songs ?"); string answer = Console.ReadLine(); if (answer.ToLower() == "add") { Console.Write("Add Song by Song ID :"); int songId = Convert.ToInt32(Console.ReadLine()); SongsRepository songsRepository = new SongsRepository("songs.txt"); Entity.Song song = songsRepository.GetById(songId); if (song == null) { Console.Clear(); Console.WriteLine("Song not found."); Console.ReadKey(true); return; } playlist.Songs += " / " + song.Title + ", " + song.ArtistName + ", " + song.Year + " y."; Console.WriteLine("You add the song : " + song.Title + ", " + song.ArtistName + ", " + song.Year + " y. to your playlist!"); } else if (answer.ToLower() == "remove") { Console.Write("Remove Song by Song Index in Playlist :"); int songId = Convert.ToInt32(Console.ReadLine()); //playlist.Songs; } if (!string.IsNullOrEmpty(Name)) { playlist.Name = Name; } if (!string.IsNullOrEmpty(Description)) { playlist.Description = Description; } playlistRepository.Save(playlist); Console.WriteLine("Playlist saved successfully."); Console.ReadKey(true); }
public void AddSong() { string inputSongTitle; bool isEmptyName = false; do { Console.Clear(); Console.Write("Enter new song name: "); inputSongTitle = Console.ReadLine(); isEmptyName = (String.IsNullOrWhiteSpace(inputSongTitle)); if (isEmptyName == true) { Console.WriteLine("Song title cannot be empty. Try again!!"); Console.ReadKey(true); } }while (isEmptyName == true); short inputSongReleaseYear; bool isShortYear; bool isBeforeCurrentYear = false; do { Console.Write("Enter song's release year: "); isShortYear = short.TryParse(Console.ReadLine(), out inputSongReleaseYear); if (DateTime.Now.Year >= inputSongReleaseYear) { isBeforeCurrentYear = true; } if (isShortYear == false) { Console.WriteLine("Year can only be an integer number. Try again!!"); Console.ReadKey(true); } if (isBeforeCurrentYear == false) { Console.WriteLine("Year should not be after the current year."); } } while (isShortYear == false || isBeforeCurrentYear == false); Song newSong = new Song(); newSong.Title = inputSongTitle; newSong.Year = inputSongReleaseYear; SongsRepository songsRepo = new SongsRepository(Constants.SongsPath); if (songsRepo.EntityExists(s => s.Title == inputSongTitle && s.Year == inputSongReleaseYear)) { Console.WriteLine("The song already exists in the database!"); Console.ReadKey(true); } int songId = songsRepo.Save(newSong); ArtistsRepository artistsRepo = new ArtistsRepository(Constants.ArtistsPath); List <Artist> artists = artistsRepo.GetAll(); Console.Clear(); int artistId; if (artists.Count == 0) { artistId = ArtistsView.AddArtist(); } else { foreach (Artist artistEntity in artists) { Console.WriteLine("************************************"); Console.WriteLine("Id: {0}", artistEntity.Id); Console.WriteLine("Artist name: {0}", artistEntity.Name); Console.WriteLine("************************************"); } Console.WriteLine(); EnterArtistId: Console.Write("Enter new song's artist id (type \"0\" if not in the list): "); bool isInt = int.TryParse(Console.ReadLine(), out artistId); while (isInt == false) { Console.WriteLine("IDs can only be integer numbers. Try Again!!"); Console.ReadKey(true); goto EnterArtistId; } if (artistId == 0) { artistId = ArtistsView.AddArtist(); } } SongsArtists songArtistEntity = new SongsArtists(); songArtistEntity.SongId = songId; songArtistEntity.ArtistId = artistId; SongsArtistsRepository songsArtistsRepo = new SongsArtistsRepository(Constants.SongsArtistsPath); songsArtistsRepo.Save(songArtistEntity); Console.WriteLine("Song saved successfully!"); Console.ReadKey(true); }
public void Setup() { ISongsRepository songsRepository = new SongsRepository(Songs); _searchService = new SearchService(songsRepository); }
/// <summary> /// Initializes a new instance of the <see cref="SongsController"/> class. /// </summary> public SongsController() { // TODO: Use dependency injection - Brian Dorgan - 2/16/2018 this.repository = new SongsRepository(); }
public HomeController(SongsRepository songsRepo) { _songsRepo = songsRepo; }
public void EditSong() { bool hasSongs = ViewSongs(); if (hasSongs == false) { return; } Console.WriteLine(); int editId; bool isIntId; do { Console.Write("Enter song id to edit: "); isIntId = int.TryParse(Console.ReadLine(), out editId); if (isIntId == false) { Console.WriteLine("IDs can only be integer numbers. Try again!!"); Console.ReadKey(true); } }while (isIntId == false); SongsRepository songRepo = new SongsRepository(Constants.SongsPath); Song song = songRepo.GetAll(s => s.Id == editId).FirstOrDefault(); if (song == null) { Console.WriteLine("No song with that Id exists!"); Console.ReadKey(true); return; } Console.Clear(); Console.WriteLine("Old song title: {0}", song.Title); string newSongTitle; bool isEmptyName; do { Console.Write("New song title: "); newSongTitle = Console.ReadLine(); isEmptyName = string.IsNullOrWhiteSpace(newSongTitle); if (isEmptyName) { Console.WriteLine("Song name cannot be empty. Try again!!"); Console.ReadKey(); } } while (isEmptyName == true); song.Title = newSongTitle; short newSongReleaseYear; bool isIntYear = false; bool isCurrentOrPastYear = false; Console.WriteLine("Old song release year: {0}", song.Year); do { Console.Write("New song release year: "); isIntYear = short.TryParse(Console.ReadLine(), out newSongReleaseYear); if (isIntYear == false) { Console.WriteLine("Song release year can only be an integer number. Try Again!!"); Console.ReadKey(); } if (DateTime.Now.Year >= newSongReleaseYear) { isCurrentOrPastYear = true; } if (isCurrentOrPastYear == false) { Console.WriteLine("Song release year cannot be after the current year. Try again!!"); Console.ReadKey(true); } } while (isIntYear == false || isCurrentOrPastYear == false); song.Year = newSongReleaseYear; songRepo.Save(song); Console.WriteLine("Song edited successfully!"); Console.ReadKey(true); }
public SongsService(SongsRepository repo) { _repo = repo; }
public SongsController() { _db = new MusicDb(); _songsRepository = new SongsRepository(); }