Example #1
0
 // 添加用户对课程的打分
 public static bool AddScore(CUS cus)
 {
     if (CourseDao.SelectCourseById(cus.CourseId) == null)
     {
         return(false);
     }
     if (UserDao.SelectUserByUserName(cus.UserName) == null)
     {
         return(false);
     }
     context.CUS.Add(cus);
     return(context.SaveChanges() >= 1);
 }
Example #2
0
        // 查询课程平均分
        public static double GetAveScoreByCourseId(string id)
        {
            if (CourseDao.SelectCourseById(id) == null)
            {
                return(0);
            }
            List <CUS> cusList    = context.CUS.Where(cus => cus.CourseId.Equals(id)).ToList();
            int        totalScore = 0;

            foreach (CUS cus in cusList)
            {
                totalScore += cus.Score;
            }
            return(totalScore * 1.0 / cusList.Count);
        }