示例#1
0
        public HttpResponseMessage GetCourseListByStuIdAndTerm([FromBody] JObject stuIdAndTerm)
        {
            List <Dictionary <string, string> > retData = new List <Dictionary <string, string> >();
            Dictionary <string, string>         courseInfo;

            try
            {
                string signature = HttpUtil.GetAuthorization(Request);
                if (signature == null || !redis.IsSet(signature))
                {
                    return(new Response(2001, "未登录账户").Convert());
                }
                var    jsonParams = Request.GetQueryNameValuePairs().ToDictionary(k => k.Key, v => v.Value);
                string term       = jsonParams["term"];
                bool   isLogin    = redis.IsSet(signature);
                if (!isLogin)
                {
                    return(new Response(2001, "未登录账户").Convert());
                }
                string        targetId   = redis.Get <string>(signature);
                int           termId     = CourseDao.GetTermByName(term).id;
                List <Course> courseList = CourseDao.GetCoursesByStuIdAndTermId(targetId, termId).ToList();
                foreach (Course c in courseList)
                {
                    courseInfo = new Dictionary <string, string>
                    {
                        { "id", c.id.ToString() },
                        { "name", c.name },
                    };
                    if (c.term_id == null)
                    {
                        courseInfo.Add("semester", "");
                    }
                    else
                    {
                        courseInfo.Add("semester", CourseDao.GetTermById((int)c.term_id).name);
                    }
                    courseInfo.Add("teacher", UserDao.GetUserById(c.teacher_id).name);
                    courseInfo.Add("department", CourseDao.GetDepartmentById(c.department_id).name);
                    retData.Add(courseInfo);
                }
                return(new Response(1001, "获取成功", retData).Convert());
            }
            catch (Exception e)
            {
                ErrorLogUtil.WriteLogToFile(e, Request);
                return(Response.Error());
            }
        }