Exemplo n.º 1
0
        public JsonResult AddStudent(Student student)
        {
            ResultState resultState = CheckCookie();

            if (resultState.Code == 2)
            {
                if (StudentExits(student.StudentID))
                {
                    resultState.Message = "学生ID已存在,添加失败";
                    resultState.Success = false;
                    return(new JsonResult(resultState));
                }
                else
                {
                    _context.students.Add(student);
                    _context.SaveChangesAsync();
                    resultState.Message = "添加学生成功";
                    resultState.Success = true;
                    resultState.value   = student;
                }
            }
            else
            {
                resultState.Message = "您的权限被限制,请联系管理员获得权限";
                resultState.Success = false;
            }
            return(new JsonResult(resultState));
        }
Exemplo n.º 2
0
        public async Task <JsonResult> UpdateCourse(Course course)
        {
            ResultState resultState = CheckCookie();

            if (resultState.Code == 2)
            {
                var couInDb = await _context.Courses.FindAsync(course);

                if (couInDb.CourseID == course.CourseID &&
                    couInDb.Credits == course.Credits &&
                    couInDb.FinalWork == course.FinalWork &&
                    couInDb.Title == course.Title &&
                    couInDb.url == course.url
                    )
                {
                    resultState.Success = false;
                    resultState.Message = "课程信息没有变化";
                    return(new JsonResult(resultState));
                }
                else if (couInDb == null)
                {
                    resultState.Success = false;
                    resultState.Message = "无此课程信息";
                    return(new JsonResult(resultState));
                }
                else
                {
                    _context.Courses.Update(course);
                    await _context.SaveChangesAsync();

                    resultState.Success = true;
                    resultState.Message = "课程信息更新成功";
                    return(new JsonResult(resultState));
                }
            }
            return(new JsonResult(resultState));
        }