예제 #1
0
        private Quiz AddQuizToDatabase(QuizModel model)
        {
            var quiz = mapper.Map <Quiz>(model);

            quiz.TestId = testId;
            quiz        = context.Quizes.Add(quiz);
            context.SaveChanges();
            return(quiz);
        }
예제 #2
0
        private void OnCascadeDelete(Guid testId)
        {
            var test = context.Tests.FirstOrDefault(t => t.Id == testId);

            if (test != null)
            {
                context.Tests.Remove(test);
                context.SaveChanges();
            }
        }
예제 #3
0
 private void UpdateUsersInDatabase(List <ApplicationUser> users)
 {
     foreach (var user in users)
     {
         context.Users.AddOrUpdate(user);
     }
     context.SaveChanges();
 }
예제 #4
0
        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();
        }
예제 #5
0
        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);
        }
예제 #6
0
        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();
        }