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(); } }
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(); } }
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(); }
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(); } }
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(); } }
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(); } }
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(); } }
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); }
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); } } }