Пример #1
0
        public IRockResponse <RockCollection <Person> > Login(string username, string password)
        {
            var client = new RestSharp.RestClient(_baseUrl);

            client.CookieContainer = new System.Net.CookieContainer();
            var request = CreateRestRequest(RestSharp.Method.POST, "api/auth/login");

            request.AddBody(new {
                UserName = username,
                Password = password
            });
            var response = client.ExecuteAsPost(request, "POST");

            if (response.StatusCode == System.Net.HttpStatusCode.Unauthorized)
            {
                return(null);
            }
            var userLogins = FindBy <UserLogin>(new UserLoginQO {
                UserName = username
            }, "api/UserLogins");

            if (userLogins.IsSuccessful)
            {
                return(GetByID(userLogins.Data.Items[0].PersonId.ToString()));
            }

            return(null);
        }