Esempio n. 1
0
 /// <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);
     }
 }
Esempio n. 2
0
 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);
     }
 }
Esempio n. 3
0
 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);
     }
 }
Esempio n. 4
0
 /// <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);
     }
 }
Esempio n. 5
0
 /// <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);
     }
 }
Esempio n. 6
0
 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);
     }
 }