2011-01-30 07:14:05 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2018-08-24 10:41:33 +00:00
|
|
|
|
using Tanshu.Accounts.Entities;
|
|
|
|
|
using RestSharp;
|
2011-01-30 07:14:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace Tanshu.Accounts.Repository
|
|
|
|
|
{
|
2018-08-24 10:41:33 +00:00
|
|
|
|
public static class UserBI
|
2011-01-30 07:14:05 +00:00
|
|
|
|
{
|
2018-08-24 10:41:33 +00:00
|
|
|
|
public static IList<User> List()
|
2014-11-10 07:24:48 +00:00
|
|
|
|
{
|
2018-08-24 10:41:33 +00:00
|
|
|
|
var request = new RestRequest();
|
|
|
|
|
request.Resource = "Users.json";
|
|
|
|
|
return JsonStore.Execute<List<User>>(request);
|
2014-11-10 07:24:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-08-24 10:41:33 +00:00
|
|
|
|
public static User Get(Guid id)
|
2014-10-16 11:11:55 +00:00
|
|
|
|
{
|
2018-08-24 10:41:33 +00:00
|
|
|
|
var request = new RestRequest();
|
|
|
|
|
request.Resource = "User/{id}.json";
|
|
|
|
|
request.AddParameter("id", id, ParameterType.UrlSegment);
|
|
|
|
|
return JsonStore.Execute<User>(request);
|
2014-10-16 11:11:55 +00:00
|
|
|
|
}
|
2018-08-24 10:41:33 +00:00
|
|
|
|
|
|
|
|
|
public static User Insert(User user)
|
2011-01-30 07:14:05 +00:00
|
|
|
|
{
|
2018-08-24 10:41:33 +00:00
|
|
|
|
var request = new RestRequest(Method.PUT);
|
|
|
|
|
request.Resource = "User.json";
|
|
|
|
|
request.AddJsonBody(user);
|
|
|
|
|
return JsonStore.Execute<User>(request);
|
2011-01-30 07:14:05 +00:00
|
|
|
|
}
|
2018-08-24 10:41:33 +00:00
|
|
|
|
|
|
|
|
|
public static User Update(User user)
|
2011-01-30 07:14:05 +00:00
|
|
|
|
{
|
2018-08-24 10:41:33 +00:00
|
|
|
|
var request = new RestRequest(Method.POST);
|
|
|
|
|
request.Resource = "User/{id}.json";
|
|
|
|
|
request.AddParameter("id", user.UserID, ParameterType.UrlSegment);
|
|
|
|
|
request.AddJsonBody(user);
|
|
|
|
|
return JsonStore.Execute<User>(request);
|
2011-01-30 07:14:05 +00:00
|
|
|
|
}
|
2018-08-24 10:41:33 +00:00
|
|
|
|
|
|
|
|
|
public static User Delete(Guid id)
|
2011-01-30 07:14:05 +00:00
|
|
|
|
{
|
2018-08-24 10:41:33 +00:00
|
|
|
|
var request = new RestRequest(Method.DELETE);
|
|
|
|
|
request.Resource = "User/{id}.json";
|
|
|
|
|
request.AddParameter("id", id, ParameterType.UrlSegment);
|
|
|
|
|
return JsonStore.Execute<User>(request);
|
2011-01-30 07:14:05 +00:00
|
|
|
|
}
|
2018-08-24 10:41:33 +00:00
|
|
|
|
|
|
|
|
|
public static bool ChangePassword(string name, string oldPassword, string newPassword)
|
2011-01-30 07:14:05 +00:00
|
|
|
|
{
|
2018-08-24 10:41:33 +00:00
|
|
|
|
var request = new RestRequest(Method.POST);
|
|
|
|
|
request.Resource = "User/{id}.json";
|
|
|
|
|
request.AddQueryParameter("p", "");
|
|
|
|
|
request.AddParameter("id", name, ParameterType.UrlSegment);
|
|
|
|
|
request.AddJsonBody(new {OldPassword = oldPassword, NewPassword = newPassword });
|
|
|
|
|
return JsonStore.Execute<Boolean>(request);
|
2011-01-30 07:14:05 +00:00
|
|
|
|
}
|
2018-08-24 10:41:33 +00:00
|
|
|
|
public static bool ChangeMsr(string name, string oldPassword, string newMsr)
|
2011-01-30 07:14:05 +00:00
|
|
|
|
{
|
2018-08-24 10:41:33 +00:00
|
|
|
|
var request = new RestRequest(Method.POST);
|
|
|
|
|
request.Resource = "User/{id}.json";
|
|
|
|
|
request.AddQueryParameter("m", "");
|
|
|
|
|
request.AddParameter("id", name, ParameterType.UrlSegment);
|
|
|
|
|
request.AddJsonBody(new { OldPassword = oldPassword, NewMsr = newMsr });
|
|
|
|
|
return JsonStore.Execute<Boolean>(request);
|
2011-03-11 18:49:48 +00:00
|
|
|
|
}
|
2018-08-24 10:41:33 +00:00
|
|
|
|
public static User ValidateUser(string name, string password)
|
2014-10-16 11:11:55 +00:00
|
|
|
|
{
|
2018-08-24 10:41:33 +00:00
|
|
|
|
var request = new RestRequest(Method.POST);
|
|
|
|
|
request.Resource = "Login.json";
|
|
|
|
|
request.AddJsonBody(new User() { Name = name, Password = password });
|
|
|
|
|
return JsonStore.Execute<User>(request);
|
2014-10-16 11:11:55 +00:00
|
|
|
|
}
|
2018-08-24 10:41:33 +00:00
|
|
|
|
public static User MsrValidateUser(string msrString)
|
2014-10-16 11:11:55 +00:00
|
|
|
|
{
|
2018-08-24 10:41:33 +00:00
|
|
|
|
var request = new RestRequest(Method.POST);
|
|
|
|
|
request.Resource = "Msr.json";
|
|
|
|
|
request.AddJsonBody(new { Msr = msrString });
|
|
|
|
|
return JsonStore.Execute<User>(request);
|
2014-10-16 11:11:55 +00:00
|
|
|
|
}
|
2011-06-29 20:27:07 +00:00
|
|
|
|
}
|
2018-08-24 10:41:33 +00:00
|
|
|
|
}
|