using System;
using System.Collections.Generic;
using System.Web.Script.Serialization;
namespace Retailcrm.Versions.V3
{
public partial class Client
{
///
/// Create order
///
///
///
///
public Response OrdersCreate(Dictionary order, string site = "")
{
if (order.Count < 1)
{
throw new ArgumentException("Parameter `order` must contains a data");
}
return Request.MakeRequest(
"/orders/create",
Request.MethodPost,
FillSite(
site,
new Dictionary
{
{ "order", new JavaScriptSerializer().Serialize(order) }
}
)
);
}
///
/// Update order
///
///
///
///
///
public Response OrdersUpdate(Dictionary order, string by = "externalId", string site = "")
{
if (order.Count < 1)
{
throw new ArgumentException("Parameter `order` must contains a data");
}
if (!order.ContainsKey("id") && !order.ContainsKey("externalId"))
{
throw new ArgumentException("Parameter `order` must contains an id or externalId");
}
CheckIdParameter(by);
string uid = by == "externalId" ? order["externalId"].ToString() : order["id"].ToString();
return Request.MakeRequest(
$"/orders/{uid}/edit",
Request.MethodPost,
FillSite(
site,
new Dictionary
{
{ "by", by },
{ "order", new JavaScriptSerializer().Serialize(order) }
}
)
);
}
///
/// Get order
///
///
///
///
///
public Response OrdersGet(string id, string by = "externalId", string site = "")
{
CheckIdParameter(by);
return Request.MakeRequest(
$"/orders/{id}",
Request.MethodGet,
FillSite(
site,
new Dictionary
{
{ "by", by }
}
)
);
}
///
///
///
///
///
///
///
public Response OrdersList(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 > 1)
{
parameters.Add("page", page);
}
if (limit > 20)
{
parameters.Add("limit", limit);
}
return Request.MakeRequest("/orders", Request.MethodGet, parameters);
}
///
/// Fix external ids
///
///
///
public Response OrdersFixExternalIds(Dictionary[] ids)
{
return Request.MakeRequest(
"/orders/fix-external-ids",
Request.MethodPost,
new Dictionary
{
{ "orders", new JavaScriptSerializer().Serialize(ids) }
}
);
}
///
/// Get orders history
///
///
///
///
///
///
///
public Response OrdersHistory(DateTime? startDate = null, DateTime? endDate = null, int limit = 200, int offset = 0, bool skipMyChanges = true)
{
Dictionary parameters = new Dictionary();
if (startDate != null)
{
parameters.Add("startDate", startDate.Value.ToString("yyyy-MM-dd HH:mm:ss"));
}
if (endDate != null)
{
parameters.Add("endDate", endDate.Value.ToString("yyyy-MM-dd HH:mm:ss"));
}
if (limit > 0)
{
parameters.Add("limit", limit);
}
if (offset > 0)
{
parameters.Add("offset", offset);
}
parameters.Add("skipMyChanges", skipMyChanges);
return Request.MakeRequest(
"/orders/history",
Request.MethodGet,
parameters
);
}
///
/// Get orders statuses
///
///
///
///
public Response OrdersStatuses(List ids, List externalIds = null)
{
Dictionary parameters = new Dictionary();
if (ids == null && externalIds == null)
{
throw new ArgumentException("You must set the array of `ids` or `externalIds`.");
}
if (
ids != null && externalIds != null && ids.Count + externalIds.Count > 500 ||
ids == null && externalIds != null && externalIds.Count > 500 ||
ids != null && externalIds == null && ids.Count > 500
)
{
throw new ArgumentException("Too many ids or externalIds. Maximum number of elements is 500");
}
if (ids != null && ids.Count > 0)
{
parameters.Add("ids", ids);
}
if (externalIds != null && externalIds.Count > 0)
{
parameters.Add("externalIds", externalIds);
}
return Request.MakeRequest(
"/orders/statuses",
Request.MethodGet,
parameters
);
}
///
/// Orders upload
///
///
///
///
public Response OrdersUpload(List