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(request); } public static Product Insert(Product product) { var request = new RestRequest(Method.PUT); request.Resource = "Product.json"; request.AddJsonBody(product); return JsonStore.Execute(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(request); } public static IList List(bool? active) { var request = new RestRequest(); request.Resource = "Products.json"; if (active.HasValue) request.AddQueryParameter("a", active.Value.ToString()); return JsonStore.Execute>(request); } public static void UpdateSortOrder(IList 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(request); } } }