Example #1
0
        public async Task <ActionResult <UserDto> > Register(UserDto regUser)
        {
            regUser.Email = regUser.Email.ToLower();
            var emailExist = _dbController.FindUserByEmail(regUser.Email);

            if (emailExist != null)
            {
                return(BadRequest(new { errorMessage = "Email already in use" }));
            }
            User user = new User()
            {
                Email     = regUser.Email,
                FirstName = regUser.FirstName,
                LastName  = regUser.LastName
            };

            user.PwHash = HashPassword(regUser.Password, BcryptWorkfactor);
            user.Role   = Role.User;
            _dbController.AddAndSaveUser(user);
            return(CreatedAtAction("Get", new { id = user.UserId }, regUser));
        }
        public async Task <ActionResult <User> > PostUser(User user)
        {
            _dbController.AddAndSaveUser(user);

            return(CreatedAtAction("GetUser", new { id = user.UserId }, user));
        }