narsil/Tanshu.Accounts.Repository/ProductGroupBI.cs
2018-08-24 16:11:33 +05:30

73 lines
2.5 KiB
C#

using RestSharp;
using System;
using System.Collections.Generic;
using System.Linq;
using Tanshu.Accounts.Entities;
namespace Tanshu.Accounts.Repository
{
public class ProductGroupBI
{
public static IList<ProductGroup> List()
{
var request = new RestRequest();
request.Resource = "ProductGroups.json";
return JsonStore.Execute<List<ProductGroup>>(request);
}
public static ProductGroup Get(Guid id)
{
var request = new RestRequest();
request.Resource = "ProductGroup/{id}.json";
request.AddParameter("id", id, ParameterType.UrlSegment);
return JsonStore.Execute<ProductGroup>(request);
}
public static ProductGroup Insert(ProductGroup productGroup)
{
var request = new RestRequest(Method.PUT);
request.Resource = "ProductGroup.json";
request.AddJsonBody(productGroup);
return JsonStore.Execute<ProductGroup>(request);
}
public static ProductGroup Update(ProductGroup productGroup)
{
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);
}
public static IList<ProductGroup> SaleList()
{
var request = new RestRequest();
request.Resource = "ProductGroups.json";
request.AddQueryParameter("s", "");
var list = JsonStore.Execute<List<ProductGroup>>(request);
foreach (var item in list)
{
foreach (var product in item.Products)
{
product.ProductGroup = item;
}
}
return list;
}
public static IList<string> GetProductGroupTypes()
{
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);
}
}
}