コード例 #1
0
 public async Task <Note> GetByAccessLink(string accessLink)
 {
     using (var ctx = new MyNoteContext())
     {
         return(await ctx.Notes.Where(n => n.ShareLink == accessLink).FirstAsync());
     }
 }
コード例 #2
0
ファイル: AuditRepository.cs プロジェクト: rabakozi/MyNote
        private async Task AuditNoteActions(Note note, AuditAction action)
        {
            using (var ctx = new MyNoteContext())
            {
                var auditNote = new AuditEnrty()
                {
                    Action = Enum.GetName(typeof(AuditAction), action),
                    NoteId = note.Id,
                    Actor  = note.Owner,
                    Time   = DateTime.Now
                };

                switch (action)
                {
                case AuditAction.CreateNote:
                case AuditAction.UpdateNote:
                    auditNote.Details = $"Title:{note.Title}, Content:{note.Content}";
                    break;

                case AuditAction.ShareNote:
                    auditNote.Details = $"ShareLink:{note.ShareLink}";
                    break;
                }

                ctx.AuditEntries.Add(auditNote);
                await ctx.SaveChangesAsync();
            }
        }
コード例 #3
0
 public async Task <Note> Get(int id)
 {
     using (var ctx = new MyNoteContext())
     {
         return(await ctx.Notes.FindAsync(id));
     }
 }
コード例 #4
0
        public async Task <IEnumerable <NoteDigest> > GetAllNoteDigestByUser(string userName)
        {
            using (var ctx = new MyNoteContext())
            {
                var notes = await ctx.Notes.Where(n => n.Owner == userName).OrderByDescending(n => n.Created).ToListAsync();

                return(notes);
            }
        }
コード例 #5
0
 public async Task Delete(int id)
 {
     using (var ctx = new MyNoteContext())
     {
         var note = ctx.Notes.Find(id);
         ctx.Notes.Remove(note);
         //var note = ctx.Notes.First(n => n.Id == id);
         //ctx.Remove(note);
         await ctx.SaveChangesAsync();
     }
 }
コード例 #6
0
        public async Task Insert(Note note)
        {
            using (var ctx = new MyNoteContext())
            {
                note.Created = note.Modified = DateTime.Now;
                //TODO: return Id
                //ctx.Notes.Add(note);
                var zzz = ((DbSet <Note>)ctx.Set <Note>())
                          .Add(note);

                await ctx.SaveChangesAsync();
            }
        }
コード例 #7
0
ファイル: AuditRepository.cs プロジェクト: rabakozi/MyNote
        public async Task RegisterUser(UserModel user, IdentityResult identityResult)
        {
            using (var ctx = new MyNoteContext())
            {
                var auditNote = new AuditEnrty()
                {
                    Action  = Enum.GetName(typeof(AuditAction), AuditAction.RegisterUser),
                    Actor   = user.UserName,
                    Time    = DateTime.Now,
                    Details = identityResult.Succeeded ? "Success." :
                              string.Join("; ", identityResult.Errors)
                };

                ctx.AuditEntries.Add(auditNote);
                await ctx.SaveChangesAsync();
            }
        }
コード例 #8
0
        public async Task Update(Note note)
        {
            using (var ctx = new MyNoteContext())
            {
                var dbNote = ctx.Notes.First(u => u.Id == note.Id);
                note.Created  = dbNote.Created;
                note.Modified = DateTime.Now;
                ctx.Entry(dbNote).CurrentValues.SetValues(note);
                await ctx.SaveChangesAsync();

                //var dbNote = ctx.Notes.Find(note.Id);
                //dbNote.Lead = note.Lead;
                //dbNote.Modified = DateTime.Now;
                //dbNote.ShareLink = note.ShareLink;
                //dbNote.Title = note.Title;
                //return ctx.SaveChangesAsync();
            }
        }
コード例 #9
0
 private NoteBrowsedRecordDAL()
 {
     this.dbContext = new MyNoteContext();
 }
コード例 #10
0
 private NoteCommentDAL()
 {
     this.dbContext = new MyNoteContext();
 }
コード例 #11
0
 private FtpConfigDAL()
 {
     this.dbContext = new MyNoteContext();
 }
コード例 #12
0
 private SysInfoDAL()
 {
     this.dbContext = new MyNoteContext();
 }
コード例 #13
0
 private NoteApprovedRecordDAL()
 {
     this.dbContext = new MyNoteContext();
 }
コード例 #14
0
 private UserDAL()
 {
     this.dbContext = new MyNoteContext();
 }
コード例 #15
0
 private VerificationDAL()
 {
     this.dbContext = new MyNoteContext();
 }
コード例 #16
0
ファイル: AuthRepository.cs プロジェクト: rabakozi/MyNote
 public AuthRepository()
 {
     ctx         = new MyNoteContext();
     userManager = new UserManager <IdentityUser>(new UserStore <IdentityUser>(ctx));
 }