Ejemplo n.º 1
0
 public ActionResult<User> AddUser([FromBody] User user)
 {
     if ( ModelState.IsValid )
     {
         if ( user.FullName != null && user.Email != null )
         {
             var result = _userBll.AddUser( user );
             return Ok( result );
         }
         throw new Exception( "Invalid input" );
     }
     return NotFound( );
 }
Ejemplo n.º 2
0
        public ActionResult SignUp([FromBody] SignUpViewModel model)
        {
            if (ModelState.IsValid)
            {
                if (!_userBll.CheckUserUniqueness(model.Email))
                {
                    return(BadRequest(new ObjectResult(new { message = "Пользователь с таким адресом уже существует" })));
                }

                if (!_userBll.IsSnilsUnique(model.Snils))
                {
                    return(BadRequest(new ObjectResult(new { message = "Пользователь с таким СНИЛС уже существует" })));
                }

                Users user = new Users()
                {
                    FirstName        = model.FirstName,
                    LastName         = model.LastName,
                    Patronym         = model.Patronym,
                    Email            = model.Email,
                    Sex              = model.Sex,
                    District         = model.District,
                    Password         = _userBll.HashPassword(model.Password),
                    IsBlocked        = false,
                    IsConfirmedEmail = false,
                    Snils            = model.Snils,
                    Role             = 1,
                    DateOfBirth      = model.DateOfBirth,
                    UserAvatar       = model.UserAvatar,
                };

                _userBll.AddUser(user);
                _userBll.SendConfirmationEmail(model.Email);


                return(Ok());
            }

            return(BadRequest());
        }
Ejemplo n.º 3
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtName.Text))
            {
                this.ShowInfo("请输入姓名.");
                return;
            }
            if (string.IsNullOrEmpty(txtPassword.Text))
            {
                this.ShowInfo("请输入密码.");
                return;
            }
            if (string.IsNullOrEmpty(txtPhone.Text))
            {
                this.ShowInfo("请输入手机号.");
                return;
            }
            if (string.IsNullOrEmpty(txtUserName.Text))
            {
                this.ShowInfo("请输入账号.");
                return;
            }
            UserModel model = new UserModel
            {
                UserName = txtUserName.Text,
                Name     = txtName.Text,
                Password = txtPassword.Text,
                Phone    = txtPhone.Text,
                Status   = 1,
            };
            var result = _userBll.AddUser(model);

            if (!result)
            {
                this.ShowInfo("添加失败.");
                return;
            }
            BindData();
        }