Exemplo n.º 1
0
        async Task Delete(int id)
        {
            ApiResult <bool> apiResult = await _connector.PostAsync <int, bool>("api/Organization/Delete", id);

            if (apiResult.IsSuccess)
            {
                Console.WriteLine("成功删除了ID=" + id.ToString() + "的组织");
            }
            else
            {
                Console.WriteLine(apiResult.Message);
            }
        }
Exemplo n.º 2
0
        public async Task <TReturn> HttpPost <T, TReturn>(string route, T data = default(T))
            where TReturn : new()
        {
            var apiResult = await _connector.PostAsync <T, TReturn>(route, data);

            if (apiResult.IsSuccess)
            {
                return(apiResult.GetData());
            }
            else
            {
                throw new Exception(apiResult.Message);
            }
        }
Exemplo n.º 3
0
        async Task InsertReferences(List <Reference> references)
        {
            try
            {
                foreach (var reference in references)
                {
                    var result = await _connector.PostAsync <Reference, int>("api/Reference/Save", reference);

                    if (result.IsSuccess)
                    {
                        Console.WriteLine($"插入参照项成功, " +
                                          $"类型:{reference.ReferenceType}, " +
                                          $"代码:{reference.ReferenceCode}, " +
                                          $"值:{reference.ReferenceValue}, " +
                                          $"ID:{result.GetData()}");
                    }
                    else
                    {
                        Console.WriteLine($"插入参照项失败, 值:{reference.ReferenceValue}, 错误:{result.Message}");
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine($"插入参照项发生操作异常, 错误:{ex.Message}");
            }
        }
Exemplo n.º 4
0
        async Task CreateNewUserAsync()
        {
            Random r       = new Random();
            User   newUser = new User()
            {
                ActiveStatus = true,
                Login        = "******" + r.Next(10000),
                Name         = "CH" + r.Next(10000),
                Role         = (int)RoleEnum.HumanResourceAdmin
            };

            ApiResult <int> apiResult = await _connector.PostAsync <User, int>("api/User/SaveUser", newUser);

            if (apiResult.IsSuccess)
            {
                Console.WriteLine("Create a new user: id=" + apiResult.GetData().ToString());
                //change credential
                ChangeCredential changeCredential = new ChangeCredential()
                {
                    UserID        = apiResult.GetData(),
                    OldCredential = string.Empty,
                    NewCredential = CryptoHelper.CreateCredential("P@55w0rd")
                };

                ApiResult <bool> setPwdResult = await _connector.PostAsync <ChangeCredential, bool>("api/User/ChangeCredential", changeCredential);

                if (setPwdResult.IsSuccess && setPwdResult.GetData())
                {
                    Console.WriteLine("the password for this user has been set.");
                }
                else
                {
                    Console.WriteLine("set password failed.");
                }
            }
            else
            {
                Console.WriteLine("Create new user failed, err=" + apiResult.Message);
            }
        }