Esempio n. 1
0
        public async Task <ItemsResponseModel <NoteDto> > GetNotes(int userId, int?page, int?size)
        {
            var user = await _userProvider.GetUser(userId);

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

            var notesTask = _noteProvider.GetNotes(userId, page, size);

            if (page.HasValue && size.HasValue)
            {
                var countTask = _noteProvider.CountNotes(userId);

                return(new ItemsResponseModel <NoteDto>
                {
                    Items = await notesTask,
                    PaginationInfo = new PaginationModel
                    {
                        Page = page.Value,
                        Size = size.Value,
                        TotalRecords = await countTask
                    }
                });
            }

            return(new ItemsResponseModel <NoteDto>
            {
                Items = await notesTask,
                PaginationInfo = null
            });
        }
Esempio n. 2
0
 public IActionResult GetStaffNotes([FromQuery(Name = "staff_id")] int?staffId)
 {
     // If there is no staff member id specified in the query, return all existing notes.
     if (staffId == null)
     {
         ImmutableList <KnownNote> allNotes = _noteProvider.GetNotes();
         return(Json(new NoteListResponse(allNotes)));
     }
     if (_staffProvider.Get(staffId.Value) == null)
     {
         return(BadRequest(Json(new ErrorResponse(String.Format("Staff member with ID {0} does not exist.", staffId)))));
     }
     return(Json(new NoteListResponse(_noteProvider.GetStaffNotes(staffId.Value))));
 }