using System; using System.Collections.Generic; using System.Web.Script.Serialization; namespace Retailcrm.Versions.V5 { public partial class Client { /// /// Get costs /// /// /// /// /// public Response CostsList(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("/costs", Request.MethodGet, parameters); } /// /// Create cost /// /// /// /// public Response CostsCreate(Dictionary cost, string site = "") { if (cost.Count < 1) { throw new ArgumentException("Parameter `cost` must contains a data"); } if (!cost.ContainsKey("costItem")) { throw new ArgumentException("Parameter `costItem` must be set"); } if (!cost.ContainsKey("summ")) { throw new ArgumentException("Parameter `summ` must be set"); } if (!cost.ContainsKey("dateFrom")) { throw new ArgumentException("`dateFrom`: Time interval lower bound must not be blank"); } if (!cost.ContainsKey("dateTo")) { throw new ArgumentException("`dateTo`: Time interval upper bound must not be blank"); } return Request.MakeRequest( "/costs/create", Request.MethodPost, FillSite( site, new Dictionary { { "cost", new JavaScriptSerializer().Serialize(cost) } } ) ); } /// /// Delete cost /// /// /// public Response CostsDelete(List ids) { if (ids.Count < 1) { throw new ArgumentException("Parameter `ids` must contains a data"); } return Request.MakeRequest( "/costs/delete", Request.MethodPost, new Dictionary { { "ids", new JavaScriptSerializer().Serialize(ids) } } ); } /// /// Upload costs /// /// /// public Response CostsUpload(List costs) { if (costs.Count < 1) { throw new ArgumentException("Parameter `costs` must contains a data"); } if (costs.Count > 50) { throw new ArgumentException("Parameter `costs` must contain 50 or less records"); } return Request.MakeRequest( "/costs/upload", Request.MethodPost, new Dictionary { { "costs", new JavaScriptSerializer().Serialize(costs) } } ); } /// /// Get cost /// /// /// public Response CostsGet(int id) { return Request.MakeRequest($"/costs/{id}", Request.MethodGet); } /// /// Batch delete /// /// /// public Response CostsDelete(string id) { return Request.MakeRequest( $"/costs/{id}/delete", Request.MethodPost ); } /// /// Update cost /// /// /// /// public Response CostsUpdate(Dictionary cost, string site = "") { if (cost.Count < 1) { throw new ArgumentException("Parameter `cost` must contains a data"); } if (!cost.ContainsKey("id")) { throw new ArgumentException("Parameter `cost` must contains an id"); } return Request.MakeRequest( $"/costs/{cost["id"].ToString()}/edit", Request.MethodPost, FillSite( site, new Dictionary { { "cost", new JavaScriptSerializer().Serialize(cost) } } ) ); } } }