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));
        }
Esempio n. 2
0
        public async Task <IActionResult> PatchNoteAsync(
            [FromRoute] string noteId,
            [FromBody] Client.Notes.NotePatchInfo patchInfo,
            CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            if (!this.TryGetSessionState(this.HttpContext.Request.Cookies, out var state))
            {
                return(this.Unauthorized());
            }
            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));
            }
            if (!this.IsNoteBelongsToUserAsync(state, noteIdGuid, cancellationToken).Result)
            {
                return(this.Forbid());
            }

            Models.Notes.Note modelNote = null;
            var modelPathInfo           = NotePathcInfoConverter.Convert(noteIdGuid, patchInfo);

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

            var clientNote = NoteConverter.Convert(modelNote);

            return(this.Ok(clientNote));
        }