/// <summary> /// Deletes the song from tblSong in the database /// </summary> /// <param name="song"></param> internal void DeleteSong(tblSong song) { using (AudioPlayerEntities context = new AudioPlayerEntities()) { tblSong songToDelete = (from s in context.tblSongs where s.SongID == song.SongID select s).First(); context.tblSongs.Remove(songToDelete); context.SaveChanges(); } }
/// <summary> /// Returns am user with UserName as parameter. /// </summary> /// <param name="userName"></param> /// <returns></returns> internal tblUser GetUser(string userName) { tblUser user = new tblUser(); using (AudioPlayerEntities context = new AudioPlayerEntities()) { user = (from u in context.tblUsers where u.UserName == userName select u).First(); } return(user); }
/// <summary> /// Returns list of songs with user's ID. /// </summary> /// <param name="userName"></param> /// <returns></returns> internal List <tblSong> GetUserSongs(string userName) { List <tblSong> list = new List <tblSong>(); using (AudioPlayerEntities context = new AudioPlayerEntities()) { tblUser user = (from u in context.tblUsers where u.UserName == userName select u).First(); list = (from s in context.tblSongs where s.UserID == user.UserID select s).ToList(); } return(list); }
/// <summary> /// Adds an user to the data base /// </summary> /// <param name="userName"></param> /// <param name="password"></param> internal tblUser AddUser(string userName, string password) { using (AudioPlayerEntities context = new AudioPlayerEntities()) { tblUser user = new tblUser(); user.UserName = userName; user.Pass = password; context.tblUsers.Add(user); context.SaveChanges(); return(user); } }
/// <summary> /// Adds a song to the database. /// </summary> /// <param name="song"></param> /// <param name="user"></param> internal void AddSong(tblSong song, int userID) { using (AudioPlayerEntities context = new AudioPlayerEntities()) { tblSong newSong = new tblSong(); newSong.SongName = song.SongName; newSong.Author = song.Author; newSong.DurationInSeconds = song.DurationInSeconds; newSong.UserID = userID; context.tblSongs.Add(newSong); context.SaveChanges(); } }
public List <Song> GetAllSongs() { try { using (AudioPlayerEntities context = new AudioPlayerEntities()) { return((from x in context.Songs select x).ToList()); } } catch (Exception ex) { MessageBox.Show("Exception " + ex.Message.ToString(), "Error", MessageBoxButton.OK, MessageBoxImage.Error); return(null); } }
/// <summary> /// Checks if user with userName and password exists in the database. /// </summary> /// <param name="userName"></param> /// <param name="password"></param> /// <returns></returns> internal bool IsUser(string userName, string password) { try { using (AudioPlayerEntities context = new AudioPlayerEntities()) { tblUser user = (from u in context.tblUsers where u.UserName == userName && u.Pass == password select u).First(); return(true); } } catch { return(false); } }
/// <summary> /// Gets all songs of a logged in user from database /// </summary> /// <returns>list of songs</returns> public List <vwSong> GetUsersSongs(vwUser user) { try { using (AudioPlayerEntities context = new AudioPlayerEntities()) { return(context.vwSongs.Where(x => x.UserId == user.UserId).ToList()); } } catch (Exception ex) { Debug.WriteLine("Exception" + ex.Message.ToString()); return(null); } }
/// <summary> /// Gets user by forwarded username. /// </summary> /// <param name="username">User's username</param> /// <returns>User.</returns> public vwUser GetUserByUsername(string username) { try { using (AudioPlayerEntities context = new AudioPlayerEntities()) { return(context.vwUsers.Where(x => x.Username == username).FirstOrDefault()); } } catch (Exception ex) { Debug.WriteLine("Exception" + ex.Message.ToString()); return(null); } }
public Song GetSong(int ID) { try { using (AudioPlayerEntities context = new AudioPlayerEntities()) { return((from x in context.Songs where x.SongID == ID select x).FirstOrDefault()); } } catch (Exception ex) { MessageBox.Show("Exception " + ex.Message.ToString(), "Error", MessageBoxButton.OK, MessageBoxImage.Error); return(null); } }
public void DeleteSong(int ID) { try { using (AudioPlayerEntities context = new AudioPlayerEntities()) { context.Songs.Remove((from x in context.Songs where x.SongID == ID select x).FirstOrDefault()); context.SaveChanges(); MessageBox.Show("Action successfull!", "Success", MessageBoxButton.OK, MessageBoxImage.Information); } } catch (Exception ex) { MessageBox.Show("Exception " + ex.Message.ToString(), "Error", MessageBoxButton.OK, MessageBoxImage.Error); } }
public void AddSong(Song song) { try { using (AudioPlayerEntities context = new AudioPlayerEntities()) { context.Songs.Add(song); context.SaveChanges(); MessageBox.Show("Action successfull!", "Success", MessageBoxButton.OK, MessageBoxImage.Information); } } catch (Exception ex) { MessageBox.Show("Exception " + ex.Message.ToString(), "Error", MessageBoxButton.OK, MessageBoxImage.Error); } }
public void UpdateAppUser(AppUser au) { try { using (AudioPlayerEntities context = new AudioPlayerEntities()) { AppUser user = (from x in context.AppUsers where x.AppUserID == au.AppUserID select x).FirstOrDefault(); user = au; context.SaveChanges(); MessageBox.Show("Action successfull!", "Success", MessageBoxButton.OK, MessageBoxImage.Information); } } catch (Exception ex) { MessageBox.Show("Exception " + ex.Message.ToString(), "Error", MessageBoxButton.OK, MessageBoxImage.Error); } }
/// <summary> /// Gets all played songs from database /// </summary> /// <returns>list of played songs</returns> public List <tblPlayedSong> GetAllPlayedSongs() { try { using (AudioPlayerEntities context = new AudioPlayerEntities()) { List <tblPlayedSong> list = new List <tblPlayedSong>(); list = (from x in context.tblPlayedSongs select x).ToList(); return(list); } } catch (Exception ex) { Debug.WriteLine("Exception" + ex.Message.ToString()); return(null); } }
/// <summary> /// Return username and password on database /// </summary> /// <param name="username"></param> /// <param name="password"></param> /// <returns></returns> public tblUser GetUsernamePassword(string username, string password) { try { using (AudioPlayerEntities context = new AudioPlayerEntities()) { tblUser user = (from e in context.tblUsers where e.UsernameUser.Equals(username) where e.PasswordUser.Equals(password) select e).First(); return(user); } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Exception" + ex.Message.ToString()); return(null); } }
/// <summary> /// Method for deleting song from database /// </summary> /// <param name="song"></param> /// <returns>true if deleted, false if not</returns> public bool DeleteSong(vwSong song) { try { using (AudioPlayerEntities context = new AudioPlayerEntities()) { var songToDelete = context.tblSongs.Where(x => x.SongId == song.SongId).FirstOrDefault(); context.tblSongs.Remove(songToDelete); context.SaveChanges(); return(true); } } catch (Exception ex) { Debug.WriteLine("Exception" + ex.Message.ToString()); return(false); } }
/// <summary> /// Adds the user /// </summary> /// <param name="username">Username</param> /// <param name="password">Password</param> /// <returns>true for created user, false if not</returns> public bool AddUser(string username, string password) { try { using (AudioPlayerEntities context = new AudioPlayerEntities()) { tblUser user = new tblUser { Password = password, Username = username }; context.tblUsers.Add(user); context.SaveChanges(); return(true); } } catch (Exception ex) { Debug.WriteLine("Exception" + ex.Message.ToString()); return(false); } }
/// <summary> /// Method for adding new User /// </summary> /// <param name="user"></param> /// <returns></returns> public tblUser AddUser(tblUser user) { try { using (AudioPlayerEntities context = new AudioPlayerEntities()) { if (user.UserID == 0) { tblUser newUser = new tblUser { UserID = user.UserID, UsernameUser = user.UsernameUser, PasswordUser = user.PasswordUser }; context.tblUsers.Add(newUser); context.SaveChanges(); user.UserID = newUser.UserID; return(user); } else { tblUser userToEdit = (from r in context.tblUsers where r.UserID == user.UserID select r).First(); userToEdit.UsernameUser = user.UsernameUser; userToEdit.PasswordUser = user.PasswordUser; context.SaveChanges(); return(user); } } } catch (Exception ex) { MessageBox.Show("Nešto je pošlo po zlu prilikom registracije", "Greška"); System.Diagnostics.Debug.WriteLine("Exception: " + ex.Message.ToString()); return(null); } }
/// <summary> /// Method for adding song by user /// </summary> /// <param name="user">user which is adding song</param> /// <param name="song">song for adding</param> /// <returns></returns> public bool AddSong(vwUser user, vwSong song) { try { using (AudioPlayerEntities context = new AudioPlayerEntities()) { tblSong newSong = new tblSong(); newSong.SongName = song.SongName; newSong.SongAuthor = song.SongAuthor; newSong.SongDuration = song.SongDuration; newSong.UserId = user.UserId; context.tblSongs.Add(newSong); context.SaveChanges(); song.SongId = newSong.SongId; return(true); } } catch (Exception ex) { Debug.WriteLine("Exception" + ex.Message.ToString()); return(false); } }