예제 #1
0
        public IActionResult GetNote(int noteId)
        {
            KnownNote note = _noteProvider.GetNote(noteId);

            if (note != null)
            {
                return(Json(new NoteResponse(note)));
            }
            return(BadRequest(Json(new ErrorResponse(String.Format("Note with note ID {0} does not exist", noteId)))));
        }
예제 #2
0
        public IActionResult Create([FromBody] KnownNote newNote)
        {
            if (newNote.Contents == null)
            {
                return(BadRequest(Json(new ErrorResponse("Contents can't be empty."))));
            }
            int newNoteId = _noteProvider.Create(newNote);

            if (newNoteId != 0)
            {
                return(Json(new NoteIdResponse(newNoteId)));
            }
            return(BadRequest(Json(new ErrorResponse(String.Format("Staff member with ID {0} does not exist.", newNote.StaffId)))));
        }
예제 #3
0
 /// <summary>
 /// Updates an existing note
 /// </summary>
 /// <param name="noteId">Id of the existing note</param>
 /// <param name="newNote">The new note</param>
 /// <returns>Success status</returns>
 public bool Update(int noteId, KnownNote newNote)
 {
     using (var dbContext = new AllocationContext(_dbContextOptions))
     {
         Model.Note note = dbContext.Notes.Find(noteId);
         if (note == null)
         {
             return(false);
         }
         note.Contents             = newNote.Contents;
         note.LastModificationTime = DateTimeOffset.UtcNow.ToUnixTimeSeconds();
         dbContext.SaveChanges();
         return(true);
     }
 }
예제 #4
0
 public IActionResult UpdateExistingNote(int noteId, [FromBody] KnownNote newNote)
 {
     if (newNote == null)
     {
         return(BadRequest(Json(new ErrorResponse("Invalid Request"))));
     }
     if (newNote.Contents == null)
     {
         return(BadRequest(Json(new ErrorResponse("Contents can't be empty."))));
     }
     if (_noteProvider.Update(noteId, newNote))
     {
         return(Json(new NoteResponse(_noteProvider.GetNote(noteId))));
     }
     return(BadRequest(Json(new ErrorResponse(String.Format("Note with ID {0} does not exist.", noteId)))));
 }
예제 #5
0
        /// <summary>
        /// Creates a new note
        /// </summary>
        /// <param name="newNote">The new note supplied</param>
        /// <returns>The database identifier key of the newly created note</returns>
        public int Create(KnownNote newNote)
        {
            var now       = DateTimeOffset.UtcNow.ToUnixTimeSeconds();
            var modelNote = new Model.Note()
            {
                StaffMemberId        = newNote.StaffId,
                Contents             = newNote.Contents,
                CreationTime         = now,
                LastModificationTime = now
            };

            using (var dbContext = new AllocationContext(_dbContextOptions))
            {
                if (dbContext.StaffMembers.Find(modelNote.StaffMemberId) != null)
                {
                    dbContext.Notes.Add(modelNote);
                    dbContext.SaveChanges();
                    return(modelNote.NoteId);
                }
                return(0);
            }
        }
예제 #6
0
 /// <summary>
 /// Creates a new note response message
 /// </summary>
 /// <param name="note">The given note value</param>
 public NoteResponse(KnownNote note) : base(ResponseStatus.Success)
 {
     Note = note;
 }