Пример #1
0
        /// <summary>
        /// Adds the given location to the eca system.
        /// </summary>
        /// <param name="additionalLocation">The new location.</param>
        /// <returns>The task.</returns>
        public async Task <Location> CreateAsync(AdditionalLocation additionalLocation)
        {
            Location city     = null;
            Location country  = null;
            Location division = null;
            Location region   = null;

            if (additionalLocation.CityId.HasValue)
            {
                city = await CreateGetLocationByIdQuery(additionalLocation.CityId).FirstOrDefaultAsync();

                throwIfLocationNotFound(additionalLocation.CityId.Value, city, "City");
            }
            if (additionalLocation.DivisionId.HasValue)
            {
                division = await CreateGetLocationByIdQuery(additionalLocation.DivisionId).FirstOrDefaultAsync();

                throwIfLocationNotFound(additionalLocation.DivisionId.Value, division, "Division");
            }
            if (additionalLocation.CountryId.HasValue)
            {
                country = await CreateGetLocationByIdQuery(additionalLocation.CountryId).FirstOrDefaultAsync();

                throwIfLocationNotFound(additionalLocation.CountryId.Value, country, "Country");
            }
            if (additionalLocation.RegionId.HasValue)
            {
                region = await CreateGetLocationByIdQuery(additionalLocation.RegionId).FirstOrDefaultAsync();

                throwIfLocationNotFound(additionalLocation.RegionId.Value, region, "Region");
            }
            var existingLocations = await CreateGetLikeLocationsQuery(additionalLocation).ToListAsync();

            throwIfLocationsAlreadyExist(additionalLocation, existingLocations);

            var locationType = await Context.LocationTypes.FindAsync(additionalLocation.LocationTypeId);

            throwIfLocationTypeDoesNotExist(additionalLocation.LocationTypeId, locationType);

            return(DoCreate(
                       country: country,
                       division: division,
                       city: city,
                       region: region,
                       locationType: locationType,
                       additionalLocation: additionalLocation));
        }
Пример #2
0
        private Location DoCreate(Location region, Location country, Location division, Location city, LocationType locationType, AdditionalLocation additionalLocation)
        {
            var validationEntity = GetLocationValidationEntity(additionalLocation, region, country, division, city);

            locationValidator.ValidateCreate(validationEntity);
            if (division == null && city != null && city.Division != null)
            {
                division = city.Division;
            }
            if (country == null && division != null && division.Country != null)
            {
                country = division.Country;
            }
            if (region == null && country != null && country.Region != null)
            {
                region = country.Region;
            }
            var newLocation = new Location
            {
                IsActive     = true,
                City         = city,
                Country      = country,
                Division     = division,
                Region       = region,
                Latitude     = additionalLocation.Latitude,
                Longitude    = additionalLocation.Longitude,
                LocationName = additionalLocation.LocationName,
                LocationType = locationType,
            };

            Context.Locations.Add(newLocation);
            additionalLocation.Audit.SetHistory(newLocation);
            return(newLocation);
        }
Пример #3
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="additionalLocation"></param>
 /// <returns></returns>
 public Task <Location> CreateAsync(AdditionalLocation additionalLocation)
 {
     Contract.Requires(additionalLocation != null, "The additional location must not be null.");
     return(Task.FromResult <Location>(null));
 }
Пример #4
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="additionalLocation"></param>
 /// <returns></returns>
 public Location Create(AdditionalLocation additionalLocation)
 {
     Contract.Requires(additionalLocation != null, "The additional location must not be null.");
     return(null);
 }