private void AddDataOnClick(object sender, RoutedEventArgs e) { using var context = new MusicalQuizDbContext(); var userDmytro = new User() { Username = $"User{context.Users.Count() + 1}", Password = $"PaswordHash{context.Users.Count() + 1}", AppRating = context.Users.Count() % 6, Quizzes = new List <Quiz>() }; context.Users.Add(userDmytro); context.Genres.AddRange( new Genre() { Name = $"Rock{context.Users.Count() + 1}" }, new Genre() { Name = $"Rap{context.Users.Count() + 1}" }); context.SaveChanges(); var quiz = new Quiz() { Title = $"Rock generation {context.Users.Count() + 1}", Genre = context.Genres.FirstOrDefault(g => g.Name.Equals($"Rock{context.Users.Count()}")), AnswerTime = context.Users.Count() + 1, PlayTime = context.Users.Count() + 1 % 26 <= 2 ? 2 : context.Users.Count() + 1 % 26, QuizSongs = new List <QuizSong>() { new QuizSong { Song = new Song() { Link = $"https:/spotify.web.api/some/track/{context.Users.Count()}" } } } }; context.Quizzes.Add(quiz); userDmytro.Quizzes.Add(quiz); context.SaveChanges(); userDmytro.Scores.Add(new Score() { Quiz = userDmytro.Quizzes.First(), Points = context.Users.Count() }); context.SaveChanges(); LoadData(); }
private void CleanDataOnClick(object sender, RoutedEventArgs e) { using var context = new MusicalQuizDbContext(); context.Users.RemoveRange(context.Users.ToList()); context.Genres.RemoveRange(context.Genres.ToList()); context.Songs.RemoveRange(context.Songs.ToList()); context.SaveChanges(); LoadData(); }