Exemple #1
0
        public async Task CreateAsync(Guid id, Guid ownerId, string name,
                                      LocationDto location, string description, decimal fundsPerChild)
        {
            if (location == null)
            {
                throw new ServiceException("invalid_location", "Invalid location.");
            }

            Location foundLocation = null;

            if (!string.IsNullOrWhiteSpace(location.Address))
            {
                foundLocation = await _locationProvider.GetAsync(location.Address);
            }
            if (foundLocation == null && (Math.Abs(location.Latitude) > 0.01 && Math.Abs(location.Longitude) > 0.01))
            {
                foundLocation = await _locationProvider.GetAsync(location.Latitude, location.Longitude);
            }
            if (foundLocation == null)
            {
                throw new ServiceException("address_not_found",
                                           $"Address: '{location.Address} [lat: {location.Latitude}, " +
                                           $"lng: {location.Longitude}]' was not found.");
            }

            var ngo = new Ngo(id, ownerId, name, new Core.Domain.Shared.Location(foundLocation.Address,
                                                                                 foundLocation.Latitude, foundLocation.Longitude), description, fundsPerChild);
            await _ngoRepository.CreateAsync(ngo);
        }