public IActionResult Result(CurrencyConverterModel model) { TextInfo textInfo = new CultureInfo("en-US", false).TextInfo; model.YourNameHere = textInfo.ToTitleCase(model.YourNameHere); model.ResultingText = model.ConvertNumberToString(model.NumberToConvert); return(View(model)); }
public IActionResult Convert(CurrencyConverterModel model) { if (!ModelState.IsValid) { return(View(model)); } return(RedirectToAction("Index", "Home")); }
public ActionResult Index() { var model = new CurrencyConverterModel() { CurrencyOptions = DropdownHelper.GetCurrencies(), ShowResult = false }; return(View(model)); }
public IActionResult Index() { var viewModel = new CurrencyConverterModel { CurrencyFrom = "CAD", CurrencyTo = "USD", Quantity = 50 }; return(View(viewModel)); }
public IActionResult Convert(CurrencyConverterModel model) { if (model.CurrencyFrom == model.CurrencyTo) { ModelState.AddModelError(string.Empty, "Cannot convert currency to itself"); } if (!ModelState.IsValid) { return(View(model)); } return(RedirectToAction("Index", "Checkout")); }
public IActionResult Convert(CurrencyConverterModel model) { if (model.CurrencyFrom == model.CurrencyTo) { ModelState.AddModelError(string.Empty, "Cannot convert currency to itself"); } if (!ModelState.IsValid) { return(View(model)); } // Store the valid values somewhere (e.g. database), // do the conversion etc return(RedirectToAction("Index", "Checkout")); }
public ActionResult Index(CurrencyConverterModel model) { if (ModelState.IsValid) { var resultModel = new CurrencyConverterModel() { Amount = model.Amount, CurrencyOptions = DropdownHelper.GetCurrencies(), FromCurrency = model.FromCurrency, ToCurrency = model.ToCurrency, ShowResult = true, Result = ExchangeRateHelper.GetExchangedValue(model.Amount, model.FromCurrency, model.ToCurrency).ToString() }; return(View(resultModel)); } return(RedirectToAction("Index")); }
public ActionResult ExportCurrencyList() { CurrencyConverterModel model = new CurrencyConverterModel(); var CurrencyList = CurrencyMethod.GetCurrencyListRecord(); DataTable dt = new DataTable("Currency"); dt.Columns.Add("Name", typeof(string)); dt.Columns.Add("Code", typeof(string)); dt.Columns.Add("Fixed Rate", typeof(decimal)); dt.Columns.Add("Date Freezing", typeof(DateTime)); dt.Columns.Add("Live Rate", typeof(decimal)); dt.Columns.Add("Fixed?", typeof(string)); foreach (var item in CurrencyList) { List <string> lstStrRow = new List <string>(); lstStrRow.Add(item.Name); lstStrRow.Add(item.Code); lstStrRow.Add(Convert.ToDecimal(Math.Round(decimal.Parse(item.FixedRate.ToString()), 4).ToString()).ToString()); lstStrRow.Add(item.FreezingDate.ToString()); lstStrRow.Add(Convert.ToDecimal(Math.Round(decimal.Parse(item.LiveRate.ToString()), 4).ToString()).ToString()); lstStrRow.Add((bool)item.IsFixed ? "Yes" : "No"); string[] newArray = lstStrRow.ToArray(); dt.Rows.Add(newArray); } using (XLWorkbook wb = new XLWorkbook()) { wb.Worksheets.Add(dt); wb.Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; wb.Style.Font.Bold = true; Response.Clear(); Response.Buffer = true; Response.Charset = ""; Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; Response.AddHeader("content-disposition", "attachment;filename= CurrencyReports_" + DateTime.Now.ToShortDateString() + ".xlsx"); using (MemoryStream MyMemoryStream = new MemoryStream()) { wb.SaveAs(MyMemoryStream); MyMemoryStream.WriteTo(Response.OutputStream); Response.Flush(); Response.End(); } } return(View()); }
// GET: CurrencyConverter public ActionResult Index() { CurrencyConverterModel model = new CurrencyConverterModel(); model.BindCurrencyList = CurrencyMethod.BindCurrencyListRecord(); var CurrencyList = CurrencyMethod.GetCurrencyListRecord(); foreach (var item in CurrencyList) { CurrencyConverterModel m = new CurrencyConverterModel(); m.Id = item.Id; m.Name = item.Name; m.Code = item.Code; m.FixedRate = Convert.ToDecimal(Math.Round(decimal.Parse(item.FixedRate.ToString()), 4).ToString()); m.LiveRate = Convert.ToDecimal(Math.Round(decimal.Parse(item.LiveRate.ToString()), 4).ToString()); m.FreezingDate = item.FreezingDate; m.IsFixed = (bool)item.IsFixed; model.CurrencyList.Add(m); } return(View(model)); }
public IActionResult Index(CurrencyConverterModel viewModel) { return(View(viewModel)); }
public ActionResult ConvertCurrency(CurrencyConverterModel model) { string currencyUrl = "http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml"; string rate = ""; string incurrcodetoeuro = model.SelectedFromCurrency; string outcurrcodetoeuro = model.SelectedToCurrency; string incurrcode = incurrcodetoeuro; string outcurrcode = outcurrcodetoeuro; try { if (model.FromAmount == 0) { model.ToAmount = 0; } else { // If input currency code and output currency code are same then return // currency value as output currency value if (incurrcode.Equals(outcurrcode)) { model.ToAmount = model.FromAmount; } else { //Fetch Currency Feed XML File XDocument xmlDoc = XDocument.Load(currencyUrl); foreach (XElement element in xmlDoc.Root.Descendants()) { XName name = element.Name; if (name.LocalName == "Cube") { foreach (XElement elem in element.DescendantNodes()) { //string time = elem.Attribute("time").Value; foreach (XElement element1 in elem.DescendantNodes()) { if (element1.Attribute("currency").Value.Equals(incurrcode)) { // the value of 1 equivalent euro to input currency //ex input currency code as "USD", 1 EURO = 1.36 USD // then, incurrcodetoeuro = 1.36 incurrcodetoeuro = element1.LastAttribute.Value.ToString(); } else if (element1.Attribute("currency").Value.Equals(outcurrcode)) { // the value of 1 equivalent euro // ex output currency code as "USD", 1 EURO = 1.36 USD // then, outcurrcodetoeuro = 1.36 outcurrcodetoeuro = element1.LastAttribute.Value.ToString(); } } } } } // Since the base currency is euro, return outcurrcodetoeuro // if the input currency code is equal to "EUR" (Euro) if (incurrcode.Equals("EUR")) { rate = outcurrcodetoeuro; Double currVal = double.Parse(rate) * model.FromAmount; model.ToAmount = currVal; } // If output currency code is "EUR // return value = (1/incurrcodetoeuro) * the value to be converted else if (outcurrcode.Equals("EUR")) { rate = incurrcodetoeuro; Double currVal = (1 / double.Parse(rate)) * model.FromAmount; model.ToAmount = currVal; } // return value = 1/incurrcodetoeuro outcurrcodetoeuro the value to be converted else { Double fromVal = double.Parse(incurrcodetoeuro); Double toVal = double.Parse(outcurrcodetoeuro); Double baseResult = (1 / fromVal); Double currVal = baseResult * toVal * model.FromAmount; model.ToAmount = currVal; } } } //Return coverted currency value rounded to 4 decimals model.ToAmount = Math.Round(model.ToAmount, 4); return(Json(model.ToAmount, JsonRequestBehavior.AllowGet)); } catch (FormatException fex) { return(Json(model.ToAmount, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { return(Json(model.ToAmount, JsonRequestBehavior.AllowGet)); } }