using System;
using System.Collections.Generic;
using System.Web.Script.Serialization;
namespace Retailcrm.Versions.V3
{
public partial class Client
{
///
/// Create customer
///
///
///
///
///
public Response CustomersCreate(Dictionary customer, string site = "")
{
if (customer.Count < 1)
{
throw new ArgumentException("Parameter `customer` must contains a data");
}
return Request.MakeRequest(
"/customers/create",
Request.MethodPost,
FillSite(
site,
new Dictionary
{
{ "customer", new JavaScriptSerializer().Serialize(customer) }
}
)
);
}
///
/// Update customer
///
///
///
///
///
///
public Response CustomersUpdate(Dictionary customer, string by = "externalId", string site = "")
{
if (customer.Count < 1)
{
throw new ArgumentException("Parameter `customer` must contains a data");
}
if (!customer.ContainsKey("id") && !customer.ContainsKey("externalId"))
{
throw new ArgumentException("Parameter `customer` must contains an id or externalId");
}
CheckIdParameter(by);
string uid = by == "externalId" ? customer["externalId"].ToString() : customer["id"].ToString();
return Request.MakeRequest(
$"/customers/{uid}/edit",
Request.MethodPost,
FillSite(
site,
new Dictionary
{
{ "by", by },
{ "customer", new JavaScriptSerializer().Serialize(customer) }
}
)
);
}
///
/// Get customer
///
///
///
///
///
public Response CustomersGet(string id, string by = "externalId", string site = "")
{
CheckIdParameter(by);
return Request.MakeRequest(
$"/customers/{id}",
Request.MethodGet,
FillSite(
site,
new Dictionary
{
{ "by", by }
}
)
);
}
///
/// Get customers list
///
///
///
///
///
public Response CustomersList(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("/customers", Request.MethodGet, parameters);
}
///
/// Fix external id
///
///
///
public Response CustomersFixExternalIds(Dictionary[] ids)
{
return Request.MakeRequest(
"/customers/fix-external-ids",
Request.MethodPost,
new Dictionary
{
{ "customers", new JavaScriptSerializer().Serialize(ids) }
}
);
}
///
/// Upload customers
///
///
///
///
///
public Response CustomersUpload(List