Пример #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 GetHighlight(int id)
        {
            try
            {
                using (var db = new AnnotateWebPageDBEntities())
                {
                    foreach (var highlight in db.Highlight)
                    {
                        if (highlight.id == id)
                        {
                            return new HighlightModel()
                                   {
                                       id = highlight.id, user_id = highlight.user_id, web_page = highlight.web_page, start = highlight.start, end = highlight.end, color = highlight.color
                                   }
                        }
                        ;
                    }

                    return(null);
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Пример #3
0
        public UserModel GetUser(string id)
        {
            try
            {
                using (var db = new AnnotateWebPageDBEntities())
                {
                    foreach (var user in db.User)
                    {
                        if (user.id.Equals(id))
                        {
                            return new UserModel()
                                   {
                                       id = user.id, name = user.name
                                   }
                        }
                        ;
                    }

                    return(null);
                }
            }
            catch (Exception e)
            {
                // throw;
                return(null);
            }
        }
 public List <CommentModel> GetComment(string userId, string url)
 {
     try
     {
         using (var db = new AnnotateWebPageDBEntities())
         {
             List <CommentModel> comments = new List <CommentModel>();
             foreach (var comment in db.Comment)
             {
                 if (comment.user_id.Equals(userId) && comment.web_page.Equals(url))
                 {
                     comments.Add(new CommentModel()
                     {
                         id = comment.id, text = comment.text, color = comment.color, user_id = comment.user_id, web_page = comment.web_page
                     });
                 }
             }
             return(comments);
         }
     }
     catch (Exception e)
     {
         throw;
     }
 }
        public CommentModel GetComment(int id)
        {
            try
            {
                using (var db = new AnnotateWebPageDBEntities())
                {
                    foreach (var comment in db.Comment)
                    {
                        if (comment.id == id)
                        {
                            return new CommentModel()
                                   {
                                       id = comment.id, text = comment.text, color = comment.color, user_id = comment.user_id, web_page = comment.web_page
                                   }
                        }
                        ;
                    }

                    return(null);
                }
            }
            catch (Exception e)
            {
                throw;
            }
        }
Пример #6
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);
            }
        }
Пример #7
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);
 }
 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);
     }
 }
Пример #9
0
 public List <HighlightModel> GetHighlight(string userId, string url)
 {
     using (var db = new AnnotateWebPageDBEntities())
     {
         List <HighlightModel> highlights = new List <HighlightModel>();
         foreach (var highlight in db.Highlight)
         {
             if (highlight.user_id.Equals(userId) && highlight.web_page.Equals(url))
             {
                 highlights.Add(new HighlightModel()
                 {
                     id = highlight.id, user_id = highlight.user_id, web_page = highlight.web_page, start = highlight.start, end = highlight.end, color = highlight.color
                 });
             }
         }
         return(highlights);
     }
 }
 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;
     }
 }
Пример #11
0
 public IEnumerable <HighlightModel> GetHighlights()
 {
     try
     {
         using (var db = new AnnotateWebPageDBEntities())
         {
             List <HighlightModel> highlights = new List <HighlightModel>();
             foreach (var highlight in db.Highlight)
             {
                 highlights.Add(new HighlightModel()
                 {
                     id = highlight.id, user_id = highlight.user_id, web_page = highlight.web_page, start = highlight.start, end = highlight.end, color = highlight.color
                 });
             }
             return(highlights);
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
 public IEnumerable <CommentModel> GetComments()
 {
     try
     {
         using (var db = new AnnotateWebPageDBEntities())
         {
             List <CommentModel> comments = new List <CommentModel>();
             foreach (var comment in db.Comment)
             {
                 comments.Add(new CommentModel()
                 {
                     id = comment.id, text = comment.text, color = comment.color, user_id = comment.user_id, web_page = comment.web_page
                 });
             }
             return(comments);
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
 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;
     }
 }
Пример #14
0
        public IEnumerable <UserModel> GetUsers()
        {
            try
            {
                using (var db = new AnnotateWebPageDBEntities())
                {
                    List <UserModel> users = new List <UserModel>();
                    foreach (var user in db.User)
                    {
                        users.Add(new UserModel()
                        {
                            id = user.id, name = user.name
                        });
                    }

                    return(users);
                }
            }
            catch (Exception)
            {
                throw;
            }
        }