public ActionResult Index(SolutionViewModel solutionViewModel) { var resultViewModel = new ResultViewModel(); var solver = new EquationSolver(); if (solver.IsInCorrectFormat(solutionViewModel.Solution)) { if (solver.Solve(solutionViewModel.Solution)) { resultViewModel.HasSolution = true; resultViewModel.Message = "Well done :) "; resultViewModel.Time = TimeSpan.FromSeconds(solutionViewModel.Duration); resultViewModel.Equation = solutionViewModel.Equation; resultViewModel.Solution = solver.Format(solutionViewModel.Solution); } else { resultViewModel.Message = "Sides not equal - try again!"; } } else { resultViewModel.Message = "Format error - try again!"; } return View(resultViewModel); }
private static bool Solve(string equation) { var solver = new EquationSolver(); if (!solver.IsInCorrectFormat(equation)) return false; return solver.Solve(equation); }