narsil/Tanshu.Accounts.Repository/ProductGroupBI.cs

73 lines
2.5 KiB
C#
Raw Permalink Normal View History

2018-08-24 10:41:33 +00:00
using RestSharp;
using System;
using System.Collections.Generic;
2018-08-24 10:41:33 +00:00
using System.Linq;
using Tanshu.Accounts.Entities;
namespace Tanshu.Accounts.Repository
{
2018-08-24 10:41:33 +00:00
public class ProductGroupBI
{
2018-08-24 10:41:33 +00:00
public static IList<ProductGroup> List()
{
2018-08-24 10:41:33 +00:00
var request = new RestRequest();
request.Resource = "ProductGroups.json";
return JsonStore.Execute<List<ProductGroup>>(request);
}
2018-08-24 10:41:33 +00:00
public static ProductGroup Get(Guid id)
{
2018-08-24 10:41:33 +00:00
var request = new RestRequest();
request.Resource = "ProductGroup/{id}.json";
request.AddParameter("id", id, ParameterType.UrlSegment);
return JsonStore.Execute<ProductGroup>(request);
}
2018-08-24 10:41:33 +00:00
public static ProductGroup Insert(ProductGroup productGroup)
{
var request = new RestRequest(Method.PUT);
request.Resource = "ProductGroup.json";
request.AddJsonBody(productGroup);
return JsonStore.Execute<ProductGroup>(request);
}
2018-08-24 10:41:33 +00:00
public static ProductGroup Update(ProductGroup productGroup)
{
2018-08-24 10:41:33 +00:00
var request = new RestRequest(Method.POST);
request.Resource = "ProductGroup/{id}.json";
request.AddParameter("id", productGroup.ProductGroupID, ParameterType.UrlSegment);
request.AddJsonBody(productGroup);
return JsonStore.Execute<ProductGroup>(request);
}
2018-08-24 10:41:33 +00:00
public static IList<ProductGroup> SaleList()
{
2018-08-24 10:41:33 +00:00
var request = new RestRequest();
request.Resource = "ProductGroups.json";
request.AddQueryParameter("s", "");
var list = JsonStore.Execute<List<ProductGroup>>(request);
foreach (var item in list)
{
2018-08-24 10:41:33 +00:00
foreach (var product in item.Products)
{
product.ProductGroup = item;
}
}
2018-08-24 10:41:33 +00:00
return list;
}
2018-08-24 10:41:33 +00:00
public static IList<string> GetProductGroupTypes()
{
2018-08-24 10:41:33 +00:00
var request = new RestRequest();
request.Resource = "ProductGroupTypes.json";
return JsonStore.Execute<List<string>>(request);
}
public static void UpdateSortOrder(IList<ProductGroup> list)
{
var request = new RestRequest(Method.POST);
request.Resource = "ProductGroups.json";
request.AddJsonBody(list.Select(x => new { ProductGroupID = x.ProductGroupID }));
JsonStore.Execute<Boolean>(request);
}
}
}