public async Task AddAsync(Tag tag) { var user = new User { Id = 1 }; _dbContext.Tag.Add(tag); _dbContext.Entry(tag).Property(Constants.LastUpdated).CurrentValue = DateTime.Now; _dbContext.Entry(tag).Property(Constants.UserId).CurrentValue = user.Id; await _dbContext.SaveChangesAsync(); }
public void CreateNote(NoteDTO obj) { Note CreateNote = new Note(); CreateNote.Title = obj.Title; CreateNote.Body = obj.Body; CreateNote.CreateDate = obj.CreateDate; CreateNote.UpdateDate = obj.UpdateDate; _db.Entry(CreateNote).State = Microsoft.EntityFrameworkCore.EntityState.Added; _db.SaveChanges(); }
public void RestoreTestData() { foreach (var note in _db.Notes) { _db.Entry(note).State = EntityState.Deleted; } _db.Notes.Add(new Note { Title = "Yeah it's called a shrug..", Description = @"¯\_(ツ)_/¯", Importance = 2, CreatedAt = DateTime.Now }); _db.Notes.Add(new Note { Title = "Important Note", Description = "This one is a very important note:\nDON'T DELETE ME", Importance = 4, CreatedAt = DateTime.Now.AddDays(-2).AddHours(-1) }); _db.Notes.Add(new Note { Title = "Finished Note", Description = "An already finished note! Wooh", Importance = 3, CreatedAt = DateTime.Now.AddHours(-20), FinishedAt = DateTime.Now.AddHours(-2) }); _db.SaveChanges(); }
public ActionResult Edit([Bind(Include = "Id,Name,Description")] Category category) { if (ModelState.IsValid) { db.Entry(category).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(category)); }
public async Task <UpdateResult> UpdateNote(Note note , IEnumerable <SelectableTag> selectableTags , IEnumerable <Comment> comments) { var now = DateTime.Now; Assert(selectableTags != null); Assert(comments != null); if (note.NoteTags == null) { note.NoteTags = new List <NoteTag>(); } try { _context.Database.ExecuteSqlCommand("delete from NoteTag where Noteid = {0}", note.Id); _context.Database.ExecuteSqlCommand("delete from Comments where Noteid = {0}", note.Id); var user = new User { Id = 1 }; _context.User.Attach(user); note.User = user; if (IsNewNote(note)) { _context.Add(note); } else { _context.Update(note); } _context.Entry(note).Property(Constants.LastUpdated).CurrentValue = now; IncludeSelectedTagsInNote(note, selectableTags); foreach (NoteTag ntt in note.NoteTags) { _context.NoteTag.Add(ntt); _context.Entry(ntt).Property(Constants.LastUpdated).CurrentValue = now; _context.Entry(ntt).Property(Constants.UserId).CurrentValue = user.Id; } note.Comments.Clear(); foreach (var cmt in comments) { Comment newComment = new Comment { Payload = cmt.Payload }; note.Comments.Add(newComment); _context.CommentSet.Add(newComment); _context.Entry(newComment).Property(Constants.LastUpdated).CurrentValue = now; _context.Entry(newComment).Property(Constants.UserId).CurrentValue = user.Id; } int x = await _context.SaveChangesAsync(); return(UpdateResult.Success); } catch (DbUpdateConcurrencyException) { if (!NoteExists(note.Id)) { return(UpdateResult.NoteAlreadyDeleted); } else { return(UpdateResult.ConcurrencyConflict); } } }
public void Update(User user) { user.UpdatedAt = DateTime.Now; _context.Entry(user).State = EntityState.Modified; }
public Task UpdateAsync(Note note) { _NoteContext.Entry(note).State = EntityState.Modified; return(_NoteContext.SaveChangesAsync()); }
public void Update(Note note) { note.UpdatedAt = DateTime.Now; _context.Entry(note).State = EntityState.Modified; }