public static string ToJsonString(RankingsModel model)
 {
     if (model != null)
     {
         return(JsonConvert.SerializeObject(model));
     }
     else
     {
         return(null);
     }
 }
Пример #2
0
        public static RankingsModel GetRankings(int userID, int semester, int year)
        {
            RankingsModel scoreByCategory = null;
            SqlConnection connection      = GetConnection();

            string selectStatement = "EXEC GetRankings @userID, @semester, @year";

            SqlCommand command = new SqlCommand(selectStatement, connection);

            command.Parameters.AddWithValue("userID", userID);
            command.Parameters.AddWithValue("semester", semester);
            command.Parameters.AddWithValue("year", year);

            try
            {
                connection.Open();
                SqlDataReader reader = command.ExecuteReader();
                scoreByCategory = new RankingsModel();
                while (reader.Read())
                {
                    var data = new RankingsModel.Data();
                    data.CourseID          = Convert.ToInt32(reader["CSID"]);
                    data.Crn               = Convert.ToInt32(reader["bannerCRN"]);
                    data.Marker            = reader["marker"].ToString();
                    data.Semester          = Convert.ToInt32(reader["semester"]);
                    data.Year              = Convert.ToInt32(reader["year"]);
                    data.Course            = reader["course"].ToString();
                    data.instructorName    = reader["iName"].ToString();
                    data.InstructorAverage = Convert.ToDouble(reader["InstructorAverage"].ToString());
                    data.StudentCount      = Convert.ToInt32(reader["StudentCount"]);
                    data.DecTile           = Convert.ToInt32(reader["DecTile"]);


                    scoreByCategory.DATA.Add(data);
                }

                return(scoreByCategory);
            }

            catch (SqlException ex)
            {
                return(null);
            }


            finally
            {
                connection.Close();
            }
        }