Beispiel #1
0
        public static async Task <string> DeleteLinked(NotesDbContext db, NoteHeader nh)
        {
            // Check for linked notefile(s)

            List <LinkedFile> links = await db.LinkedFile.Where(p => p.HomeFileId == nh.NoteFileId).ToListAsync();

            if (links == null || links.Count < 1)
            {
            }
            else
            {
                foreach (var link in links)
                {
                    if (link.SendTo)
                    {
                        LinkQueue q = new LinkQueue
                        {
                            Activity     = LinkAction.Delete,
                            LinkGuid     = nh.LinkGuid,
                            LinkedFileId = nh.NoteFileId,
                            BaseUri      = link.RemoteBaseUri,
                            Secret       = link.Secret
                        };

                        db.LinkQueue.Add(q);
                        await db.SaveChangesAsync();
                    }
                }
            }

            return("Ok");
        }
Beispiel #2
0
        public static async Task <NoteHeader> EditNote(NotesDbContext db, UserManager <IdentityUser> userManager, NoteHeader nh, NoteContent nc, string tags)
        {
            NoteHeader eHeader = await GetBaseNoteHeader(db, nh.Id);

            eHeader.LastEdited       = nh.LastEdited;
            eHeader.ThreadLastEdited = nh.ThreadLastEdited;
            eHeader.NoteSubject      = nh.NoteSubject;
            db.Entry(eHeader).State  = EntityState.Modified;

            NoteContent eContent = await GetNoteContent(db, nh.NoteFileId, nh.ArchiveId, nh.NoteOrdinal, nh.ResponseOrdinal);

            eContent.NoteBody        = nc.NoteBody;
            eContent.DirectorMessage = nc.DirectorMessage;
            db.Entry(eContent).State = EntityState.Modified;

            List <Tags> oTags = await GetNoteTags(db, nh.NoteFileId, nh.ArchiveId, nh.NoteOrdinal, nh.ResponseOrdinal, 0);

            db.Tags.RemoveRange(oTags);

            db.UpdateRange(oTags);
            db.Update(eHeader);
            db.Update(eContent);

            await db.SaveChangesAsync();

            // deal with tags

            if (tags != null && tags.Length > 1)
            {
                var theTags = Tags.StringToList(tags, eHeader.Id, eHeader.NoteFileId, eHeader.ArchiveId);

                if (theTags.Count > 0)
                {
                    await db.Tags.AddRangeAsync(theTags);

                    await db.SaveChangesAsync();
                }
            }

            // Check for linked notefile(s)

            List <LinkedFile> links = await db.LinkedFile.Where(p => p.HomeFileId == eHeader.NoteFileId && p.SendTo).ToListAsync();

            if (links == null || links.Count < 1)
            {
            }
            else
            {
                foreach (var link in links)
                {
                    if (link.SendTo)
                    {
                        LinkQueue q = new LinkQueue
                        {
                            Activity     = LinkAction.Edit,
                            LinkGuid     = eHeader.LinkGuid,
                            LinkedFileId = eHeader.NoteFileId,
                            BaseUri      = link.RemoteBaseUri,
                            Secret       = link.Secret
                        };

                        db.LinkQueue.Add(q);
                        await db.SaveChangesAsync();
                    }
                }
            }

            return(eHeader);
        }
Beispiel #3
0
        public static async Task <NoteHeader> CreateNote(NotesDbContext db, UserManager <IdentityUser> userManager, NoteHeader nh, string body, string tags, string dMessage, bool send, bool linked)
        {
            if (nh.ResponseOrdinal == 0)  // base note
            {
                nh.NoteOrdinal = await NextBaseNoteOrdinal(db, nh.NoteFileId, nh.ArchiveId);
            }

            if (!linked)
            {
                nh.LinkGuid = Guid.NewGuid().ToString();
            }

            if (!send) // indicates an import operation / adjust time to UCT / assume original was CST = UCT-06, so add 6 hours
            {
                int offset = 6;
                if (nh.LastEdited.IsDaylightSavingTime())
                {
                    offset--;
                }

                Random rand = new Random();
                int    ms   = rand.Next(999);

                nh.LastEdited       = nh.LastEdited.AddHours(offset).AddMilliseconds(ms);
                nh.CreateDate       = nh.LastEdited;
                nh.ThreadLastEdited = nh.CreateDate;
            }

            NoteFile nf = await db.NoteFile
                          .Where(p => p.Id == nh.NoteFileId)
                          .FirstOrDefaultAsync();

            nf.LastEdited      = nh.CreateDate;
            db.Entry(nf).State = EntityState.Modified;
            db.NoteHeader.Add(nh);
            await db.SaveChangesAsync();

            NoteHeader newHeader = nh;

            if (newHeader.ResponseOrdinal == 0)
            {
                newHeader.BaseNoteId      = newHeader.Id;
                db.Entry(newHeader).State = EntityState.Modified;
                await db.SaveChangesAsync();
            }
            else
            {
                NoteHeader baseNote = await db.NoteHeader
                                      .Where(p => p.NoteFileId == newHeader.NoteFileId && p.ArchiveId == newHeader.ArchiveId && p.NoteOrdinal == newHeader.NoteOrdinal && p.ResponseOrdinal == 0)
                                      .FirstOrDefaultAsync();

                newHeader.BaseNoteId      = baseNote.Id;
                db.Entry(newHeader).State = EntityState.Modified;
                await db.SaveChangesAsync();
            }

            NoteContent newContent = new NoteContent()
            {
                NoteHeaderId    = newHeader.Id,
                NoteBody        = body,
                DirectorMessage = dMessage
            };

            db.NoteContent.Add(newContent);
            await db.SaveChangesAsync();

            // deal with tags

            if (tags != null && tags.Length > 1)
            {
                var theTags = Tags.StringToList(tags, newHeader.Id, newHeader.NoteFileId, newHeader.ArchiveId);

                if (theTags.Count > 0)
                {
                    await db.Tags.AddRangeAsync(theTags);

                    await db.SaveChangesAsync();
                }
            }

            // Check for linked notefile(s)

            List <LinkedFile> links = await db.LinkedFile.Where(p => p.HomeFileId == newHeader.NoteFileId && p.SendTo).ToListAsync();

            if (linked || links == null || links.Count < 1)
            {
            }
            else
            {
                foreach (var link in links)
                {
                    if (link.SendTo)
                    {
                        LinkQueue q = new LinkQueue
                        {
                            Activity     = newHeader.ResponseOrdinal == 0 ? LinkAction.CreateBase : LinkAction.CreateResponse,
                            LinkGuid     = newHeader.LinkGuid,
                            LinkedFileId = newHeader.NoteFileId,
                            BaseUri      = link.RemoteBaseUri,
                            Secret       = link.Secret
                        };

                        db.LinkQueue.Add(q);
                        await db.SaveChangesAsync();
                    }
                }
            }

            return(newHeader);
        }