示例#1
0
        public PostedNote.PostedNotePayload SetNoteActive([FromBody] SetNoteActiveRequestObject requestObject)
        {
            ProMaUser user = DataController.LoggedInUser;

            if (user == null)
            {
                throw new NotLoggedInException();
            }

            PostedNote relevantNote = PostedNoteHandler.GetNote(requestObject.noteId);

            if (relevantNote == null)
            {
                throw new Exception("No note with id " + requestObject.noteId.ToString());
            }

            if (relevantNote.NoteTypeId.HasValue && !NoteTypeHandler.UserCanPostNotesOfType(user.UserId, relevantNote.NoteTypeId.Value))
            {
                throw new Exception("Cannot modify or create notes of this type");
            }

            relevantNote.Active = requestObject.active;

            relevantNote.EditedTime   = ProMaUser.NowTime();
            relevantNote.EditedUserId = user.UserId;

            PostedNoteHandler.UpdatePostedNote(relevantNote);

            return(PostedNoteHandler.GetPayloadNote(relevantNote, user.UserId));
        }
示例#2
0
        public PostedNote.PostedNotePayload ToggleHighlightNote([FromForm] int noteId)
        {
            ProMaUser user = DataController.LoggedInUser;

            if (user == null)
            {
                throw new NotLoggedInException();
            }

            PostedNote relevantNote = PostedNoteHandler.GetNote(noteId);

            if (relevantNote == null)
            {
                throw new Exception("No note with id " + noteId.ToString());
            }

            if (relevantNote.NoteTypeId.HasValue && !NoteTypeHandler.UserCanPostNotesOfType(user.UserId, relevantNote.NoteTypeId.Value))
            {
                throw new Exception("Cannot modify or create notes of this type");
            }

            relevantNote.Highlighted = !relevantNote.Highlighted;

            relevantNote.EditedTime   = ProMaUser.NowTime();
            relevantNote.EditedUserId = user.UserId;

            PostedNoteHandler.UpdatePostedNote(relevantNote);

            return(PostedNoteHandler.GetPayloadNote(relevantNote, user.UserId));
        }
示例#3
0
        public ProMaUser RegisterProMaUser([FromBody] RegisterProMaUserRequestObject requestObject)
        {
            using (ProMaDB scope = new ProMaDB())
            {
                if (string.IsNullOrWhiteSpace(requestObject.md5Password))
                {
                    throw new Exception("Invalid password");
                }

                if (!ProMaUser.VerifyName(requestObject.userName))
                {
                    throw new Exception("Invalid user name");
                }

                // make sure no user with the same name
                ProMaUser existingUser = ProMaUserHandler.GetUserByUserName(requestObject.userName);

                if (existingUser != null)
                {
                    throw new Exception("User already exists by that name");
                }

                ProMaUser newUser = new ProMaUser();

                newUser.HashedPassword = ProMaUser.ComputeSHA256(requestObject.md5Password);;
                newUser.JoinTime       = ProMaUser.NowTime();
                newUser.UserName       = requestObject.userName;

                ProMaUserHandler.AddProMaUser(newUser);

                PostedNote seedNote = new PostedNote();
                seedNote.UserId        = newUser.UserId;
                seedNote.NoteText      = @"You can create new notes by using the text area in the right.\r\n\r\nNotes can have note types (see the ""as type"" selector). You can create new note types using the utilties area to the bottom right, and selecting the ""Note Types"" tab.\r\n\r\nYou can sort by note types using the filters at the bottom of the screen, among other filter options.\r\n\r\nEach note has buttons to the top right of them, like the pencil icon for editing a note or the target icon for marking it as complete. Use these to alter the notes however you would like.\r\n\r\nTry out the other tabs for useful utilities, like keeping track of daily chores, or the Egg Timer tab to handle productivity cycles.\r\n\r\nHave fun using ProMa!";
                seedNote.PostedTime    = ProMaUser.NowTime();
                seedNote.Active        = true;
                seedNote.Completed     = false;
                seedNote.CompletedTime = null;
                seedNote.Highlighted   = false;
                seedNote.NoteTypeId    = null;

                PostedNoteHandler.AddPostedNote(seedNote);

                return(newUser);
            }
        }
示例#4
0
        public PostedNote.PostedNotePayload EditNote([FromBody] EditNoteRequestObject requestObject)
        {
            ProMaUser user = DataController.LoggedInUser;

            if (user == null)
            {
                throw new NotLoggedInException();
            }

            PostedNote relevantNote = PostedNoteHandler.GetNote(requestObject.noteId);

            if (relevantNote == null)
            {
                throw new Exception("No note with id " + requestObject.noteId.ToString());
            }

            if (relevantNote.NoteTypeId.HasValue && !NoteTypeHandler.UserCanPostNotesOfType(user.UserId, relevantNote.NoteTypeId.Value))
            {
                throw new Exception("Cannot modify or create notes of this type");
            }

            relevantNote.NoteText = PostedNoteHandler.CleanNoteText(requestObject.noteText);

            if (requestObject.noteTypeId != -1)
            {
                relevantNote.NoteTypeId = requestObject.noteTypeId;
            }
            else
            {
                relevantNote.NoteTypeId = null;
            }

            relevantNote.EditedTime   = ProMaUser.NowTime();
            relevantNote.EditedUserId = user.UserId;
            relevantNote.NoteTitle    = requestObject.noteTitle;

            PostedNoteHandler.UpdatePostedNote(relevantNote);

            return(PostedNoteHandler.GetPayloadNote(relevantNote, (int?)(user.UserId)));
        }
示例#5
0
        public PostedNote.PostedNotePayload PostNote([FromBody] PostNoteRequestObject requestObject)
        {
            ProMaUser user = DataController.LoggedInUser;

            if (user == null)
            {
                throw new NotLoggedInException();
            }

            if (requestObject.noteTypeId != -1 && !NoteTypeHandler.UserCanPostNotesOfType(user.UserId, requestObject.noteTypeId))
            {
                throw new Exception();
            }

            PostedNote newNote = new PostedNote();

            newNote.NoteText   = PostedNoteHandler.CleanNoteText(requestObject.noteText);
            newNote.PostedTime = ProMaUser.NowTime();
            newNote.UserId     = user.UserId;
            newNote.Active     = true;

            newNote.Completed     = false;
            newNote.CompletedTime = null;

            newNote.Highlighted = false;

            if (requestObject.noteTypeId != -1)
            {
                newNote.NoteTypeId = requestObject.noteTypeId;
            }
            else
            {
                newNote.NoteTypeId = null;
            }

            PostedNoteHandler.AddPostedNote(newNote);

            return(PostedNoteHandler.GetPayloadNote(newNote, user.UserId));
        }
示例#6
0
        public List <PostedNote.PostedNotePayload> GetAllNotes([FromForm] string sortOption)
        {
            ProMaUser user = DataController.LoggedInUser;

            if (user == null)
            {
                throw new NotLoggedInException();
            }

            // includeUnusuals looks like "[inactive][complete]", which we need to parse out to the below options
            bool includeInactive = sortOption.Contains("[showinactive]");
            bool onlyInactive    = sortOption.Contains("[onlyinactive]");
            bool includeComplete = sortOption.Contains("[showcomplete]");
            bool includeMany     = sortOption.Contains("[showmany]");
            int  onlyShow        = -1;

            if (sortOption.Contains("[notetype"))
            {
                onlyShow = int.Parse(sortOption.Substring(sortOption.IndexOf("[notetype") + "[notetype".Length, sortOption.IndexOf("endnotetype]") - sortOption.IndexOf("[notetype") - "[notetype".Length));
            }

            List <PostedNote> originalNotes = PostedNoteHandler.GetNotes(shownToUser: user.UserId, includeInactive: includeInactive, onlyInactive: onlyInactive, includeComplete: includeComplete, onlyThisNoteId: onlyShow, includeHibernatedNotes: false);

            var  orderedQuery  = originalNotes.OrderByDescending(x => x.PostedTime);
            bool firstSortDone = false;

            // sortOption looks like complete, which means complete descending, or posted, which means posted descending
            // this has limited options, based on what is implemented so far. it was a quick resolution for a minor problem, needs maintaining
            if (!string.IsNullOrEmpty(sortOption))
            {
                if (sortOption.Contains("[sortpinhighlighted]"))
                {
                    if (!firstSortDone)
                    {
                        orderedQuery  = orderedQuery.OrderByDescending(x => x.Highlighted);
                        firstSortDone = true;
                    }
                    else
                    {
                        orderedQuery = orderedQuery.ThenByDescending(x => x.Highlighted);
                    }
                }
                if (sortOption.Contains("[sortcomplete]"))
                {
                    if (!firstSortDone)
                    {
                        orderedQuery  = orderedQuery.OrderByDescending(x => x.CompletedTime);
                        firstSortDone = true;
                    }
                    else
                    {
                        orderedQuery = orderedQuery.ThenByDescending(x => x.CompletedTime);
                    }
                }
            }

            orderedQuery = orderedQuery.ThenByDescending(x => x.PostedTime);

            List <PostedNote> postedNoteFinishedList = null;

            if (!includeMany)
            {
                postedNoteFinishedList = orderedQuery.Take(100).ToList();
            }
            else
            {
                postedNoteFinishedList = orderedQuery.ToList();
            }

            return(PostedNoteHandler.GetPayloadNotes(postedNoteFinishedList, user.UserId));
        }