Exemple #1
0
    public object Post(CreateUser request)
    {
        var id   = Db.Insert(request.ConvertTo <User>());
        var user = Db.SingleById <User>(id);

        return(user);
    }
        public async Task <object> Post(CreateUser request)
        {
            var response = new BaseResponse();

            var entity = request.ConvertTo <User>();

            // check isValid Role
            if (!base.IsUserValidRole(entity.RoleId))
            {
                throw new MethodAccessException();
            }

            new SaltedHash().GetHashAndSaltString(request.Password, out var hashedPassword, out var salt);
            entity.Password = hashedPassword;
            entity.Salt     = salt;
            var result = await _userService.Create(entity);

            response.Success    = true;
            response.StatusCode = (int)HttpStatusCode.Created;
            response.Message    = "Create user success";
            response.Results    = result;
            return(response);
        }