示例#1
0
        public async Task <Result <Courier> > Identify(CourierIdentificationContext context)
        {
            var customer = await _db.Customers.FindAsync(context.CustomerId);

            if (customer == null)
            {
                _logger.LogInformation("Customer not found.");

                return(new Result <Courier> {
                    Reason = ReasonType.CustomerNotFound, IsSuccessful = false
                });
            }

            var customerAddress = await _db.Addresses.FindAsync(customer.AddressId);

            foreach (var courier in (from courier in _db.Couriers select courier).ToList())
            {
                var address = await _db.Addresses.FindAsync(courier.AddressId);

                if (address == null || address.RegionId != customerAddress.RegionId || address.City != customerAddress.City)
                {
                    continue;
                }

                if (!courier.IsActive || courier.Status != (int)CourierStatus.Idle)
                {
                    Log.Information($"Courier {courier.CourierId} could not be chosen because he/she status is not available.");
                    continue;
                }

                _logger.LogInformation($"Courier {courier.CourierId} was identified for dispatch.");

                return(new Result <Courier> {
                    Value = MapEntity(courier, address), IsSuccessful = true
                });
            }

            _logger.LogInformation("No couriers currently available in the area.");

            return(new Result <Courier> {
                Reason = ReasonType.CourierNotAvailable, IsSuccessful = false
            });
        }
示例#2
0
 public async Task <Result <Courier> > Identify(CourierIdentificationContext context) => throw new NotImplementedException();