public async Task<ActionResult> Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                ApplicationUser user =
                    new ApplicationUser
                    {
                        UserName = model.Login,
                        FirstName = model.FirstName,
                        LastName = model.LastName,
                        Patronymic = model.Patronymic,
                        Position = model.Position,
                        Email = model.Email
                    };

                IdentityResult result = await UserManager.CreateAsync(user, model.Password);
                if (result.Succeeded)
                {
                    FullName = user.FirstName + " " + user.LastName;
                    UserId = user.Id;

                    await UserManager.AddToRoleAsync(UserId, "User");
                    return RedirectToAction("Index", "Home");
                }
                else
                {
                    foreach (string error in result.Errors)
                    {
                        ModelState.AddModelError("", error);
                    }
                }
            }
            return View(model);
        }
        public User Register(RegisterModel registerModel)
        {
            if (_usersRepository.GetAll(user => user.UserName == registerModel.Login).Count() == 0)
            {
                _usersRepository.Add(new User
                {
                    FirstName = registerModel.FirstName,
                    LastName = registerModel.LastName,
                    Patronymic = registerModel.Patronymic,
                    UserName = registerModel.Login,
                    PositionId = registerModel.PositionId,
                    Password = registerModel.Password,
                    Email = registerModel.Email,
                    RoleId = 2 //user
                });

                return _usersRepository.GetAll(user => user.UserName == registerModel.Login).First();
            }
            return null;
        }
        public ActionResult Register(RegisterModel model)
        {
            if (!ModelState.IsValid) return View(model);

            var user = Mapper.Map<BlModels.User, User>
                (_usersRepositoryHandler.GetUserByEmail(model.Email));

            if (user == null)
            {
                _usersRepositoryHandler.Add(
                    new BlModels.User
                    {
                        Email = model.Email,
                        FirstName = model.FirstName,
                        LastName = model.LastName,
                        Patronymic = model.Patronymic,
                        Role = _rolesRepositoryHandler.FindByName("User"),
                        Position = _positionsRepositoryHandler.FindById(model.PositionId),
                        Password = model.Password,
                        UserName = model.Email
                    });

                return RedirectToAction("Login", "Account");
            }

            ModelState.AddModelError("", "Пользователь с такой почтой уже существует");
            return View(model);
        }