public bool IsStudentResultExists(StudentResult studentResult)
        {
            connection.ConnectionString = connectionString;

            string query = "SELECT * FROM StudentResult WHERE RegNo =@RegNo AND CourseId=@CourseId";
            SqlCommand command = new SqlCommand(query, connection);
            command.Parameters.Clear();
            command.Parameters.Add("RegNo", SqlDbType.VarChar);
            command.Parameters["RegNo"].Value = studentResult.RegNo;
            command.Parameters.Add("CourseId", SqlDbType.Int);
            command.Parameters["CourseId"].Value = studentResult.CourseId;
            connection.Open();
            SqlDataReader reader = command.ExecuteReader();

            if (reader.HasRows)
            {
                connection.Close();
                return true;
            }
            else
            {
                connection.Close();
                return false;
            }
        }
 public ActionResult SaveStudentResult(StudentResult studentResult)
 {
     ViewBag.Message = studentResultManager.Save(studentResult);
     List<Student> students = studentManager.GetAllStudent();
     ViewBag.StudentList = students;
     ViewBag.Grade = GetGrade();
     return View();
 }
 public int Save(StudentResult studentResult)
 {
     connection.ConnectionString = connectionString;
     string query = "INSERT INTO StudentResult(RegNo,CourseId,Grade) VALUES(@RegNo,@CourseId,@Grade)";
     SqlCommand command = new SqlCommand(query, connection);
     command.Parameters.Clear();
     command.Parameters.Add("RegNo", SqlDbType.VarChar);
     command.Parameters["RegNo"].Value = studentResult.RegNo;
     command.Parameters.Add("CourseId", SqlDbType.Int);
     command.Parameters["CourseId"].Value = studentResult.CourseId;
     command.Parameters.Add("Grade", SqlDbType.VarChar);
     command.Parameters["Grade"].Value = studentResult.Grade;
     connection.Open();
     int rowAffected = command.ExecuteNonQuery();
     connection.Close();
     return rowAffected;
 }
 public string Save(StudentResult studentResult)
 {
     if (studentResultGateway.IsStudentResultExists(studentResult))
     {
         return "This student is already evaluated";
     }
     else
     {
         if (studentResultGateway.Save(studentResult) > 0)
         {
             return "Saved";
         }
         else
         {
             return "Save failed";
         }
     }
 }