Пример #1
0
        public async Task <IActionResult> CreateItemsAsync([FromBody] Client.TodoItems.TodoItemBuildInfo buildInfo, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

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

            var name  = User.Identity.Name;
            var usser = this.usersRepository.Get(name).Id;

            var creationInfo = TodoItemBuildInfoConverter.Convert(usser.ToString(), buildInfo);

            var modelItemInfo = await this.itemsRepository.CreateAsync(creationInfo, cancellationToken).ConfigureAwait(false);

            var clientItemInfo = TodoItemInfoConverter.Convert(modelItemInfo);

            var routeParams = new Dictionary <string, object>
            {
                { "itemId", clientItemInfo.Id }
            };

            return(this.CreatedAtRoute("GetItemRoute", routeParams, clientItemInfo));
        }
Пример #2
0
        public async Task <IActionResult> SearchItemsAsync([FromQuery] Client.TodoItems.TodoItemInfoSearchQuery query, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            var modelQuery = TodoItemInfoSearchQueryConverter.Convert(query ?? new Client.TodoItems.TodoItemInfoSearchQuery());
            var userid     = this.usersRepository.Get(User.Identity.Name).Id;
            var modelItems = await this.itemsRepository.SearchAsync(modelQuery, cancellationToken, userid).ConfigureAwait(false);

            var clientItems     = modelItems.Select(item => TodoItemInfoConverter.Convert(item)).ToList();
            var clientItemsList = new Client.TodoItems.ItemsList
            {
                TodoItems = clientItems
            };

            return(this.Ok(clientItemsList));
        }