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 async Task <Category> DeleteCategory(int id) { var category = await noteDb.Categories.FindAsync(id); if (category == null) { return(null); } noteDb.Categories.Remove(category); await noteDb.SaveChangesAsync(); return(category); }
public async Task <IActionResult> OnPostAsync() { Note.CreatedAt = DateTime.Now; Note.IsPinned = false; Note.UserId = _identityDbContext.Users.Where(x => x.UserName.Equals(User.Identity.Name)).Select(x => x.Id).SingleOrDefault(); if (Note.Title == null || Note.Title.Equals(string.Empty)) { Note.Title = "(Untitled note)"; } if (ModelState.IsValid == false) { return(Page()); } _noteDbContext.Notes.Add(Note); await _noteDbContext.SaveChangesAsync(); return(RedirectToPage("/Dashboard")); }
public async Task InsertEmail(tbl_Emails model) { try { model.ID = Guid.NewGuid(); db.tbl_Emails.Add(model); await db.SaveChangesAsync(); } catch (Exception ex) { return; } }
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 Task AddAsync(Note note) { _NoteContext.Notes.Add(note); return(_NoteContext.SaveChangesAsync()); }