Exemplo n.º 1
0
        public IActionResult Registration(RegistrationViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                return(View(viewModel));
            }

            var user = mapper.Map <CitizenUser>(viewModel);

            citizenUserRepository.Save(user);
            return(View());
        }
Exemplo n.º 2
0
        private void AddIfNotExistUsersWithRole(List <CitizenUser> users, string roleName = null)
        {
            foreach (var user in users.Where(u => !citizenUserRepository.UserExists(u.Login)))
            {
                if (roleName != null)
                {
                    var role = roleRepository.GetRoleByName(roleName);
                    user.Roles.Add(role);
                }

                citizenUserRepository.Save(user);
            }
        }
Exemplo n.º 3
0
        public IActionResult SignUp(UserVerificationViewModel model)
        {
            var user = cuRepo.GetUserByLogin(User.Identity.Name);

            if (ValidateItems(user.BirthDate >= new DateTime(1930, 1, 1), model.BirthdateCapable))
            {
                user.BirthDate = model.Birthdate;
            }

            if (ValidateItems(user.Gender != Gender.NotChosen, model.Gender != Gender.NotChosen))
            {
                user.Gender = model.Gender;
            }

            if (ValidateItems(!string.IsNullOrEmpty(user.FirstName), !string.IsNullOrEmpty(model.FirstName)))
            {
                user.FirstName = model.FirstName;
            }

            if (ValidateItems(!string.IsNullOrEmpty(user.LastName), !string.IsNullOrEmpty(model.LastName)))
            {
                user.LastName = model.LastName;
            }

            cuRepo.Save(user);
            pmRepo.MakePolicemanFromUser(user);

            return(RedirectToAction("VerifyUser"));
        }
Exemplo n.º 4
0
        public IActionResult Profile(ProfileViewModel profileViewModel)
        {
            var citizen = mapper.Map <CitizenUser>(profileViewModel);

            citizenUserRepository.Save(citizen);
            return(View(profileViewModel));
        }
Exemplo n.º 5
0
        public IActionResult Registration(LoginViewModel viewModel)
        {
            var user = mapper.Map <CitizenUser>(viewModel);

            citizenUserRepository.Save(user);
            return(View());
        }
        public IActionResult MyCitizenTest(ForDHLoginViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                return(View(viewModel));
            }

            var user = mapper.Map <CitizenUser>(viewModel);

            citizenRepository.Save(user);
            return(View());
        }
Exemplo n.º 7
0
        public IActionResult Registration(LoginViewModel viewModel)
        {
            //var user = new CitizenUser()
            //{
            //    Login = viewModel.Login,
            //    Password = viewModel.Password
            //};
            var user = mapper.Map <CitizenUser>(viewModel);

            citizenUserRepository.Save(user);

            return(View());
        }
Exemplo n.º 8
0
        /// <summary>
        /// Creates specified number of unique users (actually creates less than that number because of limited names dictionoary)
        /// </summary>
        /// <param name="quantity">Number of new users required</param>
        /// <returns>Actual number of users created</returns>
        public int GenerateCitizenUsers(int quantity)
        {
            var rnd            = new Random();
            var firstNamesMale = new List <string>
            {
                "Ярослав", "Викентий", "Фёдор", "Клаус", "Степан", "Остин", "Нестор", "Йозеф", "Филипп", "Леопольд",
                "Герман", "Йоган", "Эрик", "Лукьян", "Остап", "Шамиль", "Захар", "Михаил",
            };
            var firstNamesFemale = new List <string>
            {
                "Харитина", "Надежда", "Татьяна", "Клара", "Богдана", "Ульяна", "Зинаида", "Белла", "Рада", "Надежда",
                "Мария", "Генриетта", "Бронислава", "Изольда", "Шарлота", "Эмилия", "Алла", "Цара", "Зоя", "Шарлота",
            };
            var lastNamesMale = new List <string>
            {
                "Котов", "Рыбаков", "Горшков", "Меркушев", "Фокин", "Матвеев", "Цушко", "Васильев", "Афанасьев", "Барановский",
                "Красинец", "Семёнов", "Новиков", "Горбачёв", "Шамрыло", "Игнатьев", "Гриневский", "Михеев", "Ермаков", "Филиппов",
            };
            var lastNamesFemale = new List <string>
            {
                "Петрова", "Пестова", "Шарапова", "Ярова", "Моисеенко", "Иващенко", "Моисеенко", "Гончар", "Кличко", "Петренко", "Шкраба",
                "Лазарева", "Егорова", "Права", "Вишнякова", "Белоусова", "Орлова", "Плаксий", "Милославска", "Данилова",
            };
            var ListOfFullNames = citizenUserRepository.GetAll()
                                  .Select(user => user.FirstName + " " + user.LastName).ToList();
            var ListOfRoles = roleRepository.GetAll();

            // количество попыток найти уникальное сочетание имя+фамилия
            var attemptNumber = 0;
            // количество успешных попыток найти уникальное сочетание имя+фамилия
            var successfulAttemptNumber = 0;


            do
            {
                string firstName;
                string lastName;
                var    isMale = rnd.Next(0, 2);


                if (isMale == 1)
                {
                    firstName = firstNamesMale[rnd.Next(firstNamesMale.Count)];
                    lastName  = lastNamesMale[rnd.Next(lastNamesMale.Count)];
                }
                else
                {
                    firstName = firstNamesMale[rnd.Next(firstNamesMale.Count)];
                    lastName  = lastNamesMale[rnd.Next(lastNamesMale.Count)];
                }

                var FullName = firstName + " " + lastName;
                if (!ListOfFullNames.Any(s => s == FullName))
                {
                    // имя-фамилия уникально, сохраняем
                    ListOfFullNames.Add(FullName);
                    var startBirthdate = new DateTime(1950, 1, 1);
                    var range          = (new DateTime(2010, 1, 1) - startBirthdate).Days;
                    var birthdate      = startBirthdate.AddDays(rnd.Next(range));

                    var newCitizen = new CitizenUser
                    {
                        Id        = 0,
                        Login     = firstName + "_" + lastName,
                        Password  = "******",
                        FirstName = firstName,
                        LastName  = lastName,
                        BirthDate = birthdate,
                        Gender    = isMale == 1 ? Gender.Male : Gender.Female,
                        Roles     = new List <Role>(),
                    };
                    newCitizen.Roles.Add(ListOfRoles[rnd.Next(ListOfRoles.Count)]);
                    citizenUserRepository.Save(newCitizen);
                    successfulAttemptNumber++;
                }
                // имя-фамилия не уникально, ищем другие
                attemptNumber++;
            }while (attemptNumber < quantity);
            return(successfulAttemptNumber);
        }
Exemplo n.º 9
0
 public void Save(CitizenUser user)
 {
     citizenUserRepository.Save(user);
 }