Beispiel #1
0
        public async Task <ICommandResult <List <Application.Models.Product> > > Handle(
            GetProductsCommand request,
            CancellationToken cancellationToken)
        {
            var repo = this._unitOfWork.GetRepository <Application.Entities.Product>();

            var result = await repo.All();


            List <Application.Models.Product> models = new List <Application.Models.Product>();

            foreach (var product in result)
            {
                var model = new Application.Models.Product();

                model.Name      = product.Name;
                model.Amount    = product.Quantity;
                model.Id        = product.Id;
                model.Price     = product.Price;
                model.ProductId = product.ProductId;

                models.Add(model);
            }

            return(CommandResult <List <Application.Models.Product> > .Success(models));
        }
        public async Task <Result <List <ProductDto> > > Handle(GetProductsCommand request, CancellationToken cancellationToken)
        {
            var productsInDb = await _productRepository.GetRangeAsync(request.Predicate);

            var products = _mapper.Map <List <ProductDto> >(productsInDb);

            return(Result <List <ProductDto> > .Success(products));
        }
Beispiel #3
0
        public async Task <ActionResult> GetProductsAsync()
        {
            var command = new GetProductsCommand();

            CommandResult <List <Models.Product> > result = await _commandDispatcher.ExecuteAsync(command);

            return(Ok(result));
        }
 public async Task <GetProductsResponse> GetProducts
     (GetProductsCommand command,
     CancellationToken cancellationToken = default)
 => await _daprClient.InvokeMethodAsync <GetProductsCommand, GetProductsResponse>
     (StoreAppId,
     "api/dapr/products/",
     command,
     HttpExtension,
     cancellationToken);
 public ProductsController(ILogger <ProductsController> logger, IOptionsSnapshot <WingtipToysProductServiceOptions> options, GetProductCommand cmd1, GetProductsCommand cmd2,
                           [FromServices] IDistributedCache cache)
 {
     _logger             = logger;
     _options            = options;
     _cache              = cache;
     _getProductCommand  = cmd1;
     _getProductsCommand = cmd2;
 }
Beispiel #6
0
        public async Task <IActionResult> GetProducts([FromBody] GetProductsCommand getProductsCommand)
        {
            string accessToken = await HttpContext.GetTokenAsync("access_token");

            getProductsCommand.Token = accessToken;

            await this._busClient.PublishAsync(getProductsCommand);

            return(Accepted());
        }
 public async Task <IActionResult> GetAll([FromQuery] GetProductsCommand model)
 {
     try
     {
         return(await _mediator.Send(model));
     }
     catch (Exception ex)
     {
         _logger.LogError(ex, "Error in {0}", HttpContext.Request.Path);
         return(BadRequest(ErrorMessages.InternalExceptionModel));
     }
 }
 public async Task <GetProductsResponse> GetProductsAsync(
     string url,
     GetProductsCommand getProductsCommand,
     CancellationToken cancellationToken)
 {
     return(await this._daprClient.
            InvokeMethodAsync <GetProductsCommand, GetProductsResponse>
                ("storeapi",
                url,
                getProductsCommand,
                new HTTPExtension { Verb = HTTPVerb.Get },
                cancellationToken));
 }
Beispiel #9
0
 public async Task <GetProductsResponse> GetProductsAsync(
     string url,
     GetProductsCommand getProductsCommand,
     CancellationToken cancellationToken)
 {
     return(await this._daprClient.
            InvokeMethodAsync <GetProductsCommand, GetProductsResponse>
                ("storeapi",
                url,
                getProductsCommand,
                HttpInvocationOptions.UsingGet(),
                cancellationToken));
 }
Beispiel #10
0
        public async Task <IActionResult> GetProducts()
        {
            var command = new GetProductsCommand();

            var result = await this._mediator.Send(command);

            if (result.Status == CommandResultStatus.Success)
            {
                return(new OkObjectResult(result.Result));
            }
            else
            {
                return(new BadRequestObjectResult("Something went wrong"));
            }
        }
Beispiel #11
0
        public async Task <CommandResult <ProductDtoCollection> > Handle(GetProductsCommand request,
                                                                         CancellationToken cancellationToken)
        {
            try
            {
                var products = await _productReadRepository.GetProducts();

                var productDtos = _mapper.Map <IEnumerable <ProductDto> >(products);
                return(new CommandResult <ProductDtoCollection>(new ProductDtoCollection(productDtos)));
            }
            catch (Exception e)
            {
                _logger.LogError(e, Resource.ProductCouldNotBeRetrieved);
                return(new CommandResult <ProductDtoCollection>(Resource.ProductCouldNotBeRetrieved));
            }
        }
Beispiel #12
0
        public ProductsViewModel(IDataRepository dataRepository, IDialogCoordinator dialogCoordinator, DataContext dbContext)
        {
            _dataRepository    = dataRepository;
            _dialogCoordinator = dialogCoordinator;
            _context           = dbContext;

            GetProductsCommand              = new GetProductsCommand(this);
            GetAvailableProductsCommand     = new GetAvailableProductsCommand(this);
            GetSoldProductsCommand          = new GetSoldProductsCommand(this);
            ShowNewProductPanelCommand      = new ShowNewProductPanelCommand(this);
            ShowUpdatingProductPanelCommand = new ShowUpdatingProductPanelCommand(this);
            SelectedCellsChanged            = new SelectedCellsChanged(this);
            SearchProductInGoogleCommand    = new SearchProductInGoogleCommand(this);
            AddProductViewModel             = new AddProductViewModel(this, dataRepository, dialogCoordinator);

            Test = new TestCommand(this);
        }
        public async Task <IList <ProductDto> > Handle(GetProductsCommand request, CancellationToken cancellationToken)
        {
            using var bus = RabbitHutch.CreateBus(_configuration.GetConnectionString("RabbitMq"));

            var products = new List <Product>
            {
                new Product(1, 1, "product 1"),
                new Product(2, 1, "product 2"),
                new Product(3, 2, "product 3"),
            };

            var userIds = products.Select(e => e.UserId)
                          .Distinct()
                          .ToList();

            try
            {
                var usersResponse = await bus.RequestAsync <GetUsersByIdsRequest, GetUsersByIdsResponse>(new GetUsersByIdsRequest
                {
                    Ids = userIds
                });

                var responsedUsersAsUserDtos = usersResponse.Users.Select(e => new UserDto
                {
                    Id    = e.Id,
                    Name  = e.Name,
                    Email = e.Email
                });

                return(products.Select(e => new ProductDto
                {
                    Id = e.Id,
                    Name = e.Name,
                    UserDto = responsedUsersAsUserDtos.FirstOrDefault(user => user.Id == e.UserId)
                }).ToList());
            }
            catch
            {
                return(products.Select(e => new ProductDto
                {
                    Id = e.Id,
                    Name = e.Name,
                    UserDto = null
                }).ToList());
            }
        }
        public async Task <CommandResult <List <Product> > > ExecuteAsync(GetProductsCommand command)
        {
            List <Product> products = new List <Product>()
            {
                new Product {
                    Name = "Person 1", Uid = Guid.NewGuid()
                },
                new Product {
                    Name = "Person 2", Uid = Guid.NewGuid()
                },
                new Product {
                    Name = "Person 3", Uid = Guid.NewGuid()
                },
                new Product {
                    Name = "Person 4", Uid = Guid.NewGuid()
                },
            };

            return(await Task.FromResult(new CommandResult <List <Product> >(true, "OK", products, HttpStatusCode.OK)));
        }
 public Task <List <Product> > Handle(GetProductsCommand request, CancellationToken cancellationToken)
 {
     return(_testDbContext.Products.ToListAsync(cancellationToken));
 }