private async void OnSave() { UpdateLocation(Location, _editingLocation); if (EditMode) { await _repo.UpdateLocationAsync(_editingLocation); } else { await _repo.AddLocationAsync(_editingLocation); } Done(); }
public async Task <LocationResponse> AddLocationAsync(LocationRequest request) { var vehicle = await vehiclesRepository.GetVehicleByVehicleIdAsync(request.VehicleId); if (vehicle == null) { return(null); } var location = new Location { VehicleId = vehicle.VehicleId, Latitude = request.Latitude, Longitude = request.Longitude, UpdateDate = DateTime.UtcNow }; await locationsRepository.AddLocationAsync(location); return(MapLocationResponse(location)); }
public async Task AddLocationAsync_WithLocationRequest_ReturnLocationResponse() { var locationRequest = new LocationRequest { VehicleId = 1, Latitude = 13.788571, Longitude = 100.538034 }; var vehicle = new Vehicle { Id = Guid.NewGuid(), VehicleId = 1, Number = "A-001", Model = "Honda City", Description = "Blue Color" }; var location = new Location { Id = Guid.NewGuid(), VehicleId = 1, Latitude = 13.788571, Longitude = 100.538034, UpdateDate = new DateTime(2020, 3, 2) }; vehiclesRepository.GetVehicleByVehicleIdAsync(Arg.Any <int>()).Returns(Task.FromResult(vehicle)); locationsRepository.AddLocationAsync(Arg.Any <Location>()).Returns(Task.FromResult(location)); // Act var response = await locationsService.AddLocationAsync(locationRequest); // Assert Assert.NotNull(response); Assert.IsType <LocationResponse>(response); Assert.Equal(1, response.VehicleId); Assert.Equal(13.788571, response.Latitude); Assert.Equal(100.538034, response.Longitude); }
public async Task <bool> AddLocationAsync(AddressInfo addressInfo) { var location = addressInfo.ToLocation(); return(await _repository.AddLocationAsync(location)); }