public string Get(string name, string currency) { var model = new NameCurrencyModel(); if (string.IsNullOrWhiteSpace(name)) { model.ErrorMessage = Constants.RequiredName; return(GetJsonModel(model)); } if (!IsValidName(name)) { model.ErrorMessage = Constants.InvalidName; return(GetJsonModel(model)); } string isNegative = ""; double number; if (!double.TryParse(currency, out number)) { model.ErrorMessage = Constants.InvalidCurrency; return(GetJsonModel(model)); } if (currency.Contains("-")) { isNegative = "MINUS "; currency = currency.Substring(1, currency.Length - 1); } if (currency == "0") { model.Currency = "ZERO DOLLAR"; } else { var wordFormat = ConvertToWords.ConvertNumber(currency); if (wordFormat == Constants.ErrorNotSupported || wordFormat == Constants.InvalidCurrency) { model.ErrorMessage = wordFormat; return(GetJsonModel(model)); } else { model.Currency = isNegative + wordFormat; } } model.Name = name.ToUpper().Trim(); return(GetJsonModel(model)); }
private string GetJsonModel(NameCurrencyModel model) { //can convert in xml or json return(JsonConvert.SerializeObject(model)); }