Ejemplo n.º 1
0
        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));
        }
Ejemplo n.º 2
0
        public ActionResult Edit(EditUserModel model)
        {
            var user = GetUser();

            if (user != null)
            {
                user.Email      = model.Email;
                user.UserName   = model.Login;
                user.FirstName  = model.FirstName;
                user.LastName   = model.LastName;
                user.Patronymic = model.Patronymic;
                user.Position   = _positionsRepositoryHandler.FindById(model.PositionId);

                _usersRepositoryHandler.Update(user);
                return(RedirectToAction("Index", "Main"));
            }
            ModelState.AddModelError("", "Не удалось найти пользователя. Попробуйте еще раз.");
            return(RedirectToAction("Index", "Main"));
        }