public async Task <List <SupplierDto> > Handle(GetSuppliersQuery request, CancellationToken cancellationToken) { var result = ( from suppliers in _context.Suppliers join countries in _context.Countries on suppliers.CountryId equals countries.Id join categorySuppliers in _context.CategorySuppliers on suppliers.CategorySupplierId equals categorySuppliers.Id join termsOfPayments in _context.TermsOfPayments on suppliers.TermsOfPaymentId equals termsOfPayments.Id select new SupplierDto { Id = suppliers.Id, Name = suppliers.Name, Email = suppliers.Email, City = suppliers.City, Country = countries.Name, CategorySupplierId = categorySuppliers.Id, CategorySupplier = categorySuppliers.Name, TaxLocation = suppliers.TaxLocation, TermsOfPaymentId = termsOfPayments.Id, TermsOfPayment = termsOfPayments.Name }).ToList(); var supplierPaymentHistoricist = _context.SupplierPaymentHistories.ToList(); result.ForEach(x => x.TheyOwnYou = supplierPaymentHistoricist.Where(y => y.SupplierId == x.Id).Select(z => z.TheyOwnYou).ToList().Sum()); result.ForEach(x => x.YouOwnThem = supplierPaymentHistoricist.Where(y => y.SupplierId == x.Id).Select(z => z.YouOwnThem).ToList().Sum()); result.ForEach(x => x.Balance = supplierPaymentHistoricist.Where(y => y.SupplierId == x.Id).Select(z => z.Balance).ToList().Sum()); return(await Task.FromResult(result)); }
public Task <IQueryable <Supplier> > Handle(GetSuppliersQuery request, CancellationToken cancellationToken) { var selectedPropertiesList = request.GraphQLContext.GetSelectedPropertiesListAsString(); var results = _context .Suppliers .Select <Supplier>($"new({selectedPropertiesList})"); return(Task.FromResult(results)); }
public async Task <IEnumerable <SupplierDto> > Handle(GetSuppliersQuery request, CancellationToken cancellationToken) { return(await _dbContext.Suppliers .Select(s => new SupplierDto { Id = s.Id, Name = s.Name, Description = s.Description, ActualAddress = s.ActualAddress, Code = s.Code, Email = s.Email, LegalAddress = s.LegalAddress, SuppliersTrademark = s.SuppliersTrademark, WebsiteUrl = s.WebsiteUrl }).ToListAsync()); }
public async Task <List <SupplierDto> > Handle(GetSuppliersQuery request, CancellationToken cancellationToken) { var entities = await _context.Suppliers.Include(s => s.Cards).ThenInclude(c => c.Taps).ThenInclude(t => t.Device).ToListAsync(); var responseDto = _mapper.Map <List <Supplier>, List <SupplierDto> >(entities); //var response = new TapsDto // { // //PriorityLevels = Enum.GetValues(typeof(PriorityLevel)) // // .Cast<PriorityLevel>() // // .Select(p => new PriorityLevelDto { Value = (int)p, Name = p.ToString() }) // // .ToList(), // //Lists = await _context.TodoLists // // .ProjectTo<TodoListDto>(_mapper.ConfigurationProvider) // // .OrderBy(t => t.Title) // // .ToListAsync(cancellationToken) //}; return(responseDto); }