public override void Handle(IBulkBreakCreated command) { _metadataRepository.ValidateBreakType(command.Data.Select(b => b.BreakType).ToList()); _salesAreaRepository.ValidateSalesArea(command.Data.Select(s => s.SalesArea).ToList()); var salesAreaDictionary = _salesAreaRepository.GetAll() .ToDictionary(x => x.Name, x => x.CustomId); var breaks = _mapper.Map <List <Break> >(command.Data); // Populate break data counting custom ID from zero for each day var breakGroups = breaks.GroupBy(s => new { s.ScheduledDate.Date, s.SalesArea }); foreach (var breakGroup in breakGroups) { PopulateBreakProperties(breakGroup.ToList(), salesAreaDictionary); } _breakRepository.Add(breaks); // Note: this implies that any batch of breaks recieved should be treated as the only // schedule breaks for a schedule day ie. overwrite list not append to list foreach (var breakGroup in breakGroups) { var schedule = _scheduleRepository.GetSchedule(breakGroup.Key.SalesArea, breakGroup.Key.Date) ?? new Schedule { SalesArea = breakGroup.Key.SalesArea, Date = breakGroup.Key.Date }; schedule.Breaks = breakGroup.ToList(); _scheduleRepository.Add(schedule); } _scheduleRepository.SaveChanges(); }
public void Handle(IBulkStandardDayPartCreated command) { var dayParts = _mapper.Map <List <StandardDayPart> >(command.Data); _salesAreaRepository.ValidateSalesArea(dayParts.Select(c => c.SalesArea).ToList()); _standardDayPartRepository.AddRange(dayParts); _standardDayPartRepository.SaveChanges(); }
public void Handle(IBulkInventoryLockCreated command) { var inventoryLocks = _mapper.Map <List <InventoryLock> >(command.Data.ToList()); _salesAreaRepository.ValidateSalesArea(inventoryLocks.Select(c => c.SalesArea).ToList()); _inventoryLockRepository.AddRange(inventoryLocks); _inventoryLockRepository.SaveChanges(); }
public void Handle(IBulkTotalRatingCreated command) { var totalRatings = _mapper.Map <List <TotalRating> >(command.Data); _demographicRepository.ValidateDemographics(totalRatings.Select(c => c.Demograph).ToList()); _salesAreaRepository.ValidateSalesArea(totalRatings.Select(c => c.SalesArea).ToList()); _totalRatingRepository.AddRange(totalRatings); _totalRatingRepository.SaveChanges(); }
public void Handle(IBulkSpotBookingRuleCreated command) { var spotBookingRules = _mapper.Map <List <SpotBookingRule> >(command.Data); _salesAreaRepository.ValidateSalesArea(command.Data.Where(c => c.SalesAreas != null && c.SalesAreas.Any()).SelectMany(c => c.SalesAreas).ToList()); _metadataRepository.ValidateBreakType(command.Data.Select(c => c.BreakType).ToList()); _spotBookingRuleRepository.AddRange(spotBookingRules); _spotBookingRuleRepository.SaveChanges(); }
public override void Handle(IBulkLengthFactorCreated command) { var salesAreaNames = command.Data.Select(x => x.SalesArea).Distinct().ToList(); _salesAreaRepository.ValidateSalesArea(salesAreaNames); var lengthFactors = _mapper.Map <List <GamePlan.Domain.LengthFactors.LengthFactor> >(command.Data); _repository.AddRange(lengthFactors); _repository.SaveChanges(); }
public void Handle(IBulkStandardDayPartGroupCreated command) { var daypartGroups = _mapper.Map <List <StandardDayPartGroup> >(command.Data); _standardDayPartRepository.ValidateDayParts(command.Data.Where(c => c.Splits != null && c.Splits.Any()).SelectMany(c => c.Splits.Select(d => d.DayPartId)).ToList()); _salesAreaRepository.ValidateSalesArea(daypartGroups.Select(c => c.SalesArea).ToList()); _demographicRepository.ValidateDemographics(daypartGroups.Select(c => c.Demographic).ToList()); _standardDayPartGroupRepository.AddRange(daypartGroups); _standardDayPartGroupRepository.SaveChanges(); }
public override void Handle(IBulkUniverseCreated command) { _salesAreaRepository.ValidateSalesArea(command.Data.Select(x => x.SalesArea).ToList()); _demographicRepository.ValidateDemographics(command.Data.Select(x => x.Demographic).ToList()); var universes = _universeRepository.Search(command.Data.Select(x => x.Demographic).Distinct().ToList(), command.Data.Select(x => x.SalesArea).Distinct().ToList(), DateTime.MinValue, DateTime.MinValue).ToList(); SaveUniverse(command.Data.ToList(), universes); _universeRepository.SaveChanges(); }
public override void Handle(IBulkRestrictionCreatedOrUpdated command) { if (command.Data.Any()) { var newRestrictionModelItems = command.Data.ToList(); ValidateNewRestrictions(newRestrictionModelItems); var salesAreas = newRestrictionModelItems.SelectMany(x => x.SalesAreas) .Select(x => x.Trim()) .Distinct() .ToList(); _salesAreaRepository.ValidateSalesArea(salesAreas); var programmeCategoryNames = newRestrictionModelItems .Select(x => x.ProgrammeCategory) .Distinct(StringComparer.OrdinalIgnoreCase).ToList(); _programmeCategoryRepository.ValidateProgrammeCategory(programmeCategoryNames); var clearenceCodes = newRestrictionModelItems .Where(x => !string.IsNullOrWhiteSpace(x.ClearanceCode)) .Select(x => x.ClearanceCode) .Distinct(StringComparer.OrdinalIgnoreCase).ToList(); ValidateClearanceCodes(clearenceCodes); var newRestrictions = _mapper.Map <List <RestrictionDbObject> >(newRestrictionModelItems); var allSalesAreaQty = _salesAreaRepository.CountAll; foreach (var newRestriction in newRestrictions) { newRestriction.Uid = Guid.NewGuid(); if ((newRestriction.SalesAreas?.Any() ?? false) && newRestriction.SalesAreas.Count == allSalesAreaQty) { newRestriction.SalesAreas = new List <string>(); } } _restrictionRepository.UpdateRange(newRestrictions); _restrictionRepository.SaveChanges(); } }