private Quiz AddQuizToDatabase(QuizModel model) { var quiz = mapper.Map <Quiz>(model); quiz.TestId = testId; quiz = context.Quizes.Add(quiz); context.SaveChanges(); return(quiz); }
private void OnCascadeDelete(Guid testId) { var test = context.Tests.FirstOrDefault(t => t.Id == testId); if (test != null) { context.Tests.Remove(test); context.SaveChanges(); } }
private void UpdateUsersInDatabase(List <ApplicationUser> users) { foreach (var user in users) { context.Users.AddOrUpdate(user); } context.SaveChanges(); }
private void RegisterUser(RegistrationModel model) { model.Password = HashGenerator.GenerateHash(model.Password); ApplicationUser appUser = mapper.Map <RegistrationModel, ApplicationUser>(model); appUser.RoleId = context.Roles.First(r => r.RoleName.Equals("User")).Id; context.Users.Add(appUser); context.SaveChanges(); }
private void AddProgress(Guid testId, int progress) { var result = context.UserTestsResults.Add(new UserTestResult { ApplicationUserId = user.Id, CompletionDate = DateTime.Now, Mark = progress, TestId = testId }); context.SaveChanges(); ShowProgressWindow(result.Id); }
private void InitializeLanguages(EF.ApplicationContext db) { db.Languages.AddOrUpdate(new Language { Name = "Русский", Code = "ru", FlagImagePath = "ru.png", }); db.Languages.AddOrUpdate(new Language { Name = "English", Code = "en", FlagImagePath = "en.png", }); db.Languages.AddOrUpdate(new Language { Name = "Deutsch", Code = "de", FlagImagePath = "de.png", }); db.Languages.AddOrUpdate(new Language { Name = "French", Code = "fr", FlagImagePath = "fr.png", }); db.Languages.AddOrUpdate(new Language { Name = "Español", Code = "es", FlagImagePath = "es.png", }); db.Languages.AddOrUpdate(new Language { Name = "Italian", Code = "it", FlagImagePath = "it.png", }); db.SaveChanges(); }