Пример #1
0
        public async Task <IActionResult> GetNoteAsync([FromRoute] string noteId, CancellationToken cancelltionToken)
        {
            cancelltionToken.ThrowIfCancellationRequested();

            if (!Guid.TryParse(noteId, out var modelNoteId))
            {
                var error = ServiceErrorResponses.NoteNotFound(noteId);
                return(this.NotFound(error));
            }

            Model.Notes.Note modelNote = null;

            try
            {
                modelNote = await this.repository.GetAsync(modelNoteId, cancelltionToken).ConfigureAwait(false);
            }
            catch (Model.Notes.NoteNotFoundExcepction)
            {
                var error = ServiceErrorResponses.NoteNotFound(noteId);
                return(this.NotFound(error));
            }

            var clientNote = NoteConverter.Convert(modelNote);

            return(this.Ok(clientNote));
        }
Пример #2
0
        public async Task <IActionResult> PatchNoteAsync([FromRoute] string noteId, [FromBody] Client.Notes.NotePatchInfo patchInfo, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            if (patchInfo == null)
            {
                var error = ServiceErrorResponses.BodyIsMissing("NotePatchInfo");
                return(this.BadRequest(error));
            }

            if (!Guid.TryParse(noteId, out var noteIdGuid))
            {
                var error = ServiceErrorResponses.NoteNotFound(noteId);
                return(this.NotFound(error));
            }

            var modelPathInfo = NotePathcInfoConverter.Convert(noteIdGuid, patchInfo);

            Model.Notes.Note modelNote = null;

            try
            {
                modelNote = await this.repository.PatchAsync(modelPathInfo, cancellationToken).ConfigureAwait(false);
            }
            catch (Model.Notes.NoteNotFoundExcepction)
            {
                var error = ServiceErrorResponses.NoteNotFound(noteId);
                return(this.NotFound(error));
            }

            var clientNote = NoteConverter.Convert(modelNote);

            return(this.Ok(clientNote));
        }