public async Task <List <GetAllCustomersDto> > Handle(GetAllCustomersQuery request, CancellationToken cancellationToken) { var result = await context.Customers.ToListAsync(); if (result == null) { throw new NotFoundException(); } var customers = mapper.Map <List <GetAllCustomersDto> >(result); foreach (var customer in customers) { var customerStatus = await context.CustomerStatus.FindAsync(customer.CustomerStatusId); if (customerStatus != null) { customer.Status = customerStatus.Status; } if (customer.UserId != null) { var user = await context.Users.FindAsync(customer.UserId); if (user != null) { customer.Username = user.Username; } } } return(customers); }
public async Task <IActionResult> GetCustomers() { var query = new GetAllCustomersQuery(); var result = await _mediator.Send(query); return(Ok(result)); }
public async Task Handle_CustomersExists_ReturnCustomers( [Frozen] Mock <IRepository <Entities.Customer> > customerRepoMock, GetAllCustomersQueryHandler sut, List <Entities.IndividualCustomer> customers, GetAllCustomersQuery query ) { // Arrange customerRepoMock.Setup(x => x.ListAsync( It.IsAny <GetAllCustomersSpecification>(), It.IsAny <CancellationToken>() )) .ReturnsAsync(customers.Cast <Entities.Customer>().ToList()); //Act var result = await sut.Handle(query, CancellationToken.None); //Assert result.Should().NotBeNull(); customerRepoMock.Verify(x => x.ListAsync( It.IsAny <ISpecification <Entities.Customer> >(), It.IsAny <CancellationToken>() )); result.Count.Should().Be(customers.Count); }
public async Task <IReadOnlyList <CustomerDto> > Handle(GetAllCustomersQuery request, CancellationToken cancellationToken) { var customers = await _customerRepository.GetAllAsync(); return(customers.Select(_mapper.Map <CustomerDto>).OrderBy(x => x.FullName).ToList()); }
public async Task <List <CustomerDto> > Handle(GetAllCustomersQuery request, CancellationToken cancellationToken) { // assuming user is authenticated var customers = await _customerDbContext.Customers.ProjectTo <CustomerDto>(_customerMap.ConfigurationProvider).ToListAsync(); return(customers); }
public async Task <List <CustomerListDto> > Handle(GetAllCustomersQuery query, CancellationToken cancellationToken) { var customers = await _dbContext .Customers .ProjectTo <CustomerListDto>(_mapper.ConfigurationProvider) .ToListAsync(cancellationToken); return(customers); }
public ViewResult Index() { var getCustomersQuery = new GetAllCustomersQuery { Page = 1, ResultsPerPage = 10 }; var getCustomersDto = this.getCustomersQueryHandler.Handle(getCustomersQuery); return(this.View(new CustomersViewModel { Data = getCustomersDto })); }
public async Task <List <GetAllCustomerQueryResponse> > Handle(GetAllCustomersQuery request, CancellationToken cancellationToken) { var response = await _repository.GetList(); if (response.Count > 0) { return(_mapper.Map <List <GetAllCustomerQueryResponse> >(response)); } throw new System.Exception("Customer Not Found!"); }
public async Task <IActionResult> GetAllAsync(int pageIndex = 1, int pageSize = 10) { var query = new GetAllCustomersQuery { PageIndex = pageIndex, PageSize = pageSize }; var customers = await Bus.QueryAsync(query); return(Ok(customers)); }
public IActionResult Index() { var query = new GetAllCustomersQuery(); var customers = _queryProcessor.Process(query); var vm = new CustomerViewModel { Customers = customers, SearchTerm = string.Empty }; return(View(vm)); }
public async override Task <IEnumerable <CustomerDto> > HandleAsync(GetAllCustomersQuery query) { return(await Task.FromResult(this.store.Customers .AsQueryable() .ToList() .Select(c => new CustomerDto { Firstname = c.Firstname, Lastname = c.Lastname, Gender = (Queries.GetAllCustomers.Gender)c.Gender }) .ToList())); }
public async Task Handle_GivenValidRequest_ShouldReturnViewModel() { // Arrange var query = new GetAllCustomersQuery(); var sut = new GetAllCustomersQueryHandler(this.deletableEntityRepository); // Act var viewModel = await sut.Handle(query, It.IsAny <CancellationToken>()); viewModel.ShouldNotBeNull(); viewModel.ShouldBeOfType <GetAllCustomersViewModel>(); viewModel.Customers.Count().ShouldBe(1); }
public async Task <ResultWrapper <GetAllCustomersOutput> > Handle(GetAllCustomersQuery request, CancellationToken cancellationToken) { ResultWrapper <GetAllCustomersOutput> result = new ResultWrapper <GetAllCustomersOutput>(); var tDataList = await _dbContext.TUser .Where(x => x.Role == Infrastructure.AppEnums.RoleEnum.Customer) .Where(x => string.IsNullOrEmpty(request.query) || x.Email.Contains(request.query) || x.Phone.Contains(request.query) || x.FirstName.Contains(request.query) || x.LastName.Contains(request.query) ) .Skip(request.pageSize * (request.pageNumber - 1)) .Take(request.pageSize) .ToListAsync(); int totalItems = await _dbContext.TUser .Where(x => x.Role == Infrastructure.AppEnums.RoleEnum.Customer) .Where(x => string.IsNullOrEmpty(request.query) || x.Email.Contains(request.query) || x.Phone.Contains(request.query) || x.FirstName.Contains(request.query) || x.LastName.Contains(request.query) ) .CountAsync(); var list = tDataList.Select(x => new PublicListItem() { Enabled = x.Enabled, Selected = false, Text = x.Email, Value = x.Id.ToString(), Image = string.Empty }) .ToList(); result.Status = true; result.Result = new GetAllCustomersOutput() { list = list, pageSize = request.pageSize, pageNumber = request.pageNumber, totalItems = totalItems }; return(result); }
public async Task <IActionResult> GetCustomers(int pageSize = 20, int pageNumber = 1, string query = "") { GetAllCustomersQuery model = new GetAllCustomersQuery() { query = query, pageNumber = pageNumber <= 0 ? 1 : pageNumber, pageSize = pageSize <= 0 ? 1 : pageSize }; ResultWrapper <GetAllCustomersOutput> result = new ResultWrapper <GetAllCustomersOutput>(); result = await _mediator.Send(model); return(Ok(result)); }
public async Task <IEnumerable <CustomerViewModel> > Handle(GetAllCustomersQuery request, CancellationToken cancellationToken) { var customers = await _allMarktQueryContext .Customers .ToListAsync(cancellationToken); return(from customer in customers select new CustomerViewModel { Id = customer.Id, UserId = customer.UserId, UserDisplayName = customer.User.DisplayName, Address = customer.Address, PhoneNumber = customer.PhoneNumber }); }
public async Task <List <Customer> > Obter() { try { var query = new GetAllCustomersQuery(); Log.Information("Obtendo todos os clientes..."); var result = await _mediatR.Send(query); Log.Information("Clientes Obtidos com sucesso."); return(result); } catch (Exception ex) { Log.Error($"Não foi possível obter clientes: {ex.StackTrace}"); throw; } }
public async Task <IActionResult> GetAllCustomers() { var query = new GetAllCustomersQuery(); var result = await _mediator.Send(query); if (result.isSuccess) { return(Ok(new ApiResponse { ResponseCode = "00", ResponseDescription = result.message, Data = result.response })); } return(NotFound(new ApiResponse { ResponseCode = "01", ResponseDescription = result.message, Data = null })); }
public Task <IEnumerable <CustomerResource> > Handle(GetAllCustomersQuery request, CancellationToken cancellationToken) { if (request == null) { throw new ArgumentNullException(nameof(request)); } var customerEntities = _customerRepository.GetAll(); return(Task.FromResult(customerEntities.Select(customerEntity => new CustomerResource { Id = customerEntity.Id, Name = customerEntity.Name, Email = customerEntity.Email, DateBirth = customerEntity.DateBirth, Address = customerEntity.Address, Gender = (Gender)customerEntity.Gender }))); }
public void Handle_NoCustomersExists_ThrowArgumentNullException( [Frozen] Mock <IRepository <Entities.Customer> > customerRepoMock, GetAllCustomersQueryHandler sut, GetAllCustomersQuery query ) { // Arrange customerRepoMock.Setup(x => x.ListAsync( It.IsAny <GetAllCustomersSpecification>(), It.IsAny <CancellationToken>() )) .ReturnsAsync((List <Entities.Customer>)null); //Act Func <Task> func = async() => await sut.Handle(query, CancellationToken.None); //Assert func.Should().Throw <ArgumentNullException>() .WithMessage("Value cannot be null. (Parameter 'customers')"); }
public async Task Test_ForExistingCustomers_ShouldReturnCustomers() { // Arrange var mock = new Mock <ICustomerRepository>(); Fixture.RepeatCount = 9; var customers = Fixture.Create <Customer[]>(); mock.Setup(foo => foo.GetAll()).Returns(customers); var query = new GetAllCustomersQuery(); var queryHandler = new GetAllCustomersQueryHandler(mock.Object); // Act var result = await queryHandler.Handle(query, CancellationToken.None); // Assert Assert.NotNull(result); Assert.NotEmpty(result); Assert.Equal(customers.Length, result.Count()); }
public async Task <List <CustomerDTO> > Handle(GetAllCustomersQuery request, CancellationToken cancellationToken) { //return await _customerQuery.GetAllCustomersAsync(); _logger.Information("Requested all Customers"); return(await _dbContext.DbSet <Customer>() .Select(x => new CustomerDTO { FirstName = x.FirstName, LastName = x.LastName, Id = x.Id, Orders = x.Orders.Select(or => new OrderDTO { Id = or.Id, BillingAddress = or.BillingAddress, OrderAddress = or.OrderAddress, OrderedDate = or.OrderedDate, OrderNumber = or.OrderNumber }).ToList() }).ToListAsync()); }
public async Task <IEnumerable <Customer.Microservice.Models.Customer> > Handle(GetAllCustomersQuery query, CancellationToken cancellationToken) { var productList = await _context.Customers.ToListAsync(); if (productList == null) { return(null); } return(productList.AsReadOnly()); }
public GetAllCustomersResponse SendQuery(GetAllCustomersQuery query) { return _bus.SendAsync(query).Result; }
public async Task <List <CustomerResponse> > Handle(GetAllCustomersQuery request, CancellationToken cancellationToken) { var customerDtos = await _customersRepository.GetCustomersAsync(); return(_mapper.MapCustomerDtosToCustomerResponses(customerDtos)); }
public async Task <IEnumerable <string> > Handle(GetAllCustomersQuery request, CancellationToken cancellationToken) { var customers = await _context.Set <Account>().Where(x => x.Customer != null && x.Customer.Trim() != string.Empty).Distinct().Select(x => x.Customer).ToListAsync(cancellationToken); return(customers); }
public async Task <List <Customer> > Handle(GetAllCustomersQuery request, CancellationToken cancellationToken) { var list = await _repository.GetAll(); return(list); }
public async Task <List <CustomerDto> > Handle(GetAllCustomersQuery request, CancellationToken cancellationToken) { var result = await _customerRepository.GetAllAsync(); return(_mapper.Map <List <CustomerDto> >(result)); }
public async Task <List <CustomerDto> > Handle(GetAllCustomersQuery request, CancellationToken cancellationToken) { var customers = await _customerRepository.ListAllAsync(); return(customers.Select(x => _mapper.Map <Customer, CustomerDto>(x)).ToList()); }
public async Task <IEnumerable <Customer> > Handle(GetAllCustomersQuery request, CancellationToken cancellationToken) { var customersList = await _context.Customers.ToListAsync(); return(customersList.AsReadOnly()); }
public Task <List <Domain.Customer> > Handle(GetAllCustomersQuery request, CancellationToken cancellationToken) { return(_repository.GetAll()); }
public async Task <IEnumerable <Customer> > Handle(GetAllCustomersQuery request, CancellationToken cancellationToken) { return(await _customersRepository.GetAllCustomers()); }