public decimal GetLength(string type, decimal tempIn) { switch (type) { case "f2m": return(FeetToMeters.Convert(tempIn)); case "m2f": return(MetersToFeet.Convert(tempIn)); case "f2y": return(FeetToYards.Convert(tempIn)); case "y2f": return(YardsToFeet.Convert(tempIn)); case "m2y": return(MetersToYards.Convert(tempIn)); case "y2m": return(YardsToMeters.Convert(tempIn)); default: return(tempIn); } }
public IActionResult ConvertLength(ConverterViewModel model) { // Establish those objects which will be converted to ILengthConverter FtoM = new FeetToMeters(); ILengthConverter FtoY = new FeetToYards(); ILengthConverter MtoF = new MetersToFeet(); ILengthConverter MtoY = new MetersToYards(); ILengthConverter YtoF = new YardsToFeet(); ILengthConverter YtoM = new YardsToMeters(); switch(model.ConversionType) { case "FtoM": model.ConvertedValue = Math.Round(FtoM.getLength(model.ValueToConvert), 2); return View(model); case "FtoY": model.ConvertedValue = Math.Round(FtoY.getLength(model.ValueToConvert), 2); return View(model); case "MtoF": model.ConvertedValue = Math.Round(MtoF.getLength(model.ValueToConvert), 2); return View(model); case "MtoY": model.ConvertedValue = Math.Round(MtoY.getLength(model.ValueToConvert), 2); return View(model); case "YtoF": model.ConvertedValue = Math.Round(YtoF.getLength(model.ValueToConvert), 2); return View(model); case "YtoM": model.ConvertedValue = Math.Round(YtoM.getLength(model.ValueToConvert), 2); return View(model); default: return View(); } }
public IActionResult LengthsConvert(decimal lengthIn) { var mToF = new MetersToFeet(); var fToM = new FeetToMeters(); var mtoY = new MetersToYard(); var ytoM = new YardToMeter(); var fToY = new FeetToYards(); var ytoF = new YardToFeet(); ViewData["mToF"] = mToF.Lengths(lengthIn); ViewData["fToM"] = fToM.Lengths(lengthIn); ViewData["mtoY"] = mtoY.Lengths(lengthIn); ViewData["ytoM"] = ytoM.Lengths(lengthIn); ViewData["fToY"] = fToY.Lengths(lengthIn); ViewData["yToF"] = ytoF.Lengths(lengthIn); return(View()); }
public IActionResult LengthConvert(decimal numIn) { ILengthConversions mToF = new MetersToFeet(); ILengthConversions fToM = new FeetToMeters(); ILengthConversions mToY = new MetersToYards(); ILengthConversions yToM = new YardsToMeters(); ILengthConversions fToY = new FeetToYards(); ILengthConversions yToF = new YardsToFeet(); ViewData["NumInput"] = numIn; ViewData["MtoF"] = Math.Round(mToF.GetLength(numIn), 2); ViewData["FtoM"] = Math.Round(fToM.GetLength(numIn), 2); ViewData["MtoY"] = Math.Round(mToY.GetLength(numIn), 2); ViewData["YtoM"] = Math.Round(yToM.GetLength(numIn), 2); ViewData["FtoY"] = Math.Round(fToY.GetLength(numIn), 2); ViewData["YtoF"] = Math.Round(yToF.GetLength(numIn), 2); return(View()); }
public IActionResult DoConversion(ConverterViewModel model) { switch (model.ConversionType) { //TEMP case "CtoF": var cToF = new CelsiusToFahrenheit(); model.ConvertedValue = cToF.Temp(model.ValueToConvert); break; case "FtoC": var FtoC = new FahrenheitToCelsius(); model.ConvertedValue = FtoC.Temp(model.ValueToConvert); break; case "CtoK": var CtoK = new CelsiusToKelvin(); model.ConvertedValue = CtoK.Temp(model.ValueToConvert); break; case "KtoC": var KtoC = new KelvinToCelsius(); model.ConvertedValue = KtoC.Temp(model.ValueToConvert); break; case "fToK": var fToK = new FahrenheitToKelvin(); model.ConvertedValue = fToK.Temp(model.ValueToConvert); break; case "kToF": var kToF = new KelvinToFahrenheit(); model.ConvertedValue = kToF.Temp(model.ValueToConvert); break; //LENGTH case "mToF": var mToF = new MetersToFeet(); model.ConvertedValue = mToF.Lengths(model.ValueToConvert); break; case "fToM": var fToM = new FeetToMeters(); model.ConvertedValue = fToM.Lengths(model.ValueToConvert); break; case "mtoY": var mtoY = new MetersToYard(); model.ConvertedValue = mtoY.Lengths(model.ValueToConvert); break; case "ytoM": var ytoM = new YardToMeter(); model.ConvertedValue = ytoM.Lengths(model.ValueToConvert); break; case "fToY": var fToY = new FeetToYards(); model.ConvertedValue = fToY.Lengths(model.ValueToConvert); break; case "yToF": var yToF = new YardToFeet(); model.ConvertedValue = yToF.Lengths(model.ValueToConvert); break; //MASS case "gToK": var gToK = new GramToKilogram(); model.ConvertedValue = gToK.Mass(model.ValueToConvert); break; case "kToG": var kToG = new KilogramToGram(); model.ConvertedValue = kToG.Mass(model.ValueToConvert); break; case "gToO": var gToO = new GramToOunces(); model.ConvertedValue = gToO.Mass(model.ValueToConvert); break; case "oToG": var oToG = new OuncesToGram(); model.ConvertedValue = oToG.Mass(model.ValueToConvert); break; case "gToP": var gToP = new GramToPound(); model.ConvertedValue = gToP.Mass(model.ValueToConvert); break; case "pToG": var pToG = new PoundToGram(); model.ConvertedValue = pToG.Mass(model.ValueToConvert); break; case "pToO": var pToO = new PoundsToOunces(); model.ConvertedValue = pToO.Mass(model.ValueToConvert); break; case "oToP": var oToP = new OuncesToPounds(); model.ConvertedValue = oToP.Mass(model.ValueToConvert); break; case "kToO": var kToO = new KilogramToOunce(); model.ConvertedValue = kToO.Mass(model.ValueToConvert); break; case "oToK": var oToK = new OuncesToKilogram(); model.ConvertedValue = oToK.Mass(model.ValueToConvert); break; case "pToK": var pToK = new PoundsToKilogram(); model.ConvertedValue = pToK.Mass(model.ValueToConvert); break; case "KToP": var KToP = new KilogramToPound(); model.ConvertedValue = KToP.Mass(model.ValueToConvert); break; default: break; } //the conversion work happen in here //cToF.Temp(tempIn); return(View(model)); }