Beispiel #1
0
        public ActionResult Index(ScenariosToGrade stg)
        {
            if (String.IsNullOrEmpty((string)Session["userId"]))
            {
                return(RedirectToAction("Login", "Account"));
            }
            ScenariosToGradeList stgList;

            try
            {
                ((ScenarioToGrade)Session["scenarioToGrade"]).stgID       = Convert.ToInt32(Request["stgId"]);
                ((ScenarioToGrade)Session["scenarioToGrade"]).stgGrade    = Convert.ToInt32(Request["stgGrade"]);
                ((ScenarioToGrade)Session["scenarioToGrade"]).stgComments = Request["stgComments"];

                DatabaseUtils.addGradeForScenario(((ScenarioToGrade)Session["scenarioToGrade"]).stgID, ((ScenarioToGrade)Session["scenarioToGrade"]).stgGrade, ((ScenarioToGrade)Session["scenarioToGrade"]).stgComments);
                //Call database command passing it Singleton.scenarioToGrade
                stgList = DatabaseUtils.getScenariosToGrade();
            }
            catch (Exception ex)
            {
                Singleton.errorCode = "GRASEN02";
                Singleton.writeErrorToFile(Singleton.errorCode, ex.Message, ex.StackTrace);
                throw ex;
            }
            return(View(stgList));
        }
        public ActionResult Grades(ScenariosToGrade stg)
        {
            if (String.IsNullOrEmpty((string)Session["userId"]))
            {
                return(RedirectToAction("Login", "Account"));
            }
            try
            {
                ((ScenarioToGrade)Session["scenarioToGrade"]).stgID       = Convert.ToInt32(Request["stgId"]);
                ((ScenarioToGrade)Session["scenarioToGrade"]).stgGrade    = Convert.ToInt32(Request["stgGrade"]);
                ((ScenarioToGrade)Session["scenarioToGrade"]).stgComments = Request["stgComments"];

                DatabaseUtils.addGradeForScenario(((ScenarioToGrade)Session["scenarioToGrade"]).stgID, ((ScenarioToGrade)Session["scenarioToGrade"]).stgGrade, ((ScenarioToGrade)Session["scenarioToGrade"]).stgComments);
                String name = ((StudentGrades)Session["studentGrades"]).studentName;
                Session["studentGrades"] = DatabaseUtils.getStudentGrades(((ScenarioToGrade)Session["scenarioToGrade"]).stgStudentID);
                ((StudentGrades)Session["studentGrades"]).studentName = name;
            }
            catch (Exception ex)
            {
                Singleton.errorCode = "STUCON02";
                Singleton.writeErrorToFile(Singleton.errorCode, ex.Message, ex.StackTrace);
                throw ex;
            }
            return(View(((StudentGrades)Session["studentGrades"])));
        }
        /*
         * This function will return a list of scenarios to grade.
         */

        public static ScenariosToGradeList getScenariosToGrade(SqlConnection connection)
        {
            var scenariosToGradeList = new ScenariosToGradeList();

            scenariosToGradeList.scenariosToGrade = new List <ScenariosToGrade>();
            try
            {
                var questionCommand = new SqlCommand(null, connection);

                questionCommand.CommandText = "SELECT SCENARIOS_TO_GRADE.STG_ID, " +
                                              "SCENARIOS.SCENARIO_ID, " +
                                              "SCENARIOS.SCENARIO_NAME, " +
                                              "STUDENTS.STUDENT_ID, " +
                                              "STUDENTS.STUDENT_NAME " +
                                              "FROM SCENARIOS_TO_GRADE " +
                                              "JOIN STUDENTS ON SCENARIOS_TO_GRADE.STG_STUDENT_ID = STUDENTS.STUDENT_ID " +
                                              "JOIN SCENARIOS ON SCENARIOS_TO_GRADE.STG_SCENARIO_ID = SCENARIOS.SCENARIO_ID " +
                                              "WHERE SCENARIOS_TO_GRADE.STG_GRADE IS NULL;";


                connection.Close(); connection.Open();
                questionCommand.Prepare();
                using (var reader = questionCommand.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        var scenariosToGrade = new ScenariosToGrade();
                        scenariosToGrade.stgID           = Convert.ToInt32($"{reader["STG_ID"]}");
                        scenariosToGrade.stgScenarioID   = Convert.ToInt32($"{reader["SCENARIO_ID"]}");
                        scenariosToGrade.stgScenarioName = $"{reader["SCENARIO_NAME"]}";
                        scenariosToGrade.stgStudentID    = $"{reader["STUDENT_ID"]}";
                        scenariosToGrade.stgStudentName  = $"{reader["STUDENT_NAME"]}";

                        scenariosToGradeList.scenariosToGrade.Add(scenariosToGrade);
                    }
                }
            }
            catch (Exception ex)
            {
                Singleton.errorCode = "SEN11";
                Singleton.writeErrorToFile(Singleton.errorCode, ex.Message, ex.StackTrace);
                throw ex;
            }
            finally
            {
                connection.Close();
            }
            return(scenariosToGradeList);
        }