public async Task <List <PaymentMethodGroupViewModel> > Handle(PaymentMethodListQuery request, CancellationToken cancellationToken) { var tenantId = this._userIdentityService.GetTenantId(); var entities = await this._repository.Find(c => c.Active && c.EntityStatus != Domain.Entities.EntityStatus.Deleted); var result = entities.Select(entity => new PaymentMethodGroupViewModel { PaymentMethodGroupId = entity.PaymentMethodGroupId, Name = entity.Name, Description = entity.Description, Label = entity.Label, CountryIsoCode = entity.CountryIsoCode, Order = entity.Order, PaymentMethods = entity.PaymentMethods.Select(c => new PaymentMethodListViewModel { PaymentMethodId = c.PaymentMethodId, Code = c.Code, Name = c.Name, Description = c.Description, CountryIsoCode = c.CountryIsoCode, IconLink = c.IconLink }).ToList() }).OrderBy(x => x.Order).ToList(); var paymentMethodAvailables = await this._paymentMethodTenantRepository.GetPaymentMethods(tenantId); foreach (var group in result) { foreach (var item in group.PaymentMethods) { if (paymentMethodAvailables != null && paymentMethodAvailables.Any(x => x.PaymentMethodId.Equals(item.PaymentMethodId))) { group.Enabled = true; break; } } } return(result); }
public async Task <IActionResult> Get([FromQuery] PaymentMethodListQuery query) { var model = await this._mediator.Send(query); return(this.Ok(model)); }