Esempio n. 1
0
        public async Task DeleteNote(DiaryNoteVo noteVo)
        {
            var dac = await EnsureDocumentExist(noteVo);

            Repository.DeleteNote(dac);
            await EnsurePersisted();
        }
Esempio n. 2
0
        private async Task <DiaryNoteDac> EnsureDocumentExist(DiaryNoteVo noteVo)
        {
            var latest = await Repository.GetDiaryNoteById(noteVo.Id);

            if (latest == null)
            {
                throw new Exception($"Document with ID: {noteVo.Id} cannot be found");
            }
            return(latest);
        }
Esempio n. 3
0
        public async Task AddNote(DiaryNoteVo noteVo)
        {
            var currentUserId = SessionState.GetSession().User.Id;

            var noteDac = noteVo.ToDiaryNoteDac();

            noteDac.CreatedOn  = DateTime.UtcNow;
            noteDac.ModifiedOn = DateTime.UtcNow;
            noteDac.CreatedBy  = currentUserId;
            noteDac.ModifiedBy = currentUserId;

            await Repository.AddDiaryNote(noteDac);

            await EnsurePersisted();
        }
Esempio n. 4
0
        public static DiaryNoteDac ToDiaryNoteDac(this DiaryNoteVo noteVo)
        {
            if (noteVo == null)
            {
                return(null);
            }

            return(new DiaryNoteDac
            {
                Id = noteVo.Id,
                CreatedOn = noteVo.CreatedOn,
                Details = noteVo.Details,
                Summary = noteVo.Summary,
                NoteTitle = noteVo.Title,
                ModifiedOn = noteVo.ModifiedOn,
                IsDraft = noteVo.IsDraft
            });
        }
Esempio n. 5
0
        public async Task UpdateNote(DiaryNoteVo noteVo)
        {
            DiaryNoteDac latest = await EnsureDocumentExist(noteVo);

            if (string.IsNullOrWhiteSpace(noteVo.Title))
            {
                throw new Exception("Document title cannot be null/empty");
            }
            if (string.IsNullOrWhiteSpace(noteVo.Details))
            {
                throw new Exception("Document body cannot be null/empty");
            }
            var currentUserId = SessionState.GetSession().User.Id;

            latest.NoteTitle  = noteVo.Title;
            latest.Details    = noteVo.Details;
            latest.Summary    = noteVo.Summary;
            latest.ModifiedOn = DateTime.UtcNow;
            latest.ModifiedBy = currentUserId;

            Repository.UpdateDiaryNote(latest);
            await EnsurePersisted();
        }