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 List() { var request = new RestRequest(); request.Resource = "ProductGroups.json"; return JsonStore.Execute>(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(request); } public static ProductGroup Insert(ProductGroup productGroup) { var request = new RestRequest(Method.PUT); request.Resource = "ProductGroup.json"; request.AddJsonBody(productGroup); return JsonStore.Execute(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(request); } public static IList SaleList() { var request = new RestRequest(); request.Resource = "ProductGroups.json"; request.AddQueryParameter("s", ""); var list = JsonStore.Execute>(request); foreach (var item in list) { foreach (var product in item.Products) { product.ProductGroup = item; } } return list; } public static IList GetProductGroupTypes() { var request = new RestRequest(); request.Resource = "ProductGroupTypes.json"; return JsonStore.Execute>(request); } public static void UpdateSortOrder(IList list) { var request = new RestRequest(Method.POST); request.Resource = "ProductGroups.json"; request.AddJsonBody(list.Select(x => new { ProductGroupID = x.ProductGroupID })); JsonStore.Execute(request); } } }