public async Task <Response <GetGasStationResponseMessage> > GetGasStationsAsync(GetGasStationRequestMessage requestMessage) { var response = Response <GetGasStationResponseMessage> .Create(); if (requestMessage is null) { return(response.WithBusinessError("Search data was not reported or invalid")); } var isCoordinateSearch = double.TryParse(requestMessage.Latitude, out var latitude) & double.TryParse(requestMessage.Longitude, out var longitude); if (string.IsNullOrEmpty(requestMessage.Address) && !isCoordinateSearch) { return(response.WithBusinessError(nameof(requestMessage.Address), "It is necessary to inform the address to be searched or latitude and longitude coordinates")); } var geolocation = isCoordinateSearch ? GetLocationDto.Create(latitude, longitude) : await GetGeocodingAsync(requestMessage.Address); if (geolocation.HasError) { return(response.WithMessages(geolocation.Messages)); } var gasStationsResponse = await GasStationRepository.GetGasStationsByLocationAsync(geolocation.Data.Value); if (gasStationsResponse.HasError) { return(response.WithMessages(gasStationsResponse.Messages)); } return(response.SetValue(gasStationsResponse.Data.Value.ToGetGasStationResponseMessage(geolocation.Data.Value))); }
public async Task <bool> insertLocation(GetLocationDto getLocationDto) { try { Location oLocation = Mapper.Map <GetLocationDto, Location>(getLocationDto); _Locations.Add(oLocation); foreach (var item in getLocationDto.transporttypes) { if (!item.isChecked) { continue; } _LocationTransporttypes.Add(new LocationTransporttype { locationId = getLocationDto.id, transporttypeId = item.id, createdUserId = getLocationDto.userId }); } await _uow.SaveChangesAsync(); return(true); } catch { return(false); } }
public async Task ShouldGetLocationItem() { var locationDto = await SendAsync(new CreateLocationItemCommand() { IsEnabled = true, Name = "ShouldGetLocationItem", OpeningTime = new TimeSpan(0, 19, 0), ClosingTime = new TimeSpan(0, 21, 0), }); GetLocationItemQuery query = new GetLocationItemQuery() { Id = locationDto.Id }; GetLocationDto dto = await SendAsync(query); var created = await ExecuteDbContextAsync(db => db.Locations.Where(c => c.Id.Equals(dto.Id)).SingleOrDefaultAsync()); dto.ShouldNotBeNull(); dto.Id.ShouldBe(created.Id); dto.Name.ShouldBe(created.Name); dto.OpeningTime.ShouldBe(created.OpeningTime); dto.ClosingTime.ShouldBe(created.ClosingTime); dto.IsEnabled.ShouldBe(created.IsEnabled); }
public async Task <GetLocationDto> getLocation(BaseDto baseDto) { GetLocationDto oLocationDto = Mapper.Map <Location, GetLocationDto>(await _Locations.AsNoTracking().SingleOrDefaultAsync(i => i.id == baseDto.id)); oLocationDto.countries = await _CountryService.getCountriesDdlDto(); oLocationDto.transporttypes = await _TransporttypeService.getTransporttypesDto(baseDto); return(oLocationDto); }
public async Task <GetLocationDto> getLocationInitial() { GetLocationDto oLocationDto = new GetLocationDto(); oLocationDto.countries = await _CountryService.getCountriesDdlDto(); oLocationDto.transporttypes = await _TransporttypeService.getTransporttypesDto(); return(oLocationDto); }
public async Task <bool> updateLocation(GetLocationDto getLocationDto) { try { var oLocation = await _Locations.SingleOrDefaultAsync(i => i.id == getLocationDto.id); oLocation.locationName = getLocationDto.locationName; oLocation.locationCode = getLocationDto.locationCode; oLocation.countryId = getLocationDto.countryId; oLocation.isActive = getLocationDto.isActive; oLocation.modiferUserId = getLocationDto.userId; foreach (var item in getLocationDto.transporttypes) { var lnqLocationTransporttypes = await _LocationTransporttypes .SingleOrDefaultAsync(x => x.locationId == getLocationDto.id && x.transporttypeId == item.id); if (item.isChecked && lnqLocationTransporttypes != null) { continue; } if (!item.isChecked && lnqLocationTransporttypes == null) { continue; } if (!item.isChecked && lnqLocationTransporttypes != null) { _LocationTransporttypes.Remove(lnqLocationTransporttypes); } if (item.isChecked && lnqLocationTransporttypes == null) { _LocationTransporttypes.Add(new LocationTransporttype { locationId = getLocationDto.id, transporttypeId = item.id, createdUserId = getLocationDto.userId }); } } await _uow.SaveChangesAsync(); return(true); } catch { return(false); } }
public async Task <HttpResponseMessage> updateLocation(GetLocationDto locationDto) { locationDto.userId = Setting.payloadDto.userId; if (await _LocationService.updateLocation(locationDto)) { return(new HttpResponseMessage(HttpStatusCode.OK)); } else { return(new HttpResponseMessage(HttpStatusCode.NotModified)); } }
public async Task <GetLocationDto> getLocation(int id) { GetLocationDto oLocationDto = await _LocationService.getLocation(new BaseDto { id = id, userId = Setting.payloadDto.userId }); if (oLocationDto == null) { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.NotFound)); } else { return(oLocationDto); } }
public async Task <GetLocationDto> getLocationInitial() { GetLocationDto oLocationDto = await _LocationService.getLocationInitial(); if (oLocationDto == null) { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.NotFound)); } else { return(oLocationDto); } }
public async Task <HttpResponseMessage> insertLocation(GetLocationDto locationDto) { locationDto.userId = Setting.payloadDto.userId; if (await _LocationService.insertLocation(locationDto)) { return(Request.CreateResponse(HttpStatusCode.Created)); } else { return(Request.CreateResponse(HttpStatusCode.InternalServerError)); } //string uri = Url.Link("DefaultApi", new { id = locationDto.Id }); //response.Headers.Location = new Uri(uri); }
public GetLocationDto GetLocation(int id) { IEnumerable <Location> locations = _locationrepository.Get(); var @location = locations.FirstOrDefault(x => x.Id == id); if (@location != null) { var getLocationDto = new GetLocationDto() { Id = location.Id, Country = location.Country, City = location.City, Street = location.Street, HouseNumber = location.HouseNumber, FlatNumber = location.FlatNumber }; return(getLocationDto); } return(null); }
public async Task <Response <List <GasStation> > > GetGasStationsByLocationAsync(GetLocationDto location) { var response = Response <List <GasStation> > .Create(); if (location is null) { response.WithBusinessError("Coordinates are invalid"); } var maxDistance = Settings.GeocoddingSettings.BaseRadius; var customerLocation = new GeoJsonPoint <GeoJson2DGeographicCoordinates>(new GeoJson2DGeographicCoordinates(location.Longitude, location.Latitude)); var gasStations = new List <GasStation>(); while (!gasStations.Any() && maxDistance <= 15000) { var filter = Builders <GasStation> .Filter.Near(x => x.Address.Location, customerLocation, maxDistance) & Builders <GasStation> .Filter.Eq(x => x.DeletedAt, null); gasStations = await Collection.FindAsync(filter) .GetAwaiter() .GetResult() .ToListAsync(); maxDistance += 5000; } return(gasStations); }
public static GetGasStationResponseMessage ToGetGasStationResponseMessage(this List <GasStation> gasStations, GetLocationDto location) => new GetGasStationResponseMessage { GasStations = !gasStations.Any() ? new List <GasStationResponseMessage>() : gasStations.Select(gasStation => new GasStationResponseMessage { Id = gasStation.Id, ExternalId = gasStation.ExternalId, Name = gasStation.Name, PhoneNumber = gasStation.PhoneNumber, SiteUrl = gasStation.SiteUrl, Address = new AddressResponseMessage { StreetAddress = gasStation.Address.StreetAddress, Cep = gasStation.Address.Cep, Complement = gasStation.Address.Complement, City = gasStation.Address.City, UF = gasStation.Address.UF, Latitude = gasStation.Address.Location[1], Longitude = gasStation.Address.Location[0] } }).ToList(), ReferenceLocation = new LocationResponseMessage { Latitude = location.Latitude, Longitude = location.Longitude } };