public override void Handle(IClashUpdated command) { var clash = _clashRepository.CheckClashByExternalRef(command.Externalref); clash.ParentExternalidentifier = command.ParentExternalidentifier; clash.Description = command.Description; clash.DefaultPeakExposureCount = command.ExposureCount; clash.DefaultOffPeakExposureCount = command.ExposureCount; clash.Differences = _mapper.Map <List <ClashDifference> >(command.Differences); foreach (var difference in clash.Differences) { difference.TimeAndDow = new GamePlan.Domain.Generic.Types.TimeAndDowAPI { StartTime = new TimeSpan(6, 0, 0), EndTime = new TimeSpan(5, 59, 59) }; difference.TimeAndDow.SetDaysOfWeek("1111111"); } if (!string.IsNullOrWhiteSpace(clash.ParentExternalidentifier)) { _clashRepository.CheckClashParents(new[] { clash }); } _clashRepository.Add(clash); _clashRepository.SaveChanges(); }
public override void Handle(IBulkClashDeleted command) { var clashes = _clashRepository.FindByExternal(command.Data.Select(c => c.Externalref).ToList()).ToList(); if (clashes.Any()) { _clashRepository.DeleteRange(clashes.Select(c => c.Uid)); _clashRepository.SaveChanges(); } else { _logger.Warn("Clashes can't be found with specified external references."); } }
public override void Handle(IBulkClashCreatedOrUpdated command) { var clashModels = _mapper.Map <List <GamePlan.Domain.BusinessRules.Clashes.Objects.Clash> >(command.Data); _clashRepository.CheckClashParents(clashModels); var externalRefs = command.Data.Select(x => x.Externalref).ToList(); var dbClashes = _clashRepository.FindByExternal(externalRefs); var newEntities = new List <GamePlan.Domain.BusinessRules.Clashes.Objects.Clash>(); foreach (var item in clashModels) { var existingClash = dbClashes.SingleOrDefault(x => x.Externalref.Equals(item.Externalref, StringComparison.OrdinalIgnoreCase)); foreach (var difference in item.Differences) { difference.TimeAndDow = new GamePlan.Domain.Generic.Types.TimeAndDowAPI { StartTime = new TimeSpan(6, 0, 0), EndTime = new TimeSpan(5, 59, 59) }; difference.TimeAndDow.SetDaysOfWeek("1111111"); } if (existingClash == null) { newEntities.Add(item); } else { existingClash.ParentExternalidentifier = item.ParentExternalidentifier; existingClash.Description = item.Description; existingClash.DefaultOffPeakExposureCount = item.ExposureCount; existingClash.DefaultPeakExposureCount = item.ExposureCount; existingClash.Differences = item.Differences; } } _clashRepository.Add(newEntities); _clashRepository.UpdateRange(dbClashes); _clashRepository.SaveChanges(); }