示例#1
0
 public void UpdateTimeInApp(int time, string login)
 {
     using (GuitarHelperDBContext context = new GuitarHelperDBContext())
     {
         var userInfo = context.Users.SingleOrDefault(user => user.Login == login);
         userInfo.TimeInApp += time;
         context.SaveChanges();
     }
 }
示例#2
0
 public void AddInFavorite(string login, string nameSong)
 {
     using (GuitarHelperDBContext context = new GuitarHelperDBContext())
     {
         var userInfo = context.Users.SingleOrDefault(user => user.Login == login);
         var newSong  = context.Songs.SingleOrDefault(song => song.Name == nameSong);
         userInfo.FavoritesSongs += $"{newSong.SongID} ";
         context.SaveChanges();
     }
 }
示例#3
0
 public void DeleteSong(string name)
 {
     using (GuitarHelperDBContext context = new GuitarHelperDBContext())
     {
         Songs song = context.Songs.Where(s => s.Name == name).FirstOrDefault();
         context.Songs.Remove(song);
         context.SaveChanges();
     }
     SelectSongs();
 }
示例#4
0
        public void AddSong(string name, string text)
        {
            Songs newSong = new Songs();

            newSong.Name = name;
            newSong.Text = text;
            using (GuitarHelperDBContext context = new GuitarHelperDBContext())
            {
                context.Songs.Add(newSong);
                context.SaveChanges();
            }
        }
示例#5
0
 public void UpdateUserAvatar(string oldName, string newAvatar)
 {
     using (GuitarHelperDBContext context = new GuitarHelperDBContext())
     {
         foreach (var user in context.Users)
         {
             if (oldName == user.Login)
             {
                 user.Avatar = newAvatar;
             }
         }
         context.SaveChanges();
     }
 }
示例#6
0
 public void UpdateUserPass(string oldName, string newPass)
 {
     using (GuitarHelperDBContext context = new GuitarHelperDBContext())
     {
         foreach (var user in context.Users)
         {
             if (oldName == user.Login)
             {
                 user.Password = GetHash(newPass);
             }
         }
         context.SaveChanges();
     }
 }
示例#7
0
 public void DeleteFromFavorite(string login, string nameSong)
 {
     using (GuitarHelperDBContext context = new GuitarHelperDBContext())
     {
         var        userInfo       = context.Users.SingleOrDefault(user => user.Login == login);
         var        curentSong     = context.Songs.SingleOrDefault(song => song.Name == nameSong);
         List <int> favoritesSongs = GetFavoriteSongList(login);
         favoritesSongs.Remove(curentSong.SongID);
         string favInDB = "";
         foreach (var songId in favoritesSongs)
         {
             favInDB += songId + " ";
         }
         userInfo.FavoritesSongs = favInDB;
         context.SaveChanges();
     }
 }
示例#8
0
        public bool RecoveryPass(string login, string recoveryCode, string newPass)
        {
            bool result = false;

            using (GuitarHelperDBContext context = new GuitarHelperDBContext())
            {
                var userInfo = context.Users.SingleOrDefault(user => user.Login == login);
                if (recoveryCode == userInfo.RecoveryCode)
                {
                    MessageBox.Show("Пароль успешно изменен");
                    userInfo.Password = GetHash(newPass);
                }
                else
                {
                    result = false;
                    MessageBox.Show("Не верный кол воостановления, поворите попытку!");
                }
                context.SaveChanges();
            }
            return(result);
        }
示例#9
0
        public async Task <bool> SingUp(string login, string password)
        {
            bool result = true;

            Random rand    = new Random();
            Users  newUser = new Users();

            newUser.Login          = login;
            newUser.Password       = GetHash(password);
            newUser.Avatar         = @"NoAvatar.png";
            newUser.TimeInApp      = 0;
            newUser.FavoritesSongs = "";
            newUser.RecoveryCode   = rand.Next(10000, 99999).ToString();
            using (GuitarHelperDBContext context = new GuitarHelperDBContext())
            {
                foreach (var user in context.Users)
                {
                    if (login == user.Login)
                    {
                        MessageBox.Show("Пользователь с таким именем уже сущесвует!");
                        result = false;
                    }
                }
                if (result)
                {
                    context.Users.Add(newUser);
                    context.SaveChanges();
                    MessageBox.Show("Пользователь успешно зарегистрирован!");
                    return(result);
                }
                else
                {
                    return(result);
                }
            }
        }