static Dictionary <string, object> discountToDictionary(ProductDiscountModel discount) { Dictionary <string, object> dictionary = new Dictionary <string, object>(); dictionary.Add("price", discount.price.ToString()); dictionary.Add("numberOfPeriods", discount.numberOfPeriods); if (discount.localizedPrice != null) { dictionary.Add("localizedPrice", discount.localizedPrice); } if (discount.subscriptionPeriod != null) { dictionary.Add("subscriptionPeriod", subscriptionPeriodToDictionary(discount.subscriptionPeriod)); } return(dictionary); }
static ProductDiscountModel dictionaryToProductDiscountModel(Dictionary <string, object> dictionary) { ProductDiscountModel obj = new ProductDiscountModel(); if (dictionary.ContainsKey("price")) { obj.price = decimal.Parse((string)dictionary["price"]); } if (dictionary.ContainsKey("identifier")) { obj.identifier = (string)dictionary["identifier"]; } if (dictionary.ContainsKey("subscriptionPeriod")) { obj.subscriptionPeriod = dictionaryToProductSubscriptionPeriodModel((Dictionary <string, object>)dictionary["subscriptionPeriod"]); } if (dictionary.ContainsKey("numberOfPeriods")) { obj.numberOfPeriods = (long)dictionary["numberOfPeriods"]; } if (dictionary.ContainsKey("paymentMode")) { obj.paymentMode = stringToPaymentMode((string)dictionary["paymentMode"]); } if (dictionary.ContainsKey("localizedPrice")) { obj.localizedPrice = (string)dictionary["localizedPrice"]; } if (dictionary.ContainsKey("localizedSubscriptionPeriod")) { obj.localizedSubscriptionPeriod = (string)dictionary["localizedSubscriptionPeriod"]; } if (dictionary.ContainsKey("localizedNumberOfPeriods")) { obj.localizedNumberOfPeriods = (string)dictionary["localizedNumberOfPeriods"]; } return(obj); }