public async Task <IEnumerable <Freight> > Handle(GetAllFreightsQuery query, CancellationToken cancellationToken)
            {
                var freights = await _context.Freights.ToListAsync();

                if (freights == null)
                {
                    return(null);
                }
                return(freights.AsReadOnly());
            }
Example #2
0
        public override async Task GetAllFreights(GetAllFreightsRequest request, IServerStreamWriter <FreightModel> responseStream, ServerCallContext context)
        {
            GetAllFreightsQuery   query    = new GetAllFreightsQuery();
            IEnumerable <Freight> freights = await _mediator.Send(query);

            foreach (Freight freight in freights)
            {
                FreightModel model = new FreightModel
                {
                    Width       = freight.Width,
                    Height      = freight.Height,
                    Length      = freight.Length,
                    FreightType = Protos.FreightType.FullTruckLoad,
                    Weight      = freight.Weight,
                    CreateDate  = Timestamp.FromDateTime(freight.CreateDate)
                };
            }
        }