//a,b,c public List <CourseScore> QueryAll(string a, string b, string c, long ID) { List <CourseScore> forms = new List <CourseScore>(); using (var context = new compusDB()) { forms = context.CourseScore.Where(p => p.userid == ID).ToList(); if (a != "全部") { short year = Convert.ToInt16(a); forms = forms.Where(p => p.Year == year).ToList(); } if (b != "全部") { string type = b; forms = forms.Where(p => p.courseType == type).ToList(); } if (c != "全部") { bool term = (c == "2"); forms = forms.Where(p => p.Term == term).ToList(); } } foreach (CourseScore course in forms) { Console.WriteLine(course.courseType); } return(forms); }
//增加一条评论 public void Add(Comment comment) { using (var db = new compusDB()) { var com = db.Comment.Where(p => p.id == comment.id).FirstOrDefault(); if (com == null) { //防止在News再添加一个对象 var ne = db.News.Where(p => p.id == comment.newsid.id).FirstOrDefault(); comment.newsid = ne; comment.newsid.commentNum++;//对应的新鲜事的评论数加一 com = comment; db.Comment.Add(com); db.Configuration.ValidateOnSaveEnabled = false; db.SaveChanges(); db.Configuration.ValidateOnSaveEnabled = true; Console.WriteLine(com.text); } else { Console.WriteLine("该数据已存在"); } } }
//查询所有 public List <User> Query() { List <User> users = new List <User>(); using (var context = new compusDB()) { users = context.User.ToList(); } return(users); }
//删除一条记录 public void deleteCourseScore(short userId, long courseId) { using (var context = new compusDB()) { var score = context.CourseScore.FirstOrDefault(p => p.userid == userId && p.courseid == courseId); if (score != null) { context.CourseScore.Remove(score); context.SaveChanges(); } } }
//根据学号删除 public void Delect(long id) { using (var context = new compusDB()) { var us = context.User.Where(p => p.id == id).FirstOrDefault(); if (us != null) { context.User.Remove(us); context.SaveChanges(); } } }
//查询所有记录 public List <Course> queryAll(long id) { List <Course> cs = new List <Course>(); using (var context = new compusDB()) { cs = context.Course.Where(p => p.userid == id).ToList(); } foreach (Course course in cs) { Console.WriteLine(course.courseName); } return(cs); }
public List <CourseScore> Query2(string name) { List <CourseScore> cs = new List <CourseScore>(); using (var context = new compusDB()) { cs = context.CourseScore.Where(p => p.courseName == name).ToList(); } foreach (CourseScore course in cs) { Console.WriteLine(course.school); } return(cs); }
//查询 public List <CourseScore> Query() { List <CourseScore> cs = new List <CourseScore>(); using (var context = new compusDB()) { cs = context.CourseScore.ToList(); } foreach (CourseScore course in cs) { Console.WriteLine(course.school); } return(cs); }
//根据学号查询姓名 public string getName(long id) { using (var context = new compusDB()) { var users = context.User.Where(p => p.id == id).FirstOrDefault(); if (users != null) { return(users.nmae); } else { Console.WriteLine("不存在该记录"); return(null); } } }
//根据学号添加图片路径 public void addPic(long id, string address) { using (var context = new compusDB()) { var us = context.User.Where(p => p.id == id).FirstOrDefault(); if (us != null) { us.avatar = address; } else { Console.WriteLine("记录不存在"); } } }
//根据id查询 public News QueryId(long id) { using (var context = new compusDB()) { var news = context.News.Where(p => p.id == id).FirstOrDefault(); if (news != null) { return(news); } else { Console.WriteLine("记录不存在"); return(null); } } }
//根据发表内容查询 public News QueryText(string text) { using (var context = new compusDB()) { News news = new News(); news = context.News.Where(p => p.text == text).FirstOrDefault(); if (news != null) { return(news); } else { Console.WriteLine("记录不存在"); return(null); } } }
//根据新鲜事id查找记录 public List <Comment> queryNewId(long id) { using (var context = new compusDB()) { List <Comment> comm = new List <Comment>(); comm = context.Comment.Where(p => p.newsid.id == id).ToList(); if (comm != null) { return(comm); } else { Console.WriteLine("记录不存在"); return(null); } } }
//查找所有的评论 public List <Comment> Query() { using (var context = new compusDB()) { List <Comment> comm = new List <Comment>(); comm = context.Comment.ToList(); if (comm != null) { return(comm); } else { Console.WriteLine("记录不存在"); return(null); } } }
//根据评论内容查找记录 public Comment queryText(string text) { using (var context = new compusDB()) { Comment comm = new Comment(); comm = context.Comment.Where(p => p.text == text).FirstOrDefault(); if (comm != null) { return(comm); } else { Console.WriteLine("记录不存在"); return(null); } } }
//根据id删除数据 public void deleteId(long id) { using (var context = new compusDB()) { var ne = context.News.Where(p => p.id == id).FirstOrDefault(); if (ne != null) { context.News.Remove(ne); context.SaveChanges(); } else { Console.WriteLine("记录不存在"); } } }
//根据评论内容删除记录 public void delectText(string text) { using (var context = new compusDB()) { var comment = context.Comment.Where(p => p.text == text).FirstOrDefault(); if (comment != null) { context.Comment.Remove(comment); context.SaveChanges(); } else { Console.WriteLine("记录不存在"); } } }
//根据用户id删除该用户写的全部评论 public void delectUserId(int useid) { using (var context = new compusDB()) { var comment = context.Comment.Where(p => p.userid == userid).FirstOrDefault(); if (comment != null) { context.Comment.Remove(comment); context.SaveChanges(); } else { Console.WriteLine("记录不存在"); } } }
//根据userid查询 public List <News> QueryUserId(long userid) { using (var context = new compusDB()) { List <News> news = new List <News>(); news = context.News.Where(p => p.userid == userid).ToList(); if (news != null) { return(news); } else { Console.WriteLine("记录不存在"); return(null); } } }
//根据名字修改头像路径 public void ModifyName(long name, string address) { using (var context = new compusDB()) { User users = new User(); users = context.User.Where(p => p.nmae == nmae).FirstOrDefault(); if (users != null) { users.avatar = address; } else { Console.WriteLine("不存在该记录"); } } }
//根据名字查询 public User queryName(string names) { using (var context = new compusDB()) { User users = new User(); users = context.User.Where(p => p.nmae == nmae).FirstOrDefault(); if (users != null) { return(users); } else { return(null); Console.WriteLine("不存在该记录"); } } }
//查询所有 public List <News> Query() { using (var context = new compusDB()) { List <News> New = new List <News>(); New = context.News.OrderByDescending(News => News.id).ToList(); if (New != null) { return(New); } else { Console.WriteLine("无记录"); return(null); } } }
//根据学号查询 public User queryId(long id) { using (var context = new compusDB()) { User users = new User(); users = context.User.Where(p => p.id == id).FirstOrDefault(); if (users != null) { return(users); } else { return(null); Console.WriteLine("不存在该记录"); } } }
//根据课程名删除一条记录 public void Delete(string coName) { using (var context = new compusDB()) { var score = context.Course.FirstOrDefault(p => p.courseName == coName); if (score != null) { context.Course.Remove(score); context.SaveChanges(); Console.WriteLine("删除成功"); } else { Console.WriteLine("不存在该记录"); } } }
//增加点赞数 public void addRates(long id) { using (var context = new compusDB()) { var ne = context.News.Where(p => p.id == id).FirstOrDefault(); if (ne != null) { ne.rates++; Console.WriteLine(ne.rates); context.SaveChanges(); } else { Console.WriteLine("不存在记录"); } } }
//根据id修改,内容 public void Modify(long id, string text) { using (var context = new compusDB()) { var ne = context.News.Where(p => p.id == id).FirstOrDefault(); if (ne != null) { ne.text = text; Console.WriteLine(ne.text); context.SaveChanges(); } else { Console.WriteLine("不存在记录"); } } }
//增加 public void addCourseScore(CourseScore co) { using (var db = new compusDB()) { var courselist = db.CourseScore.Where(p => p.courseid == co.courseid).ToList(); var course = courselist.Where(p => p.userid == co.userid).FirstOrDefault(); if (course == null) { db.CourseScore.Add(co); db.SaveChanges(); Console.WriteLine(teacherName); } else { Console.WriteLine("该数据已存在"); } } }
//根据评论,修改评论内容 public void modifyText(string oldtext, string text) { using (var context = new compusDB()) { var comm = context.Comment.Where(p => p.text == oldtext).FirstOrDefault(); if (comm != null) { comm.text = text; comm.createdTime = System.DateTime.Now.ToString(); Console.WriteLine("已修改"); context.SaveChanges(); } else { Console.WriteLine("记录不存在"); } } }
//增加一条新鲜事 public void Add(News co) { using (var db = new compusDB()) { var ne = db.News.Where(p => p.id == co.id).FirstOrDefault(); if (ne == null) { ne = co; db.News.Add(ne); db.SaveChanges(); Console.WriteLine(ne.text); } else { Console.WriteLine("该数据已存在"); } } }
//根据userid删除数据 public void deleteUserId(long id) { using (var context = new compusDB()) { var ne = context.News.Where(p => p.userid == id).ToList(); if (ne != null) { foreach (News s in ne) { context.News.Remove(s); context.SaveChanges(); Console.WriteLine("已删除"); } } else { Console.WriteLine("记录不存在"); } } }