示例#1
0
        public async Task <ServiceResponse <List <GetUserDTO> > > GetNearbyUsers(GetNearByDTO location)
        {
            var serviceResponse = new ServiceResponse <List <GetUserDTO> >();

            try
            {
                serviceResponse.Data = _mapper.Map <List <GetUserDTO> >(await _repository.GetNearByDapper(location.Latitude, location.Longitude));
            }
            catch (Exception ex)
            {
                serviceResponse.Success = false;
                serviceResponse.Message = ex.Message;
            }

            return(serviceResponse);
        }
示例#2
0
        public async Task <ServiceResponse <List <GetProductDTO> > > GetNearbyProducts(GetNearByDTO location)
        {
            var serviceResponse = new ServiceResponse <List <GetProductDTO> >();

            try
            {
                List <User> nearByUsers = await _userRepository.GetNearByDapper(location.Latitude, location.Longitude);

                List <Product> products = new List <Product>();
                nearByUsers.ForEach((usr) => {
                    var userProducts   = _repository.GetProductByUserIdDapper(usr.Id).Result;
                    var activeProducts = userProducts.Where(x => x.Status == ProductStatus.Active).ToList();
                    activeProducts.ForEach(x => x.User = usr);
                    products.AddRange(activeProducts);
                });

                serviceResponse.Data = _mapper.Map <List <GetProductDTO> >(products);
            }
            catch (Exception ex)
            {
                serviceResponse.Success = false;
                serviceResponse.Message = ex.Message;
            }

            return(serviceResponse);
        }
 public async Task <IActionResult> Nearby(GetNearByDTO location)
 {
     return(Ok(await _service.GetNearbyProducts(location)));
 }