using System; using System.Collections.Generic; using System.Web.Script.Serialization; namespace Retailcrm.Versions.V5 { public partial class Client { /// /// Get custom fields /// /// /// /// /// public Response CustomFieldsList(Dictionary filter = null, int page = 1, int limit = 20) { Dictionary parameters = new Dictionary(); if (filter != null && filter.Count > 0) { parameters.Add("filter", filter); } if (page > 0) { parameters.Add("page", page); } if (limit > 0) { parameters.Add("limit", limit); } return Request.MakeRequest("/custom-fields", Request.MethodGet, parameters); } /// /// Create custom field /// /// /// public Response CustomFieldsCreate(Dictionary customField) { List types = new List { "boolean", "date", "dictionary", "email", "integer", "numeric", "string", "text" }; if (customField.Count < 1) { throw new ArgumentException("Parameter `customField` must contains a data"); } if (!customField.ContainsKey("code")) { throw new ArgumentException("Parameter `customField` should contain `code`"); } if (!customField.ContainsKey("name")) { throw new ArgumentException("Parameter `customField` should contain `name`"); } if (!customField.ContainsKey("type")) { throw new ArgumentException("Parameter `customField` should contain `type`"); } if (!customField.ContainsKey("entity")) { throw new ArgumentException("Parameter `customField` should contain `entity`"); } if (!types.Contains(customField["type"].ToString())) { throw new ArgumentException( "Parameter `customField` should contain `type` & value of type should be on of `boolean|date|dictionary|email|integer|numeric|string|text`" ); } return Request.MakeRequest( $"/custom-fields/{customField["entity"].ToString()}/create", Request.MethodPost, new Dictionary { { "customField", new JavaScriptSerializer().Serialize(customField) } } ); } /// /// Get custom field /// /// /// /// public Response CustomFieldsGet(string code, string entity) { return Request.MakeRequest( $"/custom-fields/{entity}/{code}", Request.MethodGet ); } /// /// Update custom field /// /// /// public Response CustomFieldsUpdate(Dictionary customField) { if (customField.Count < 1) { throw new ArgumentException("Parameter `customField` must contains a data"); } if (!customField.ContainsKey("code")) { throw new ArgumentException("Parameter `customField` should contain `code`"); } if (!customField.ContainsKey("name")) { throw new ArgumentException("Parameter `customField` should contain `name`"); } return Request.MakeRequest( $"/custom-fields/{customField["entity"].ToString()}/{customField["code"].ToString()}/edit", Request.MethodPost, new Dictionary { { "customField", new JavaScriptSerializer().Serialize(customField) } } ); } /// /// Get custom dictionaries /// /// /// /// /// public Response CustomDictionaryList(Dictionary filter = null, int page = 1, int limit = 20) { Dictionary parameters = new Dictionary(); if (filter != null && filter.Count > 0) { parameters.Add("filter", filter); } if (page > 0) { parameters.Add("page", page); } if (limit > 0) { parameters.Add("limit", limit); } return Request.MakeRequest("/custom-fields/dictionaries", Request.MethodGet, parameters); } /// /// Create custom dictionary /// /// /// public Response CustomDictionaryCreate(Dictionary customDictionary) { if (customDictionary.Count < 1) { throw new ArgumentException("Parameter `customDictionary` must contains a data"); } if (!customDictionary.ContainsKey("code")) { throw new ArgumentException("Parameter `customDictionary` should contain `code`"); } if (!customDictionary.ContainsKey("name")) { throw new ArgumentException("Parameter `customDictionary` should contain `name`"); } return Request.MakeRequest( "/custom-fields/dictionaries/create", Request.MethodPost, new Dictionary { { "customDictionary", new JavaScriptSerializer().Serialize(customDictionary) } } ); } /// /// Get custom dictionary /// /// /// public Response CustomDictionaryGet(string code) { return Request.MakeRequest( $"/custom-fields/dictionaries/{code}", Request.MethodGet ); } /// /// Update custom dictionary /// /// /// public Response CustomDictionaryUpdate(Dictionary customDictionary) { if (customDictionary.Count < 1) { throw new ArgumentException("Parameter `customDictionary` must contains a data"); } if (!customDictionary.ContainsKey("code")) { throw new ArgumentException("Parameter `customDictionary` should contain `code`"); } if (!customDictionary.ContainsKey("name")) { throw new ArgumentException("Parameter `customDictionary` should contain `name`"); } return Request.MakeRequest( $"/custom-fields/dictionaries/{customDictionary["code"].ToString()}/edit", Request.MethodPost, new Dictionary { { "customDictionary", new JavaScriptSerializer().Serialize(customDictionary) } } ); } } }