示例#1
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)));
        }
示例#2
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));
        }