コード例 #1
0
        public IActionResult Create(SolvingViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var sqlTask = _context.SqlTasks
                          .FirstOrDefault(t => t.Id == model.SqlTaskId);

            if (sqlTask == null)
            {
                ModelState.AddModelError("task", $"Task {model.SqlTaskId} not found!");
                return(View(model));
            }

            var newSolving = new SqlSolving
            {
                SqlTaskId         = sqlTask.Id,
                IsCorrect         = false,
                ApplicationUserId = Me.Id,
                Solving           = model.MySolving,
                SolvedAt          = DateTime.Now
            };

            _context.SqlSolvings.Add(newSolving);


            var completeQuery = model.Creates
                                + Sep
                                + model.Inserts
                                + Sep
                                + model.MySolving;

            var myOutput = "";

            _sandboxService.TryExecuteQuery(completeQuery, ref myOutput);
            _sandboxService.FlushDatabase();
            if (myOutput == sqlTask.SolvingOutput)
            {
                newSolving.IsCorrect = true;
                _context.SaveChanges();
                return(RedirectToAction("Index"));
            }
            ModelState.AddModelError("sql", myOutput);

            _context.SaveChanges();
            return(View(model));
        }
コード例 #2
0
        public IActionResult Create(int id)
        {
            var sqlTask = _context.SqlTasks
                          .FirstOrDefault(t => t.Id == id);

            if (sqlTask == null)
            {
                return(RedirectToAction("Index"));
            }

            var model = new SolvingViewModel
            {
                SqlTaskId   = sqlTask.Id,
                Creates     = sqlTask.Creates,
                Inserts     = sqlTask.Inserts,
                Name        = sqlTask.Name,
                Description = sqlTask.Description
            };

            return(View(model));
        }
コード例 #3
0
 public MainViewModel()
 {
     Migration = new MigrationViewModel();
     Solving   = new SolvingViewModel();
     Fuzzy     = new FuzzyViewModel();
 }