예제 #1
0
        public IQueryable <Note> GetAttachedNotes(IRdbDataEntity attachmentSite)
        {
            try
            {
                int pk  = Convert.ToInt32(((IPrimaryKey)attachmentSite).Key);
                var tid = GetTableObjectId(attachmentSite);

                return
                    ((
                         from nt in this.NoteTargets
                         where nt.TableObjectId == tid && nt.TablePkIntVal == pk
                         select nt.Note
                         ).Include(n => n.CreatedByContact));
            }
            catch (Exception)
            {
                return(Note.None.ToList().AsQueryable());
            }
        }
예제 #2
0
        SerializableTreeNode <Note> INoteService.GetNoteNodes(IRdbDataEntity entityWithAttachedNotes)
        {
            var notes = Rdb.GetAttachedNotes(entityWithAttachedNotes).Include(z => z.CreatedByContact);
            var root  = new SerializableTreeNode <Note>(null);

            foreach (var note in notes)
            {
                var currentNoteNode = new SerializableTreeNode <Note>(note);
                if (note.ParentNoteId != null)
                {
                    SerializableTreeNode <Note> parentNoteNode = null;

                    //find parent in root and add child to it
                    root.Walk((node, depth) =>
                    {
                        if (node.Data?.NoteId == note.ParentNoteId)
                        {
                            node.Add(currentNoteNode);
                            parentNoteNode = node;
                            return;
                        }
                    });

                    //parent isn't in root
                    if (parentNoteNode == null)
                    {
                        var parentNote = notes.SingleOrDefault(x => x.NoteId == note.ParentNoteId);
                        parentNoteNode = new SerializableTreeNode <Note>(parentNote);
                        parentNoteNode?.Add(currentNoteNode);
                    }
                }
                else
                {
                    root.Add(currentNoteNode);
                }
            }

            root.Children = root.Children.OrderBy(x => x.Data.CreatedAtUtc).ToList();
            return(root);
        }
예제 #3
0
        protected IQueryable <Note> GetNotes(IRdbDataEntity entityWithAttachedNotes)
        {
            var notes = Rdb.GetAttachedNotes(entityWithAttachedNotes).Include(z => z.CreatedByContact);

            return(notes);
        }
예제 #4
0
 public async Task <IActionResult> CreateNote(
     int?parentNoteId,
     string content,
     IRdbDataEntity attachmentSite) => await CreateNote(parentNoteId, content, new[] { attachmentSite });
예제 #5
0
 private int GetTableObjectId(IRdbDataEntity e)
 => GetDatabaseObjectId(AttributeStuff.GetCustomAttribute <TableAttribute>(e.GetType()));