Rest Client .NET
Prerequisites
Add the following dependencies to your project:
Authentication
var oneErp = new OneERPServer("localhost:8181");
try {
//Authtentication
oneErp.Authenticate("vlad", "1234", "ro");
} catch (AuthenticationException e) {
}
Entity models
Without children
[DataContract]
public class Product : IEntityProperties {
public long? Key { get; set; }
[DataMember(Name = "name")]
public string Name { get; set; }
}
With children
[DataContract]
public class MenuNode : IEntityProperties {
public long? Key { get; set; }
[DataMember(Name = "name")]
public string Name { get; set; }
}
[DataContract]
public class MenuNodeItem : IEntityProperties {
public long? Key { get; set; }
[DataMember(Name = "name")]
public string Name { get; set; }
}
[DataContract]
public class MenuNodeChildren {
[DataMember(Name = "menu_node_menu_node_item")]
public List<SimpleEntity<MenuNodeItem>> Items { get; set; }
}
Reading an entity
Entity without children
Entity<Product, Empty> productEntity = oneErp.Get<Product, Empty>("product", 1);
Product p = productEntity.Properties;
Entity with children
Entity<MenuNode, MenuNodeChildren> menuNode = oneErp.Get<MenuNode, MenuNodeChildren>("menu_node", 1);
Creating an entity
Entity without children
Product p = new Product();
p.Name = "new product";
var productEntity = new Entity<Product, Empty>();
productEntity.EntityName = "product";
productEntity.Properties = p;
oneErp.Put<Product, Empty>("product", p);
Entity with children
MenuNode node = new MenuNode();
node.Name = "new menu node";
MenuNodeItem item = new MenuNodeItem();
item.Name = "the item";
MenuNodeChildren children = new MenuNodeChildren();
children.Items.Add(item);
var nodeEntity = new Entity<MenuNode, MenuNodeChildren>();
nodeEntity.EntityName = "menu_node";
nodeEntity.Properties = node;
nodeEntity.Children = children;
oneErp.Put<Product, Empty>("menu_node", nodeEntity);
Updating an entity
var productEntity = oneErp.Get<Product, Empty>("product", 10);
Product p = productEntity.Properties;
p.Name = "updated name";
oneErp.Put<Product, Empty>("product", 10, p);
Deleting an entity
oneErp.Delete("product", 10);
Run workflow
var concatArgs = new ConcatArgs() {
Arg1 = "Salut",
Arg2 = "Vlad",
Glue = " "
};
//WorkflowName, WorkflowMethod, Args
var concatResponse = oneErp.RunWorkflow<ConcatResponse, ConcatArgs>("test", "concat", concatArgs);
Console.WriteLine("Concat: " + concatResponse.Concat);