删除年级
控制器
#region 删除年级
public ActionResult DeleteGrade(int GradeID)// 删除年级
{
ReturnJson msg = new ReturnJson();
msg.State = false;
// 通过年级ID查询年级
var Student = ChongQing.PW_Student.Where(m => m.GradeID == GradeID).ToList();
// 通过年级ID查询班级
var Grade = ChongQing.SYS_Grade.Where(m => m.GradeID == GradeID).ToList();
// 通过年级ID查询学生
var Class = ChongQing.SYS_Class.Where(m => m.GradeID == GradeID).ToList();
try
{
if (Class.Count() == 0)
{
if (Student.Count() == 0)
{
if (Grade.Count > 0)
{
ChongQing.SYS_Grade.Remove(Grade[0]);
if (ChongQing.SaveChanges() > 0)
{
msg.State = true;
msg.Text = "删除成功!";
}
else
{
msg.Text = "删除失败!";
}
}
else
{
msg.Text = "该年级不存在!";
}
}
else
{
msg.Text = "该年级存在学生,不能删除!";
}
}
else
{
msg.Text = "该年级存在班级,不能删除!";
}
}
catch (Exception)
{
msg.Text = "数据异常!";
}
return Json(msg, JsonRequestBehavior.AllowGet);// 删除年级
}
#endregion
JavaScript