예제 #1
0
        public IActionResult Register(RegisterInputModel model)
        {
            if (!ModelState.IsValid)
            {
                return(Redirect("/Users/Register"));
            }

            if (model.Password != model.ConfirmPassword)
            {
                ModelState.Add(string.Empty, "The passwords must match");
                return(Redirect("/Users/Register"));
            }

            if (usersService.UserExists(model.Username))
            {
                ModelState.Add(string.Empty, "User with the same username already exists!");
                return(Redirect("/Users/Register"));
            }

            User   user   = model.MapTo <User>();
            string userId = usersService.CreateUser(user);

            this.SignIn(userId, model.Username, model.Email);

            return(Redirect("/"));
        }
예제 #2
0
        public bool Delete(RegisterInputModel registerInputModel)
        {
            if (registerInputModel == null)
            {
                return(false);
            }

            var user = _userRepository.FirstOrDefault(u => u.UserName == registerInputModel.UserName.Trim());

            if (user == null)
            {
                return(false);
            }
            _userRepository.Delete(registerInputModel.MapTo(user));
            return(true);
        }
예제 #3
0
        public bool Modify(RegisterInputModel registerInputModel)
        {
            if (registerInputModel == null)
            {
                return(false);
            }

            var user = _userRepository.FirstOrDefault(u => u.UserName == registerInputModel.UserName.Trim());

            if (user == null)
            {
                return(false);
            }
            registerInputModel.UpdatedTime = DateTime.Now;
            _userRepository.Update(registerInputModel.MapTo(user));
            return(true);
        }
예제 #4
0
        public bool Register(RegisterInputModel registerInputModel)
        {
            if (registerInputModel == null)
            {
                return(false);
            }

            var user = _userRepository.FirstOrDefault(u => u.UserName == registerInputModel.UserName.Trim());

            if (user != null)
            {
                return(false);
            }

            registerInputModel.UserPassword = registerInputModel.UserPassword.Md5Encryption();
            registerInputModel.CreatedTime  = registerInputModel.UpdatedTime = DateTime.Now;
            _userRepository.Add(registerInputModel.MapTo <User>());
            return(true);
        }