narsil/Tanshu.Accounts.Repository/UserBI.cs

84 lines
3.1 KiB
C#
Raw Permalink Normal View History

using System;
using System.Collections.Generic;
2018-08-24 10:41:33 +00:00
using Tanshu.Accounts.Entities;
using RestSharp;
namespace Tanshu.Accounts.Repository
{
2018-08-24 10:41:33 +00:00
public static class UserBI
{
2018-08-24 10:41:33 +00:00
public static IList<User> List()
{
2018-08-24 10:41:33 +00:00
var request = new RestRequest();
request.Resource = "Users.json";
return JsonStore.Execute<List<User>>(request);
}
2018-08-24 10:41:33 +00:00
public static User Get(Guid id)
{
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);
}
2018-08-24 10:41:33 +00:00
public static User Insert(User user)
{
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);
}
2018-08-24 10:41:33 +00:00
public static User Update(User user)
{
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);
}
2018-08-24 10:41:33 +00:00
public static User Delete(Guid id)
{
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);
}
2018-08-24 10:41:33 +00:00
public static bool ChangePassword(string name, string oldPassword, string newPassword)
{
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);
}
2018-08-24 10:41:33 +00:00
public static bool ChangeMsr(string name, string oldPassword, string newMsr)
{
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);
}
2018-08-24 10:41:33 +00:00
public static User ValidateUser(string name, string password)
{
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);
}
2018-08-24 10:41:33 +00:00
public static User MsrValidateUser(string msrString)
{
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);
}
}
2018-08-24 10:41:33 +00:00
}