public ActionResult Save(StudentResult aStudentResult)
 {
     ViewBag.response = aResultManager.Save(aStudentResult);
     ViewBag.Students = aStudentManager.GetStudentSelectView();
     ViewBag.Grades = aGradeManager.GetAllGrades();
     return View();
 }
        public bool IsAlreadySaved(StudentResult aStudentResult)
        {
            string query = "SELECT * FROM StudentResults WHERE StudentId =@stdId AND CourseId =@courseId AND IsCurrent =1";
            using (connection = new SqlConnection(connectionString))
            using (SqlCommand command = new SqlCommand(query, connection))
            {
                command.Parameters.Clear();
                command.Parameters.Add("stdId", sqlDbType: SqlDbType.Int);
                command.Parameters["stdId"].Value = aStudentResult.StudentId;

                command.Parameters.Add("courseId", sqlDbType: SqlDbType.Int);
                command.Parameters["courseId"].Value = aStudentResult.CourseId;

                connection.Open();
                SqlDataReader reader = command.ExecuteReader();
                return reader.HasRows;
            }
        }
        public void Save(StudentResult aStudentResult)
        {
            string query = "INSERT INTO StudentResults (StudentId, CourseId, GradeId, IsCurrent) VALUES (@stdId, @courseId, @gradeId, @isCurrent)";
            using (connection = new SqlConnection(connectionString))
            using (SqlCommand command = new SqlCommand(query, connection))
            {
                command.Parameters.Clear();
                command.Parameters.Add("stdId", sqlDbType: SqlDbType.Int);
                command.Parameters["stdId"].Value = aStudentResult.StudentId;

                command.Parameters.Add("courseId", sqlDbType: SqlDbType.Int);
                command.Parameters["courseId"].Value = aStudentResult.CourseId;

                command.Parameters.Add("gradeId", sqlDbType: SqlDbType.Int);
                command.Parameters["gradeId"].Value = aStudentResult.GradeId;

                command.Parameters.Add("isCurrent", sqlDbType: SqlDbType.Bit);
                command.Parameters["isCurrent"].Value = aStudentResult.IsCurrent;

                connection.Open();
                command.ExecuteNonQuery();
            }
        }
        public ActionResponse Save(StudentResult aStudentResult)
        {
            ActionResponse response = new ActionResponse();
            try
            {
                bool isAlreadySaved = aResultGateway.IsAlreadySaved(aStudentResult);
                if (isAlreadySaved)
                {
                    response.Class = "danger";
                    response.Message = "This result is already saved.";
                    return response;
                }

                aResultGateway.Save(aStudentResult);
                response.Class = "success";
                response.Message = "Reasult Saved Successfully.";
            }
            catch (SqlException ex)
            {
                response.Class = "warning";
                response.Message = ex.Message;
            }
            return response;
        }