public IActionResult Index(string expressionOperation = null) { var success = Enum.TryParse(expressionOperation ?? ExpressionOperation.Addition.ToString(), out ExpressionOperation chosenOperation); if (!success) { chosenOperation = ExpressionOperation.Addition; } var model = new IndexViewModel(); model.InitializeSelectLists( this.expressionExtractor.Extract(new List <ExpressionOperation> { chosenOperation }), this.HttpContext.GetLanguageFromCookie()); model.ChosenExpressionOperation = chosenOperation.ToString(); return(View(model)); }
public async Task <IActionResult> Index(IndexViewModel model) { if (model.SelectedVariableSymbol.IsNotNullOrWhiteSpace()) { Constants.VariableSymbol = model.SelectedVariableSymbol; } model.InitializeSelectLists( this.expressionExtractor.Extract(new List <ExpressionOperation> { Enum.Parse <ExpressionOperation>(model.ChosenExpressionOperation) }), this.HttpContext.GetLanguageFromCookie()); if (!this.ModelState.IsValid) { return(View(model)); } var chosenExpressionType = Assembly .GetAssembly(typeof(IMathExpression)) .GetType(model.ChosenExpressionType); var mathExpressions = this.mathService.GenerateMathExpressions( chosenExpressionType, model.OperandMinValue, model.OperandMaxValue, model.ExpressionsCount, model.ShouldRandomize, model.SelectedVariableSymbol); if (mathExpressions.Any()) { await this.sessionContainer.AddAsync(this.HttpContext, mathExpressions); } return(View(model)); }