public FourBandResistorCalculator(IFourColorCodeBandsViewModel colorCodeBandsViewModel) =>
 public IActionResult Calculate(string bandAColor, string bandBColor, string bandCColor, string bandDColor
                                , [FromServices] IOhmValueCalculator fourBandResistorCalculator
                                , [FromServices] IFourColorCodeBandsViewModel fourColorCodeBandsViewModel) =>
 Json(fourBandResistorCalculator.CalculateOhmValue(bandAColor, bandBColor, bandCColor, bandDColor)
      .ToFormattedOhms(bandDColor, fourColorCodeBandsViewModel));
        public static string ToFormattedOhms(this decimal?decimalValue, string bandDColor, IFourColorCodeBandsViewModel fourColorCodeBandsViewModel)
        {
            // if no value then just return null
            if (!decimalValue.HasValue)
            {
                return(null);
            }

            // if there is no selected bandDColor, then just return default of plus minus 20%
            if (string.IsNullOrWhiteSpace(bandDColor))
            {
                return(string.Concat(decimalValue.ToFormattedDecimalString(), WhiteSpaceString, OhmsString, WhiteSpaceString, TwentyPercentPlusMinusToleranceString));
            }

            // try to get band D color from input; if not found, then throw exception since the user tried to submit -- this should not occur
            var bandDcolor = fourColorCodeBandsViewModel.BandDAvailableColors.FirstOrDefault(x => string.Equals(x.Name, bandDColor, StringComparison.OrdinalIgnoreCase));

            if (bandDcolor == null)
            {
                throw new InvalidOperationException($"{bandDColor} is not an available color for Band D.");
            }

            // return the fully formatted string
            return(string.Concat(decimalValue.ToFormattedDecimalString(), WhiteSpaceString, OhmsString, WhiteSpaceString, bandDcolor.Tolerance.Value.ToString(PercentFormatString)));
        }
 public IActionResult Index([FromServices] IFourColorCodeBandsViewModel viewModel) =>
 View(viewModel);