Page History
Posting a new customer in C# with the Winbooks.Apis.Services
Code Block | ||
---|---|---|
| ||
private static Guid GetId(ICriteria criteria, string type, string code)
{
criteria.Add(Condition.Eq("Code", code))
.SetProjection(Projections.Property("Id"))
.SetMaxResults(1);
Newtonsoft.Json.Linq.JArray id = _folder.GetFilterAll(criteria.JsonCriteriaSerialize(), type);
Guid guid = id == null ? Guid.Empty : Guid.Parse(id[0].ToString());
return guid;
}
private static void PostNewCustomer()
{
Guid country_id = GetId(new CountryDAO().CreateCriteria(), "Country", "BE");
Guid civility_id = GetId(new CivilityDAO().CreateCriteria(), "Civility", "NV");
Guid language_id = GetId(new LanguageDAO().CreateCriteria(), "Language", "nl");
Guid currency_id = GetId(new CurrencyDAO().CreateCriteria(), "Currency", "EUR");
Guid vat_id = GetId(new VatDAO().CreateCriteria(), "Vat", "21");
Guid customerCategory_id = GetId(new CustomerCategoryDAO().CreateCriteria(), "CustomerCategory", "BIG");
Guid defaultAccount_Id = GetId(new GLAccountDAO().CreateCriteria(), "GLAccount", "700000");
Guid centralAccount_Id = GetId(new GLAccountDAO().CreateCriteria(), "GLAccount", "400000");
Guid payCode_id = GetId(new PayCodeDAO().CreateCriteria(), "PayCode", "7");
Customer cust = new Customer();
cust.Code = "WBG3";
cust.VatApplicable = VatApplicable.Subject;
cust.Vat_Id = vat_id;
cust.CustomerCategory_Id = customerCategory_id;
cust.GLAccount_Id = defaultAccount_Id;
cust.GLAccount2_Id = centralAccount_Id;
cust.PayCode_Id = payCode_id;
cust.Third = new Third();
cust.Third.Code = "WBG3";
cust.Third.Name = "WINBOOKS GROUP 3";
cust.Third.ThirdCivility_Id = civility_id;
cust.Third.Language_Id = language_id;
cust.Third.Currency_Id = currency_id;
cust.Third.VatCountry_Id = country_id;
cust.Third.VatNumber = "0000000394";
cust.Third.Addresses = new List<Address>();
Address adr = new Address();
adr.Address1 = "330 Lemonierlaan";
adr.Address2 = "";
adr.PhoneNo = "+3223456789";
adr.Country_Id = country_id;
adr.Zip = "2000";
adr.Town = "Antwerpen";
adr.IsDelivering = true;
adr.IsDeliveringDefault = true;
adr.IsInvoicing = true;
adr.IsInvoicingDefault = true;
adr.IsPosting = true;
adr.IsPostingDefault = true;
cust.Third.Addresses.Add(adr);
_folder.Insert<Customer>(cust, 3, false);
} |
Posting a new customer (with the friendly code properties)
...