using System; using System.Collections.Generic; using System.Web.Script.Serialization; namespace Retailcrm.Versions.V5 { public partial class Client { /// /// Costs groups /// /// public Response CostGroups() { return Request.MakeRequest( "/reference/cost-groups", Request.MethodGet ); } /// /// Costs /// /// public Response CostItems() { return Request.MakeRequest( "/reference/cost-items", Request.MethodGet ); } /// /// Legal entities /// /// public Response LegalEntities() { return Request.MakeRequest( "/reference/legal-entities", Request.MethodGet ); } /// /// Cost group edit /// /// /// public Response CostGroupsEdit(Dictionary group) { if (!group.ContainsKey("code")) { throw new ArgumentException("Parameter `code` is missing"); } if (!group.ContainsKey("name")) { throw new ArgumentException("Parameter `name` is missing"); } if (!group.ContainsKey("color")) { throw new ArgumentException("Parameter `color` is missing"); } return Request.MakeRequest( $"/reference/cost-groups/{@group["code"]}/edit", Request.MethodPost, new Dictionary { { "costGroup", new JavaScriptSerializer().Serialize(group) } } ); } /// /// Cost items edit /// /// /// public Response CostItemsEdit(Dictionary item) { if (!item.ContainsKey("code")) { throw new ArgumentException("Parameter `code` is missing"); } if (!item.ContainsKey("name")) { throw new ArgumentException("Parameter `name` is missing"); } if (!item.ContainsKey("group")) { throw new ArgumentException("Parameter `group` is missing"); } List types = new List { "const", "var" }; if (item.ContainsKey("type") && !types.Contains(item["type"].ToString())) { throw new ArgumentException("Parameter `type` should be one of `const|var`"); } return Request.MakeRequest( $"/reference/cost-items/{item["code"]}/edit", Request.MethodPost, new Dictionary { { "costItem", new JavaScriptSerializer().Serialize(item) } } ); } /// /// Legal entities edit /// /// /// public Response LegalEntitiesEdit(Dictionary entity) { if (!entity.ContainsKey("code")) { throw new ArgumentException("Parameter `code` is missing"); } if (!entity.ContainsKey("legalName")) { throw new ArgumentException("Parameter `legalName` is missing"); } if (!entity.ContainsKey("countryIso")) { throw new ArgumentException("Parameter `countryIso` is missing"); } if (!entity.ContainsKey("contragentType")) { throw new ArgumentException("Parameter `contragentType` is missing"); } return Request.MakeRequest( $"/reference/legal-entities/{entity["code"]}/edit", Request.MethodPost, new Dictionary { { "legalEntity", new JavaScriptSerializer().Serialize(entity) } } ); } /// /// Couriers list /// /// public Response Couriers() { return Request.MakeRequest( "/reference/couriers", Request.MethodGet ); } /// /// Create a courier /// /// /// public Response CouriersCreate(Dictionary courier) { return Request.MakeRequest( "/reference/couriers/create", Request.MethodPost, new Dictionary { { "courier", new JavaScriptSerializer().Serialize(courier) } } ); } /// /// Edit a courier /// /// /// public Response CouriersEdit(Dictionary courier) { if (!courier.ContainsKey("id")) { throw new ArgumentException("Parameter `id` is missing"); } return Request.MakeRequest( $"/reference/couriers/{courier["id"]}/edit", Request.MethodPost, new Dictionary { { "courier", new JavaScriptSerializer().Serialize(courier) } } ); } } }