public int Execute(SalesOrder order)
        {
            //validate
              if (order == null)
              {
            throw new InvalidOperationException("Can't save a non-existent sales order");
              }

              //check if exists
              var existing = Runner.ExecuteSingle<SalesOrder>("select * from sales_order where id=@0", order.ID);
              var items = JsonConvert.SerializeObject(order.Items);
              NpgsqlCommand cmd;
              if (existing != null)
              {
            cmd = Runner.BuildCommand("UPDATE sales_order SET data=@0 WHERE id=@1", items, order.ID);
              }
              else
              {
            cmd = Runner.BuildCommand("INSERT INTO sales_order (data) VALUES(@0)", items);
              }
              //check inventory

              //reporting

              //log it to the user's account

              return Runner.Transact(cmd).Sum();
        }
Beispiel #2
0
 static void Main(string[] args)
 {
     var db = new CommandRunner("dvds");
       var salesOrder = new SalesOrder();
       salesOrder.Items.Add(new LineItem { SKU = "Ducky", Price = 12.00M, Name = "Little Duck Buddy" });
       var cmd = new Commands.Sales.SaveSalesOrder(db).Execute(salesOrder);
       Console.WriteLine(cmd);
       Console.Read();
 }