コード例 #1
0
 public UserModel InsertUser(UserModel user)
 {
     try
     {
         using (var db = new AnnotateWebPageDBEntities())
         {
             var resp = GetUser(user.id);
             if (GetUser(user.id) == null)
             {
                 User newUser = new User()
                 {
                     id = user.id, name = user.name
                 };
                 db.User.Add(newUser);
                 db.SaveChanges();
                 return(user);
             }
             return(null);
         }
     }
     catch (Exception e)
     {
         //throw;
         return(null);
     }
 }
コード例 #2
0
        public HighlightModel InsertHighlight(HighlightModel highlight)
        {
            try
            {
                HighlightModel old = null;
                using (var db = new AnnotateWebPageDBEntities())
                {
                    old = GetHighlight(highlight.id);
                }
                if (old == null)
                {
                    // generate new id
                    using (var db = new AnnotateWebPageDBEntities())
                    {
                        //var nextId = db.Highlight.ToList().Max(hg => hg.id) + 1;
                        //highlight.id = nextId;
                        Highlight newHighlight = db.Highlight.Add(new Highlight()
                        {
                            user_id = highlight.user_id, web_page = highlight.web_page, start = highlight.start, end = highlight.end, color = highlight.color
                        });
                        db.SaveChanges();
                        highlight.id = newHighlight.id;
                    }

                    return(highlight);
                }
                else //update
                {
                    Highlight updateHighlight = null;
                    using (var db = new AnnotateWebPageDBEntities())
                    {
                        updateHighlight = db.Highlight.Where(s => s.id == highlight.id).FirstOrDefault <Highlight>();
                    }

                    if (updateHighlight != null)
                    {
                        updateHighlight.user_id  = highlight.user_id;
                        updateHighlight.web_page = highlight.web_page;
                        updateHighlight.start    = highlight.start;
                        updateHighlight.end      = highlight.end;
                        updateHighlight.color    = highlight.color;
                    }

                    using (var db = new AnnotateWebPageDBEntities())
                    {
                        db.Entry(updateHighlight).State = System.Data.Entity.EntityState.Modified;
                        db.SaveChanges();
                    }
                    return(highlight);
                }
            }
            catch (Exception e)
            {
                return(null);
            }
        }
コード例 #3
0
 public bool DeleteHighlight(int highlightId)
 {
     using (var db = new AnnotateWebPageDBEntities())
     {
         Highlight highlight = db.Highlight.Where(s => s.id == highlightId).FirstOrDefault <Highlight>();
         if (highlight != null)
         {
             db.Highlight.Remove(highlight);
             db.SaveChanges();
             return(true);
         }
     }
     return(false);
 }
コード例 #4
0
 public bool DeleteComment(int id)
 {
     using (var db = new AnnotateWebPageDBEntities())
     {
         var comment = db.Comment.Where(c => c.id == id).FirstOrDefault <Comment>();
         if (comment != null)
         {
             db.Comment.Remove(comment);
             db.SaveChanges();
             return(true);
         }
         return(false);
     }
 }
コード例 #5
0
 public CommentModel InsertComment(CommentModel comment)
 {
     try
     {
         using (var db = new AnnotateWebPageDBEntities())
         {
             Comment newComment = new Comment()
             {
                 id = comment.id, text = comment.text, color = comment.color, user_id = comment.user_id, web_page = comment.web_page
             };
             db.Comment.Add(newComment);
             db.SaveChanges();
             return(comment);
         }
     }
     catch (Exception e)
     {
         throw;
     }
 }
コード例 #6
0
 public bool UpdateComment(int id, CommentModel newComment)
 {
     try
     {
         using (var db = new AnnotateWebPageDBEntities())
         {
             var comment = db.Comment.Where(c => c.id == id).FirstOrDefault <Comment>();
             if (comment != null)
             {
                 comment.text  = newComment.text;
                 comment.color = newComment.color;
                 db.SaveChanges();
                 return(true);
             }
             return(false);
         }
     }
     catch (Exception e)
     {
         throw;
     }
 }