public void Create(User user) { using (var context = new NoteShareEntities()) { user.CreatedOn = DateTime.Now; context.Users.Add(user); context.SaveChanges(); } }
public void Create(Comment comment) { using (var context = new NoteShareEntities()) { //comment.CreatedOn = DateTime.Now; context.Comments.Add(comment); context.SaveChanges(); } }
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 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(); } } }
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(); } } }