コード例 #1
0
        public async Task <Address> Add(Address address)
        {
            var path        = $"{_baseUri}";
            var addressLine = $"{address.AddressLine1} {address.City}";

            try
            {
                var locations = await Geocoding.GetLocationsAsync(addressLine);

                var location = locations.First();

                address.Latitude  = location.Latitude;
                address.Longitude = location.Longitude;

                var dto = _mapper.Map <Address, AddressDto>(address);

                var resultDto = await WebApiClient.PostCallApi <AddressDto, AddressDto>(path, dto);

                return(_mapper.Map <AddressDto, Address>(resultDto));
            }
            catch (HttpRequestException e)
            {
                Console.WriteLine(e.Message);
                return(null);
            }
        }
コード例 #2
0
        public async Task <User> SignInAsync(UserLoginDto dto)
        {
            var path = $"{_baseUri}/signin";

            try
            {
                var userDto = await WebApiClient.PostCallApi <UserDto, UserLoginDto>(path, dto);

                if (userDto == null)
                {
                    return(null);
                }

                var user = _mapper.Map <User>(userDto);

                await SaveUserAsync(user);

                return(user);
            }
            catch (HttpRequestException e)
            {
                Console.WriteLine(e.Message);
                return(null);
            }
        }
コード例 #3
0
        public async Task <List <Driver> > GetInRange(double latitude, double longitude, int km)
        {
            var path    = $"{_baseUri}/GetInRange";
            var postDto = new DriverInRangeDto()
            {
                Latitude        = latitude,
                Longitude       = longitude,
                MaxDistanceInKm = km
            };

            try
            {
                var driverDtos = await WebApiClient.PostCallApi <List <DriverDto>, DriverInRangeDto>(path, postDto);

                if (driverDtos == null)
                {
                    return(null);
                }

                var drivers = _mapper.ProjectTo <Driver>(driverDtos.AsQueryable()).ToList();

                return(drivers);
            }
            catch (HttpRequestException e)
            {
                Console.WriteLine(e.Message);
                return(null);
            }
        }
コード例 #4
0
        public async Task <Order> PlaceOrder(Order order)
        {
            var path = $"{_baseUri}/TryPlaceOrder";
            var dto  = _mapper.Map <OrderDto>(order);

            try
            {
                var result = await WebApiClient.PostCallApi <OrderDto, OrderDto>(path, dto);

                return(result == null ? null : _mapper.Map <Order>(result));
            }
            catch (HttpRequestException e)
            {
                Console.WriteLine(e.Message);
                return(null);
            }
        }