public async Task <IActionResult> ListOrders(string[] statusFilter, int pageNumber)
        {
            var userId = GetTokenClaim("id");
            var query  = new ListOrdersQuery(Guid.Parse(userId), statusFilter, pageNumber);

            var response = await _bus.Send(query);

            return(Response(Ok(new BaseResponseDto <GetOrdersResponseDto>(true, response))));
        }
        public async Task <ActionResult <CompleteOrderDataViewModel> > ListOrders(string allOrders, string saleOrders, string closedOrders,
                                                                                  string orderBy, string filterInput, int?pageNumber, int?pageSize)
        {
            var listOrdersQuery = new ListOrdersQuery(allOrders, saleOrders, closedOrders, orderBy, filterInput, pageNumber, pageSize);
            var data            = await Mediator.Send(listOrdersQuery);

            // foreach(var s in data.Item1)
            // Console.WriteLine(s.Client.Name);
            return(new CompleteOrderDataViewModel(Mapper.Map <List <Order>, List <OrderViewModel> >(data.Item1), data.Item2));
        }
Beispiel #3
0
        public async Task <IActionResult> Get([FromQuery] ListOrdersQuery query)
        {
            if (User.IsInRole("Distributor"))
            {
                query.DistributorId = User?.FindFirstValue("BusinessUserId");
            }

            var result = await Mediator.Send(query);

            return(Ok(result));
        }
Beispiel #4
0
        public OrderTests()
        {
            _listOrdersQuery          = new ListOrdersQuery(DbContext);
            _listOrderStatusesQuery   = new ListOrderStatusesQuery(DbContext);
            _listShippingMethodsQuery = new ListShippingMethodsQuery(DbContext);
            _listPhrasesByNameQuery   = new ListPhrasesByNameQuery(DbContext, WorkContext);
            var classifierBus = new ClassifierBus <ListOrderStatusesCommand, OrderStatus>(_listOrderStatusesQuery, _listPhrasesByNameQuery);

            _listOrderStatusesQueryHandler   = new ListOrderStatusesQueryHandler(classifierBus);
            _listShippingMethodsQueryHandler = new ListShippingMethodsQueryHandler(_listShippingMethodsQuery, _listPhrasesByNameQuery);
            _listOrdersQueryHandler          = new ListOrdersQueryHandler(_listOrderStatusesQueryHandler, _listShippingMethodsQueryHandler, _listOrdersQuery);
        }
        public async void Returns_List_With_Orders_Successfully()
        {
            //Arrange
            var queryOrdersList = new ListOrdersQuery("allOrders", "true", "false", "name", "", 1, 5);

            Mediator.Setup(x => x.Send(It.IsAny <ListOrdersQuery>(), new CancellationToken()))
            .ReturnsAsync((new List <Order>(), It.IsAny <int>()));

            //Act
            var handler = new ListOrdersQueryHandler(Context);
            var result  = await handler.Handle(queryOrdersList, new CancellationToken());

            //Assert
            result.Should()
            .BeOfType <(List <Order>, int)>();

            DbContextFactory.Destroy(Context);
        }
Beispiel #6
0
        public async Task ShouldListAllOrders()
        {
            // Arrange
            var accountId = await RunAsDefaultUserAsync();

            var createCustomerCommand = new CreateCustomerCommand
            {
                AccountId     = accountId,
                ShopName      = "Test Shop Name",
                ShopAddress   = "Test Shop address",
                LocationOnMap = "Test LocationOnMap"
            };

            await SendAsync(createCustomerCommand);

            // Create product brand
            var brandCommand = new CreateBrandCommand {
                Name = "Test Brand"
            };
            var brandId = await SendAsync(brandCommand);

            // Create product category
            var productCategoryCommand = new CreateProductCategoryCommand {
                Name = "Test Product Category"
            };
            var productCategoryId = await SendAsync(productCategoryCommand);

            // Create product
            var createProductCommand = new CreateProductCommand
            {
                AvailableToSell = true,
                // created brand id
                BrandId = brandId,
                // created product category id
                ProductCategoryId = productCategoryId,
                Name     = "Test Product",
                PhotoUrl = "Test Product",
                Barcode  = "Test Product"
            };

            var productId = await SendAsync(createProductCommand);

            // Add unit to product
            var addUnitToCommand = new AddUnitCommand
            {
                ProductId    = productId,
                SellingPrice = 92,
                ContentCount = 2,
                Price        = 33,
                Count        = 6,
                IsAvailable  = true,
                Name         = "Test Unit",
                Weight       = 44
            };

            var unitId = await SendAsync(addUnitToCommand);

            // AddItem To Shopping Van
            var addItemToVanCommand = new AddItemToVanCommand
            {
                ProductId = productId,
                UnitId    = unitId
            };

            await SendAsync(addItemToVanCommand);
            await SendAsync(addItemToVanCommand);

            // Place Order Command
            var placeOrderCommand = new PlaceOrderCommand();

            await SendAsync(placeOrderCommand);

            // Act

            // Get Order By Id Query
            var listOrdersQuery = new ListOrdersQuery {
                OrderStatuses = new List <OrderStatus> {
                    OrderStatus.Placed
                }
            };
            var listOrders = await SendAsync(listOrdersQuery);

            // Assert
            listOrders.Data.Should().NotBeNull();
            listOrders.Data.Count.Should().Be(1);
        }