private ActionResult CheckCurrentQuestion(QuestionInProgresWrapper result, ResponseAction response, int userId,
     Action action, TestInProgres currentQuestion, UsersContext db)
 {
     try
     {
         if (currentQuestion.Question.TestType == DataConst.CheckedType)
         {
             SaveResultOfCheckedQuestion(result, currentQuestion, db);
         }
         if (currentQuestion.Question.TestType == DataConst.RadioType)
         {
             SaveResultOfRadioQuestion(result, currentQuestion, db);
         }
        return ExecuteCommand(response, userId, action, currentQuestion, db);
     }
     catch (Exception)
     {
         ViewBag.WarningMessage = DataConst.WarningErrorMessage;
         return RedirectToAction("TestInAction", "Test", new { number = 1 });
     }
 }
 private ActionResult ExecuteCommand(ResponseAction response, int userId,
     Action action, TestInProgres currentQuestion, UsersContext db
     )
 {
     switch (response.Command)
     {
         case DataConst.Subbmit:
         {
             SubbmitTest(userId, currentQuestion, action, db);
             return RedirectToAction("Results", "Result");
         }
         case DataConst.Next:
         {
             if (response.CurrentNumber.HasValue)
             {
                 return RedirectToAction("TestInAction", "Test", new { number = response.CurrentNumber + 1});
             }
             break;
         }
         case DataConst.Prev:
         {
             if (response.CurrentNumber.HasValue)
             {
                 return RedirectToAction("TestInAction", "Test", new { number = response.CurrentNumber - 1 });
             }
             break;
         }
         case DataConst.GoTo:
         {
             if (response.GoTo.HasValue)
             {
                 return RedirectToAction("TestInAction", "Test", new { number = response.GoTo });
             }
             break;
         }
     }
     ViewBag.WarningMessage = DataConst.WarningErrorMessage;
     return RedirectToAction("TestInAction", "Test", new { number = 1 });
 }
 public ActionResult GoToQuestion(QuestionInProgresWrapper result, string submit)
 {
     using (var db = new UsersContext())
     {
         var userId = WebSecurity.GetUserId(User.Identity.Name);
         var action = db.Actions.FirstOrDefault(a => a.User.UserId == userId && a.Status == 1);
         var response = new ResponseAction(submit);
         if (action != null && response.CurrentNumber != null)
         {
             var currentQuestion =
                 action.TestsInProgres.FirstOrDefault(q => q.Question.Number == response.CurrentNumber);
             if (currentQuestion != null)
             {
                return CheckCurrentQuestion(result, response, userId, action, currentQuestion, db);
             }
         }
     }
     ViewBag.WarningMessage = DataConst.WarningMessageForTest;
     return RedirectToAction("TestInAction", "Test", new { number = 1 });
 }