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); } }
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); } }
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); } }
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; } }
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; } }