public IList<User> GetAll() { using (var context = new NoteShareEntities()) { return context.Users.ToList(); } }
public User Get(int id) { using (var context = new NoteShareEntities()) { return context.Users .SingleOrDefault(user => user.Id == id); } }
public void Create(User user) { using (var context = new NoteShareEntities()) { user.CreatedOn = DateTime.Now; context.Users.Add(user); context.SaveChanges(); } }
public IList<Comment> GetComments(int id) { using (var context = new NoteShareEntities()) { return context.Comments .Include(c => c.User) .Where(comment => comment.NoteId == id) .ToList(); } }
public void Create(Comment comment) { using (var context = new NoteShareEntities()) { //comment.CreatedOn = DateTime.Now; context.Comments.Add(comment); context.SaveChanges(); } }
public Note Get(int id) { using (var context = new NoteShareEntities()) { return context.Notes .Include("User") .Include("Comments") .Include("Comments.User") .SingleOrDefault(note => note.Id == id); } }
public void Create(Note note) { using (var context = new NoteShareEntities()) { note.CreatedOn = DateTime.Now; note.User = context.Users.First(); context.Notes.Add(note); context.SaveChanges(); } }
public IList<Note> GetAll() { using (var context = new NoteShareEntities()) { return context.Notes .Include("User") .Include("Comments") .Include("Comments.User") .ToList(); } }
public void Delete(int id) { using (var context = new NoteShareEntities()) { var user = context.Users.SingleOrDefault(x => x.Id == id); if (user != null) { context.Users.Remove(user); context.SaveChanges(); } } }
public IList<Note> GetNotes(int id) { using (var context = new NoteShareEntities()) { context.Configuration.LazyLoadingEnabled = false; return context.Notes .Include(n => n.User) .Include(n => n.Comments) .Include(n => n.Comments.Select(c => c.User)) .Where(note => note.UserId == id) .ToList(); } }
public void Update(User user) { using (var context = new NoteShareEntities()) { var existingUser = context.Users.SingleOrDefault(x => x.Id == user.Id); if (existingUser != null) { existingUser.FullName = user.FullName; existingUser.IsPremiumUser = user.IsPremiumUser; context.SaveChanges(); } } }
public void Delete(int id) { using (var context = new NoteShareEntities()) { var note = context.Notes.SingleOrDefault(x => x.Id == id); if (note != null) { context.Comments.RemoveRange(note.Comments); context.Notes.Remove(note); context.SaveChanges(); } } }
public void Update(Note note) { using (var context = new NoteShareEntities()) { var existingNote = context.Notes.SingleOrDefault(x => x.Id == note.Id); if (existingNote != null) { existingNote.Title = note.Title; existingNote.Text = note.Text; context.SaveChanges(); } } }