public ActionResult Index(CalcModel model) { model.OperationList = Calc.Operations .Select(o => new SelectListItem() { Text = $"{o.Name}", Value = $"{o.Name}", Selected = model.Operation == o.Name }); var operation = Calc.Operations.FirstOrDefault(o => o.Name == model.Operation); if (operation != null) { var dbOper = OperationRepository.GetByName(operation.Name); var operId = dbOper.Id; var inputData = string.Join(",", model.Arguments); var oldResult = ORRepository.GetOldResult(operId, inputData); if (!double.IsNaN(oldResult)) { model.Result = oldResult; } else { #region вычисление model.Result = operation.Execute(model.Arguments); var rec = ORRepository.Create(); //текущего пользователя назначаем автором var currUser = UserRepository.GetByName(User.Identity.Name); rec.Author = currUser; rec.Operation = dbOper; rec.ExecutionDate = DateTime.Now; rec.ExecutionTime = new Random().Next(0, 100); rec.InputData = inputData; rec.Result = model.Result ?? Double.NaN; ORRepository.Update(rec); #endregion } return(View(model)); } return(View()); }