Beispiel #1
0
        public async Task <IList <Book> > GetAllBooksAsync()
        {
            List <Book> listBooks             = new List <Book>();
            CustomerListBookResponse response = await client().GetAllBooksAsync(new VoidRequest());

            foreach (var item in response.Books)
            {
                var book = new Book
                {
                    Id       = item.Id,
                    Name     = item.Name,
                    Category = item.Category,
                    Author   = item.Author,
                    Price    = item.Price
                };
                listBooks.Add(book);
            }
            return(listBooks);
        }
        public override Task <CustomerListBookResponse> GetAllBooks(VoidRequest request, ServerCallContext context)
        {
            logger.LogInformation("Begin grpc call from method {Method} for all books", context.Method);
            //using ( var dbcontext = new dbBooksContext(dbContextOptions))
            //{
            CustomerListBookResponse response = new CustomerListBookResponse();
            var datas = bookContext.Books;

            foreach (var item in datas)
            {
                response.Books.Add(new CustomerBookDataReponse
                {
                    Id       = item.Id,
                    Name     = item.Name,
                    Price    = item.Price,
                    Category = item.Category,
                    Author   = item.Author,
                });
            }

            return(Task.FromResult(response));

            //}
        }