Beispiel #1
0
        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();
            }
        }
Beispiel #2
0
        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 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());
        }