/** * Generate sample item for testing */ public static Product test_instance(bool on_sale=false, bool mem_sale=false) { var p = new Product (); p.UPC = "123"; p.description = "Testing item"; p.brand = "Fake Brand"; p.normal_price = 5.95; if (on_sale) p.sale_price = 5.55; else if (mem_sale) p.member_price = 5.55; return p; }
public static Product oneFromJson(JsonObject json) { try { Product p = new Product (); p.UPC = json ["upc"]; p.description = json ["description"]; p.brand = json ["brand"]; p.normal_price = double.Parse (json ["price"].ToString ()); if (json.ContainsKey ("weight")) p.scale = true; if (json.ContainsKey ("salePrice")) p.sale_price = double.Parse (json ["salePrice"].ToString ()); if (json.ContainsKey ("memberPrice")) p.member_price = double.Parse (json ["memberPrice"].ToString ()); return p; } catch(Exception){ throw new Exception ("bad json data for product"); } }