public async Task <IEnumerable <ParcelDto> > HandleAsync(GetParcels query) { Size? size = null; Status?status = null; if (Enum.TryParse <Size>(query.Size, true, out var parcelSize)) { size = parcelSize; } if (Enum.TryParse <Status>(query.Status, true, out var parcelStatus)) { status = parcelStatus; } var parcels = await _parcelsRepository.BrowseAsync(size, status); return(parcels.Select(p => new ParcelDto { Id = p.Id, Name = p.Name, Size = p.Size.ToString(), Status = p.Status.ToString() })); }
public async Task <IEnumerable <ParcelDto> > HandleAsync(GetParcels query) { var documents = _parcelRepository.Collection.AsQueryable(); if (query.CustomerId.HasValue) { documents = documents.Where(p => p.CustomerId == query.CustomerId); } if (!query.IncludeAddedToOrders) { documents = documents.Where(p => !p.AddedToOrder); } var parcels = await documents.ToListAsync(); return(parcels.Select(p => p.AsDto())); }
public async Task <IEnumerable <ParcelDto> > HandleAsync(GetParcels query) { var documents = _database.GetCollection <Parcel>("parcels").AsQueryable(); if (Enum.TryParse <Size>(query.Size, true, out var size)) { documents = documents.Where(p => p.Size == size); } if (Enum.TryParse <Status>(query.Status, true, out var status)) { documents = documents.Where(p => p.Status == status); } var parcels = await documents.ToListAsync(); return(parcels.Select(p => new ParcelDto(p))); }
public async Task <IEnumerable <ParcelDto> > HandleAsync(GetParcels query) { var documents = _parcelRepository.Collection.AsQueryable(); if (query.CustomerId.HasValue) { var identity = _appContext.Identity; if (identity.IsAuthenticated && identity.Id != query.CustomerId && !identity.IsAdmin) { return(Enumerable.Empty <ParcelDto>()); } documents = documents.Where(p => p.CustomerId == query.CustomerId); } if (!query.IncludeAddedToOrders) { documents = documents.Where(p => !p.AddedToOrder); } var parcels = await documents.ToListAsync(); return(parcels.Select(p => p.AsDto())); }
public async Task <ActionResult <IEnumerable <ParcelDto> > > Get([FromQuery] GetParcels query) { var parcels = await _dispatcher.QueryAsync(query); return(Ok(parcels)); }