Ejemplo n.º 1
0
        public HttpResponseMessage Get(Guid id)
        {
            var getNoteByIdQuery = new GetNoteByIdQuery(id);

            try
            {
                var note = _noteQueryService.Execute(getNoteByIdQuery);
                return(Request.CreateResponse(HttpStatusCode.OK, note));
            }
            catch (FileNotFoundException ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.NotFound, ex));
            }
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> GetNoteAsync(Guid noteId)
        {
            var userId = Guid.Parse(User.FindFirst(ClaimTypes.NameIdentifier)?.Value);

            var query  = new GetNoteByIdQuery(noteId, userId);
            var result = await _mediator.Send(query);

            if (!result.Success)
            {
                return(BadRequest(new ErrorResource(result.Message)));
            }

            var noteResource = _mapper.Map <Note, NoteResource>(result.Note);

            return(Ok(noteResource));
        }