示例#1
0
        public async Task <IActionResult> PlaceOrder([FromForm] OrderViewModel vm)
        {
            if (ModelState.IsValid)
            {
                await new UpdateOrder(_context).Do(vm);
                var ShoppingCart = new GetShoppingCart(_context).Do(vm.CustomerId);
                var CartItems    = new GetCartItems(_context).Do(ShoppingCart.CartId);
                var Products     = new GetAllProducts(_context).Do(ShoppingCart.CartId, 0)
                                   .Where(prod => CartItems.Select(cartItem => cartItem.ProductRefId)
                                          .Contains(prod.ProductId));

                foreach (var cartitem in CartItems.ToList())
                {
                    await new CreateProductInOrder(_context).Do(new ProductInOrdersViewModel
                    {
                        OrderRefId   = vm.OrderId,
                        ProductRefId = cartitem.ProductRefId,
                        UsedQuantity = cartitem.Quantity,
                    });
                    await new UpdateProduct(_context, _fileManager).UpdateStockAfterOrder(cartitem.ProductRefId, cartitem.Quantity);
                }
                ShoppingCart.Status = "Closed";
                await new UpdateShoppingCart(_context).Do(ShoppingCart);
                return(Ok());
            }
            return(BadRequest());
        }
 public void OnGet(int orderId)
 {
     OrderInfo       = new GetOrderInfo(_context).Do(orderId);
     ProductInOrders = new GetAllProductInOrder(_context).Do(orderId);
     Products        = new GetAllProducts(_context).Do()
                       .Where(prod => ProductInOrders.Select(product => product.ProductRefId).Contains(prod.ProductId));
 }
        public async Task <IActionResult> OnGet()
        {
            var currUser = _userManager.GetUserId(User);

            ShoppingCart = new GetShoppingCart(_context).Do(currUser);
            CartItems    = new GetCartItems(_context).Do(ShoppingCart.CartId);
            Products     = new GetAllProducts(_context).Do()
                           .Where(prod => CartItems.Select(cartItem => cartItem.ProductRefId)
                                  .Contains(prod.ProductId));
            Order = new GetOrder(_context).Do(currUser, "Pending");
            foreach (var cartitem in CartItems.ToList())
            {
                await new CreateProductInOrder(_context).Do(new ProductInOrdersViewModel
                {
                    OrderRefId   = Order.OrderId,
                    ProductRefId = cartitem.ProductRefId,
                    UsedQuantity = cartitem.Quantity,
                });
                await new UpdateProduct(_context, _fileManager).UpdateStockAfterOrder(cartitem.ProductRefId, cartitem.Quantity);
            }
            Order.Status       = "Ordered";
            Order.TotalOrdered = ShoppingCart.TotalInCart;
            await new UpdateOrder(_context).Do(Order);
            ShoppingCart.Status = "Closed";
            await new UpdateShoppingCart(_context).Do(ShoppingCart);
            return(RedirectToPage("/Account/Manage/Orders", new { Area = "Identity" }));
        }
        public void GetAllProducts_Action_Fails()
        {
            // Arrange
            GenericServiceResponse <IEnumerable <ProductDto> > fakeResponse = null;

            mockClientServicesProvider.Setup(x => x.Logger).Returns(mockLogger.Object).Verifiable();
            mockClientServicesProvider.Setup(x => x.ProductService.GetAllProducts()).Returns(fakeResponse).Verifiable();

            var viewModel = new GenericListViewModel <ProductDto>();

            var action = new GetAllProducts <GenericListViewModel <ProductDto> >(mockClientServicesProvider.Object)
            {
                OnComplete = model => viewModel = model
            };

            // Act
            var result = action.Invoke();

            // Assert
            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(GenericListViewModel <ProductDto>));
            Assert.IsNotNull(result.Notifications);
            Assert.IsInstanceOfType(result.Notifications, typeof(NotificationCollection));
            Assert.IsTrue(result.Notifications.Count() == 1);
            Assert.IsTrue(result.HasErrors);
            Assert.IsNotNull(result.Items);
            Assert.IsTrue(result.Items.Count() == 0);
            Assert.IsInstanceOfType(result.Items, typeof(IEnumerable <ProductDto>));
            Assert.IsTrue(result.Items.ToList().Count() == 0);
        }
示例#5
0
        public async void AllProducts()
        {
            GetAllProducts products = new GetAllProducts();
            await products.GetAllProductsList();

            AddImages(GetAllProducts.productList);
        }
示例#6
0
        public async Task OnGet()
        {
            var currUser = _userManager.GetUserId(User);

            ShoppingCart = await LoadCart(currUser);

            CartItems = new GetCartItems(_context).Do(ShoppingCart.CartId);
            Products  = new GetAllProducts(_context).Do()
                        .Where(prod => CartItems.Select(cartItem => cartItem.ProductRefId)
                               .Contains(prod.ProductId));
            Categ = new GetAllCategories(_context).Do();
            Order = new GetOrder(_context).Do(currUser, "Pending");
            if (Order == null)
            {
                await new CreateOrder(_context).Do(new OrderViewModel
                {
                    Status       = "Pending",
                    CustomerId   = currUser,
                    TotalOrdered = ShoppingCart.TotalInCart,
                });
                Order = new GetOrder(_context).Do(currUser, "Pending");
            }
            OrderInfos = new GetOrderInfo(_context).Do(Order.OrderId);
            if (OrderInfos == null)
            {
                OrderInfos = new OrderInfosViewModel();
            }
        }
示例#7
0
        public async Task <IEnumerable <ProductView> > Get(
            [FromServices] GetAllProductQueryProcessor queryProcessor,
            CancellationToken cancellationToken)
        {
            var query = new GetAllProducts();

            return(await queryProcessor.ProcessQuery(query, cancellationToken));
        }
        public async void Test1()
        {
            GetAllProducts getAllProducts = new GetAllProducts();
            await getAllProducts.GetAllProductsList();

            var products = GetAllProducts.productList;

            Assert.NotEmpty(products);
        }
 public void OnGet()
 {
     ShoppingCart = LoadCart();
     CartItems    = new GetCartItems(_context).Do(ShoppingCart.CartId);
     Products     = new GetAllProducts(_context).Do(0)
                    .Where(prod => CartItems.Select(cartItem => cartItem.ProductRefId)
                           .Contains(prod.ProductId));
     Categ = new GetAllCategories(_context).Do();
 }
示例#10
0
        protected virtual void OnGetAllProducts(GetAllProductsEventArgs args)
        {
            EventHandler <GetAllProductsEventArgs> temp = GetAllProducts;

            if (temp != null)
            {
                GetAllProducts?.Invoke(this, args);
            }
        }
        public Task <ItemsResult <Product> > Handle(GetAllProducts request, CancellationToken cancellationToken)
        {
            var entities = _dbContext.Products.ToList();
            var products = _mapper.Map <List <Product> >(entities);
            var result   = new ItemsResult <Product>()
            {
                Items = products
            };

            return(Task.FromResult(result));
        }
        // public IEnumerable<Product> Handle(GetAllProducts query)
        // {
        //     return _context.Products.ToList();
        // }

        public override IEnumerable <Product> Handle(GetAllProducts query)
        {
            IEnumerable <Product> products;

            using (IDbConnection db = new SqlConnection("server=localhost;database=BD_BENCHMARK;trusted_connection=false;User ID=sa;Password=abc123@abc;MultipleActiveResultSets=true"))
            {
                products = db.Query <Product>("Select * From TB_PRODUCT").ToList();
            }

            return(products);
        }
        public async Task <List <ProductDto> > Handle(GetAllProducts request, CancellationToken cancellationToken)
        {
            var connection = dbConnectionFactory.GetDbConnection();

            const string sql = "SELECT P.Id, P.Name, P.Barcode_Value AS Barcode, P.Price_Value AS Price, P.CategoryId " +
                               "FROM Products P " +
                               "WHERE P.LatestVersion = 1";

            var productsCollection = connection.Query <ProductDto>(sql).ToList();

            return(productsCollection);
        }
        private void LoadAsync(int orderId)
        {
            var userName = _userManager.GetUserId(User);

            Orders = new GetAllOrders(_context).Do(userName, orderId);
            if (orderId != -1)
            {
                ProductInOrders = new GetAllProductInOrder(_context).Do(Orders.FirstOrDefault(order => order.OrderId == orderId).OrderId);
                Products        = new GetAllProducts(_context).Do(0, 0)
                                  .Where(prod => ProductInOrders.Select(product => product.ProductRefId).Contains(prod.ProductId));
            }
        }
        public void OnGet()
        {
            var currUser = _userManager.GetUserId(User);

            ShoppingCart = new GetShoppingCart(_context).Do(currUser);
            CartItems    = new GetCartItems(_context).Do(ShoppingCart.CartId);
            Products     = new GetAllProducts(_context).Do()
                           .Where(prod => CartItems.Select(cartItem => cartItem.ProductRefId)
                                  .Contains(prod.ProductId));
            Categ      = new GetAllCategories(_context).Do();
            Order      = new GetOrder(_context).Do(currUser, "Pending");
            OrderInfos = new GetOrderInfo(_context).Do(Order.OrderId);
        }
示例#16
0
 public void OnPost(string ProductName)
 {
     ShoppingCartId = LoadCart().Result.CartId;
     if (ProductName != null)
     {
         Products = new GetAllProducts(_context).Do().Where(prod => prod.Name.ToLower().Contains(ProductName.ToLower()));
     }
     else
     {
         Products = new GetAllProducts(_context).Do();
     }
     Categ = new GetAllCategories(_context).Do();
 }
示例#17
0
        public async Task <IActionResult> Get()
        {
            try
            {
                var getAllProducts = new GetAllProducts();
                var products       = await _mediator.Send(getAllProducts);

                return(Ok(new { products }));
            }
            catch (Exception ex)
            {
                return(BadRequest(new { message = ex.Message }));
            }
        }
        public async void Test11()
        {
            GetAllProducts getAllProducts = new GetAllProducts();
            await getAllProducts.GetAllProductsList();

            var            productsCount  = GetAllProducts.productList.Count;
            RemoveAProduct removeAProduct = new RemoveAProduct();
            await removeAProduct.RemoveAProductByID("P114");

            await getAllProducts.GetAllProductsList();

            var productsCountAfterRemoving = GetAllProducts.productList.Count;

            Assert.Equal(productsCount - 1, productsCountAfterRemoving);
        }
示例#19
0
        public Task <List <ProductResult> > Handle(GetAllProducts request, CancellationToken cancellationToken)
        {
            var result   = _productRepository.GetAll();
            var products = new List <ProductResult>();

            foreach (var product in result)
            {
                products.Add(new ProductResult()
                {
                    Id          = product.Id,
                    Name        = product.Name,
                    Description = product.Description,
                    Image       = product.Image
                });
            }

            return(Task.FromResult(products));
        }
        public async Task <List <ProductReadModel> > GetAllProductAsync(GetAllProducts query)
        {
            const string sql =
                @"SELECT dbo.Products.Id,Brand,Color,CreateTime,[Description],Discount,Expiration,DiscountPrice,ForBaby,Gender,IsDeleted,[Name],Price,Quantity,ProductType,[Weight],Size,Images.[Url],Images.MainImage,Images.Id AS ImgId,Images.ProductId
        FROM Products
        LEFT JOIN Images ON dbo.Products.Id=Images.ProductId;";

            await using var connection = new SqlConnection(_connectionString);

            await using var command = new SqlCommand(sql, connection);

            await connection.EnsureIsOpenAsync().ConfigureAwait(false);

            await using var reader = await command.ExecuteReaderAsync().ConfigureAwait(false);

            var products = new List <ProductReadModel>(20);

            return(await ProductListReaderAsync(reader, products).ConfigureAwait(false));
        }
        public async void Test7()
        {
            GetAllProducts getAllProducts = new GetAllProducts();
            await getAllProducts.GetAllProductsList();

            var      productsCount = GetAllProducts.productList.Count;
            Products product       = new Products()
            {
                Id          = "P115",
                Name        = "DemoProduct2",
                Features    = new[] { "Alarm" },
                Services    = new[] { "ESN" },
                DisplaySize = "upto 10"
            };
            Add_Product addProduct = new Add_Product();
            await addProduct.AddAProduct(product);

            await getAllProducts.GetAllProductsList();

            var productsCountAfterAdding = GetAllProducts.productList.Count;

            Assert.Equal(productsCount + 1, productsCountAfterAdding);
        }
示例#22
0
 public void OnGet()
 {
     ShoppingCartId = LoadCart().Result.CartId;
     Products       = new GetAllProducts(_context).Do();
     Categ          = new GetAllCategories(_context).Do();
 }
示例#23
0
        public async Task <IActionResult> GetAllProductsAsync([FromQuery] GetAllProducts query)
        {
            var data = await Mediator.QueryAsync(query).ConfigureAwait(false);

            return(Ok(data));
        }
示例#24
0
 public Task <List <ProductReadModel> > HandleAsync(GetAllProducts query)
 {
     return(_readRepository.GetAllProductAsync(query));
 }
 public void OnGet()
 {
     Products = new GetAllProducts(_context).Do();
     Categ    = new GetAllCategories(_context).Do();
 }
        public async Task <ItemsResult <Product> > GetAllProducts()
        {
            var query = new GetAllProducts();

            return(await _mediator.Send(query));
        }
示例#27
0
 public async Task <IEnumerable <Product> > Handle(GetAllProducts request, CancellationToken cancellationToken)
 {
     return(await productRepo.GetAllProductsAsync());
 }
 public async Task <IList <ProductEntity> > HandleAsync(GetAllProducts query)
 {
     return(await _dbContext.Products.Where(x => x.Status != ProductStatus.Deleted).ToListAsync());
 }
 public object Any(GetAllProducts request) => new GetAllProductsResponse
 {
     Results = TemplateQueryData.Products
 };
示例#30
0
 public async Task <IEnumerable <ProductRM> > Handle(GetAllProducts request, CancellationToken cancellationToken)
 {
     return(await queryRepository.GetAllAsync());
 }