public async Task <IActionResult> Index()
        {
            var buyers = await _buyerManager.GetAll();

            var products = await _productManager.GetAll();

            var orders = await _orderManager.GetAll();

            if (User.IsInRole(RolesNames.Admin))
            {
                var orderViewModels = orders.Select(order => MapOrder(order, buyers, products));
                return(View(orderViewModels));
            }
            else
            {
                var buyerId         = (await _userManager.GetUserAsync(User)).BuyerId;
                var orderViewModels = orders.Where(order => order.BuyerId == buyerId).Select(order => MapOrder(order, buyers, products));
                return(View(orderViewModels));
            }
        }
Example #2
0
        private static void CustomMappingTest()
        {
            //Custom Mapping
            Console.WriteLine("-----");
            Console.WriteLine("Custom Mapping");
            BuyerManager buyerManager = new BuyerManager(new EfBuyerDal());

            foreach (var buyer in buyerManager.GetAll().Data)
            {
                Console.WriteLine("Customer id: {0}, first name: {1}, last name: {2}", buyer.BuyerId, buyer.Name, buyer.Surname);
            }
        }
        public async Task PrintAll()
        {
            var products = await _productManager.GetAll();

            var buyers = await _buyerManager.GetAll();

            var items = (await _orderManager.GetAll()).Select(item => new OrderViewModel
            {
                ProductName  = products.First(product => product.Id == item.ProductId).Name,
                BuyerAddress = buyers.First(buyer => buyer.Id == item.BuyerId).Address,
                Count        = item.Amount,
                OrderStatus  = item.OrderStatus,
                Id           = item.Id
            });

            items.WriteCollectionAsTable();
        }