Ejemplo n.º 1
0
        //增加一条评论
        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("该数据已存在");
                }
            }
        }
Ejemplo n.º 2
0
 //根据学号删除
 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();
         }
     }
 }
Ejemplo n.º 3
0
 //删除一条记录
 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();
         }
     }
 }
Ejemplo n.º 4
0
 //根据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("记录不存在");
         }
     }
 }
Ejemplo n.º 5
0
 //根据评论内容删除记录
 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("记录不存在");
         }
     }
 }
Ejemplo n.º 6
0
 //根据用户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("记录不存在");
         }
     }
 }
Ejemplo n.º 7
0
 //增加点赞数
 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("不存在记录");
         }
     }
 }
Ejemplo n.º 8
0
 //根据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("不存在记录");
         }
     }
 }
Ejemplo n.º 9
0
 //根据课程名删除一条记录
 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("不存在该记录");
         }
     }
 }
Ejemplo n.º 10
0
 //增加一条新鲜事
 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("该数据已存在");
         }
     }
 }
Ejemplo n.º 11
0
 //根据评论,修改评论内容
 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("记录不存在");
         }
     }
 }
Ejemplo n.º 12
0
 //增加
 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("该数据已存在");
         }
     }
 }
Ejemplo n.º 13
0
 //根据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("记录不存在");
         }
     }
 }
Ejemplo n.º 14
0
 //删除所有数据
 public void DeleteAll()
 {
     using (var context = new compusDB())
     {
         var comm = context.Comment.ToList();
         if (comm != null)
         {
             foreach (Comment co in comm)
             {
                 context.Comment.Remove(co);
                 Console.WriteLine("已删除");
             }
             context.SaveChanges();
         }
         else
         {
             Console.WriteLine("记录不存在");
         }
     }
 }
Ejemplo n.º 15
0
 public void Add(User us)
 {
     using (var context = new compusDB())
     {
         var use = context.User.Where(p => p.id == us.id).FirstOrDefault();
         if (use == null)
         {
             use = us;
             context.User.Add(us);
             try { context.SaveChanges(); }
             catch (Exception e)
             {
                 Console.WriteLine(e);
                 Console.ReadLine();
             }
         }
         else
         {
             Console.WriteLine("数据已存在");
         }
     }
 }
Ejemplo n.º 16
0
 public void modifiedCouseScore(short score, double gradePoint, long courseid, long userid, string courseType, short credits, string teacherName, string school, int yea, bool term)
 {
     using (var context = new compusDB())
     {
         var cs = context.CourseScore.FirstOrDefault(p => p.userid == userid && p.courseid == courseid);
         if (cs != null)
         {
             cs.score       = score;
             cs.gradePoint  = gradePoint;
             cs.courseType  = courseType;
             cs.credits     = credits;
             cs.teacherName = teacherName;
             cs.school      = school;
             cs.Year        = yea;
             cs.Term        = term;
             context.SaveChanges();
         }
         else
         {
             Console.WriteLine("不存在该记录");
         }
     }
 }