54 lines
1.8 KiB
C#
54 lines
1.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using Tanshu.Accounts.Entities;
|
|
using System.Linq;
|
|
using RestSharp;
|
|
|
|
namespace Tanshu.Accounts.Repository
|
|
{
|
|
public static class ProductBI
|
|
{
|
|
public static Product Get(Guid id)
|
|
{
|
|
var request = new RestRequest(Method.PUT);
|
|
request.Resource = "Product/{id}.json";
|
|
request.AddParameter("id", id, ParameterType.UrlSegment);
|
|
return JsonStore.Execute<Product>(request);
|
|
}
|
|
|
|
public static Product Insert(Product product)
|
|
{
|
|
var request = new RestRequest(Method.PUT);
|
|
request.Resource = "Product.json";
|
|
request.AddJsonBody(product);
|
|
return JsonStore.Execute<Product>(request);
|
|
}
|
|
|
|
public static Product Update(Product product)
|
|
{
|
|
var request = new RestRequest(Method.POST);
|
|
request.Resource = "Product/{id}.json";
|
|
request.AddParameter("id", product.ProductID, ParameterType.UrlSegment);
|
|
request.AddJsonBody(product);
|
|
return JsonStore.Execute<Product>(request);
|
|
}
|
|
|
|
public static IList<Product> List(bool? active)
|
|
{
|
|
var request = new RestRequest();
|
|
request.Resource = "Products.json";
|
|
if (active.HasValue)
|
|
request.AddQueryParameter("a", active.Value.ToString());
|
|
return JsonStore.Execute<List<Product>>(request);
|
|
}
|
|
|
|
public static void UpdateSortOrder(IList<Product> list)
|
|
{
|
|
var request = new RestRequest(Method.POST);
|
|
request.Resource = "Products.json";
|
|
request.AddJsonBody(list.Select(x => new { ProductID = x.ProductID, ProductGroupID = x.ProductGroup.ProductGroupID }));
|
|
JsonStore.Execute<Boolean>(request);
|
|
}
|
|
}
|
|
}
|