public async Task <int> Create(Location location) { await _locationRepository.AddAsync(location); await _unitOfWork.SaveAsync(); return(location.LocationId); }
public async Task Handle(LocationCreatedEvent notification, CancellationToken cancellationToken) { var locationEntry = _mapper.Map <LocationReader>(notification.LocationAdded); await _locations.AddAsync(locationEntry, cancellationToken); await RaiseLocationAddedEvent(notification, locationEntry, cancellationToken); }
/// <summary> /// Creates a new location. /// </summary> /// <param name="locationViewModel"></param> /// <param name="ct"></param> /// <returns>LocationViewModel</returns> public async Task <LocationViewModel> AddLocationAsync(LocationRequestViewModel locationRequestViewModel, CancellationToken ct = default(CancellationToken)) { var location = new Location { Longitude = (double)locationRequestViewModel.Longitude, Latitude = (double)locationRequestViewModel.Latitude, VehicleId = (int)locationRequestViewModel.VehicleId, CreatedAt = DateTime.Now }; location = await _repository.AddAsync(location, ct); var locationViewModel = LocationConverter.Convert(location); return(locationViewModel); }
public async Task <LocationResponse> SaveAsync(Location Location) { try { await _locationRepository.AddAsync(Location); await _unitOfWork.CompleteAsync(); return(new LocationResponse(Location)); } catch (Exception ex) { // Do some logging stuff return(new LocationResponse($"An error occurred when saving the Location: {ex.Message}")); } }
public async Task <Location> AddLocationAsync(int accountId, Location location) { Guard.AgainstNull(location, "location"); Guard.AgainstAccountNumberMismatch(accountId, location.AccountId, "accountId", "location.AccountId"); try { await _locationRepository.AddAsync(location); _logger.LogInformation($"Added location, new Id = {location.Id}"); return(location); } catch (Exception ex) { _logger.LogError(ex, $"Error adding location: {location}."); return(null); } }