Пример #1
0
        public IActionResult GetItem([FromRoute] string itemId, CancellationToken cancelltionToken)
        {
            cancelltionToken.ThrowIfCancellationRequested();

            if (!Guid.TryParse(itemId, out var modelItemId))
            {
                var error = ServiceErrorResponses.ItemNotFound(itemId);
                return(this.NotFound(error));
            }

            Model.TodoItems.TodoItem modelItem = null;
            var userid = this.usersRepository.Get(User.Identity.Name).Id;

            try
            {
                modelItem = this.itemsRepository.GetAsync(modelItemId, cancelltionToken, userid);
            }
            catch (Model.TodoItems.TodoItemNotFoundExcepction)
            {
                var error = ServiceErrorResponses.ItemNotFound(itemId);
                return(this.NotFound(error));
            }

            var clientItem = TodoItemConverter.Convert(modelItem);

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

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

            if (!Guid.TryParse(itemId, out var ItemIdGuid))
            {
                var error = ServiceErrorResponses.ItemNotFound(itemId);
                return(this.NotFound(error));
            }

            var modelPathInfo = TodoItemPathcInfoConverter.Convert(ItemIdGuid, patchInfo);

            Model.TodoItems.TodoItem modelItem = null;
            var userid = this.usersRepository.Get(User.Identity.Name).Id;

            try
            {
                modelItem = await this.itemsRepository.PatchAsync(modelPathInfo, cancellationToken, userid).ConfigureAwait(false);
            }
            catch (Model.TodoItems.TodoItemNotFoundExcepction)
            {
                var error = ServiceErrorResponses.ItemNotFound(itemId);
                return(this.NotFound(error));
            }

            var clientItem = TodoItemConverter.Convert(modelItem);

            return(this.Ok(clientItem));
        }