Ejemplo n.º 1
0
        public async Task SetAsync(Guid activityId, ActivityLocation location)
        {
            var oldLocation = await _locationRepository
                              .AsQueryable()
                              .SingleOrDefaultAsync(l => l.ActivityId == activityId);

            if (oldLocation is null)
            {
                if (location is null)
                {
                    return;
                }

                var newLocation = new ActivityLocationEntity()
                {
                    ActivityId   = activityId,
                    Address      = location.Address,
                    ShortAddress = location.ShortAddress
                };

                await _locationRepository.AddAsync(newLocation);
            }
            else
            {
                if (location?.Address == null || location.ShortAddress == null)
                {
                    await _locationRepository.DeleteAsync(oldLocation.Id);
                }
                else
                {
                    oldLocation.Address      = location.Address;
                    oldLocation.ShortAddress = location.ShortAddress;
                    await _locationRepository.UpdateAsync(oldLocation);
                }
            }
        }
Ejemplo n.º 2
0
        public void Set(Guid activityId, ActivityLocation location)
        {
            var oldLocation = _locationRepository
                              .AsQueryable()
                              .SingleOrDefault(l => l.ActivityId == activityId);

            if (oldLocation is null)
            {
                if (location is null)
                {
                    return;
                }

                var newLocation = new ActivityLocationEntity()
                {
                    ActivityId   = activityId,
                    Address      = location.Address,
                    ShortAddress = location.ShortAddress
                };

                _locationRepository.Add(newLocation);
            }
            else
            {
                if (location?.Address == null || location.ShortAddress == null)
                {
                    _locationRepository.Delete(oldLocation);
                }
                else
                {
                    oldLocation.Address      = location.Address;
                    oldLocation.ShortAddress = location.ShortAddress;
                    _locationRepository.Update(oldLocation);
                }
            }
        }