Ejemplo n.º 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));
        }
Ejemplo n.º 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));
        }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 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)));
        }
Ejemplo n.º 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));
        }