Пример #1
0
        private async Task LoadData()
        {
            ProductHttpClientWrapper wrapper = new ProductHttpClientWrapper();
            var result = await wrapper.Category.GetAllCategories();

            grdCategory.ItemsSource = result;
        }
        private async Task LoadData()
        {
            ProductHttpClientWrapper wrapper = new ProductHttpClientWrapper();
            var result = await wrapper.Product.GetAllProducts();

            grdProduct.ItemsSource = result;
        }
Пример #3
0
        private async void Delete_Click(object sender, RoutedEventArgs e)
        {
            Category c = ((FrameworkElement)sender).DataContext as Category;

            if (MessageBox.Show(string.Format("Are you sure to delete the following category?\r\n{0}", c.CategoryName), this.Title, MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
            {
                ProductHttpClientWrapper wrapper = new ProductHttpClientWrapper();
                await wrapper.Category.DeleteCategory(c.CategoryId);
                await LoadData();
            }
        }
Пример #4
0
        public async Task <Product> GetProductById(int productId)
        {
            Product p = await GetById(productId);

            if (p != null)
            {
                ProductHttpClientWrapper wrapper = new ProductHttpClientWrapper();
                Category category = await wrapper.Category.GetCategoryById(p.CategoryId);

                p.Category = category;
            }
            return(p);
        }
Пример #5
0
        public async Task <IEnumerable <Product> > GetAllProducts()
        {
            IEnumerable <Product> products = await GetAll();

            if (products != null)
            {
                if (products.Count() > 0)
                {
                    ProductHttpClientWrapper wrapper    = new ProductHttpClientWrapper();
                    IEnumerable <Category>   categories = await wrapper.Category.GetAllCategories();

                    products.ToList().ForEach(x => x.Category = categories.FirstOrDefault(y => y.CategoryId == x.CategoryId));
                }
                return(products.OrderBy(x => x.ProductName));
            }

            return(null);
        }