/// <summary>
 /// This methods finds user based on forwarded username and password.
 /// </summary>
 /// <param name="username">User username.</param>
 /// <param name="password">User password.</param>
 /// <returns>User.</returns>
 public vwUser FindUser(string username, string password)
 {
     try
     {
         using (AudioPlayerEntities context = new AudioPlayerEntities())
         {
             return(context.vwUsers.Where(x => x.Username == username && x.Password == password).FirstOrDefault());
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine("Exception" + ex.Message.ToString());
         return(null);
     }
 }
 public List <vwSong> GetUserSongs(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);
     }
 }
 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>
 /// This methods add user to DbSet and save changes to database.
 /// </summary>
 /// <param name="username">Username.</param>
 /// <param name="password">Password.</param>
 /// <returns>True if user is created, false if not.</returns>
 public bool CreateUser(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>
 /// This method checks if forwarded username unique.
 /// </summary>
 /// <param name="username">Username.</param>
 /// <returns>True if unique, false if not.</returns>
 public bool IsUsernameUnique(string username)
 {
     try
     {
         using (AudioPlayerEntities context = new AudioPlayerEntities())
         {
             var list = context.vwUsers.Where(x => x.Username == username).ToList();
             //if exists user with forwarded username, return false
             if (list.Count() > 0)
             {
                 return(false);
             }
             else
             {
                 return(true);
             }
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine("Exception" + ex.Message.ToString());
         return(false);
     }
 }
 public bool CreateSong(vwUser user, vwSong song)
 {
     try
     {
         using (AudioPlayerEntities context = new AudioPlayerEntities())
         {
             tblSong newSong = new tblSong
             {
                 Author   = song.Author,
                 Duration = song.Duration,
                 Name     = song.Name,
                 UserId   = user.UserId
             };
             context.tblSongs.Add(newSong);
             context.SaveChanges();
             return(true);
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine("Exception" + ex.Message.ToString());
         return(false);
     }
 }