84 lines
3.1 KiB
C#
84 lines
3.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using Tanshu.Accounts.Entities;
|
|
using RestSharp;
|
|
|
|
|
|
namespace Tanshu.Accounts.Repository
|
|
{
|
|
public static class UserBI
|
|
{
|
|
public static IList<User> List()
|
|
{
|
|
var request = new RestRequest();
|
|
request.Resource = "Users.json";
|
|
return JsonStore.Execute<List<User>>(request);
|
|
}
|
|
|
|
public static User Get(Guid id)
|
|
{
|
|
var request = new RestRequest();
|
|
request.Resource = "User/{id}.json";
|
|
request.AddParameter("id", id, ParameterType.UrlSegment);
|
|
return JsonStore.Execute<User>(request);
|
|
}
|
|
|
|
public static User Insert(User user)
|
|
{
|
|
var request = new RestRequest(Method.PUT);
|
|
request.Resource = "User.json";
|
|
request.AddJsonBody(user);
|
|
return JsonStore.Execute<User>(request);
|
|
}
|
|
|
|
public static User Update(User user)
|
|
{
|
|
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);
|
|
}
|
|
|
|
public static User Delete(Guid id)
|
|
{
|
|
var request = new RestRequest(Method.DELETE);
|
|
request.Resource = "User/{id}.json";
|
|
request.AddParameter("id", id, ParameterType.UrlSegment);
|
|
return JsonStore.Execute<User>(request);
|
|
}
|
|
|
|
public static bool ChangePassword(string name, string oldPassword, string newPassword)
|
|
{
|
|
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);
|
|
}
|
|
public static bool ChangeMsr(string name, string oldPassword, string newMsr)
|
|
{
|
|
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);
|
|
}
|
|
public static User ValidateUser(string name, string password)
|
|
{
|
|
var request = new RestRequest(Method.POST);
|
|
request.Resource = "Login.json";
|
|
request.AddJsonBody(new User() { Name = name, Password = password });
|
|
return JsonStore.Execute<User>(request);
|
|
}
|
|
public static User MsrValidateUser(string msrString)
|
|
{
|
|
var request = new RestRequest(Method.POST);
|
|
request.Resource = "Msr.json";
|
|
request.AddJsonBody(new { Msr = msrString });
|
|
return JsonStore.Execute<User>(request);
|
|
}
|
|
}
|
|
} |