Beispiel #1
0
        public override void Handle(ISalesAreaUpdated command)
        {
            var salesArea = _salesAreaRepository.FindByCustomId(command.CustomId);

            if (salesArea is null)
            {
                throw new DataSyncException(DataSyncErrorCode.SalesAreaNotFound, "no sales area found");
            }

            _demographicRepository.ValidateDemographics(new List <string> {
                command.BaseDemographic1, command.BaseDemographic2
            });
            ValidateSalesAreaDemographics(command);

            var newSalesArea = _mapper.Map <SalesArea>(command);

            UpdateSalesAreaModel(salesArea, newSalesArea);
            _salesAreaRepository.Update(salesArea);

            var demographics = _mapper.Map <IEnumerable <SalesAreaDemographic> >(command.Demographics).ToList();

            demographics.ForEach(x => x.SalesArea = salesArea.Name);
            UpdateSalesAreaDemographics(salesArea, demographics);

            _salesAreaRepository.SaveChanges();
        }
        public override void Handle(IBulkSalesAreaDeleted command)
        {
            var salesAreas = _salesAreaRepository.FindByShortNames(command.Data.Select(c => c.ShortName));

            if (salesAreas.Any())
            {
                _salesAreaRepository.DeleteRange(salesAreas.Select(c => c.Id));
                _salesAreaDemographicRepository.DeleteBySalesAreaNames(salesAreas.Select(c => c.Name));

                _salesAreaRepository.SaveChanges();
            }
        }
Beispiel #3
0
        public override void Handle(IBulkHolidayCreated command)
        {
            foreach (var holiday in command.Data)
            {
                List <SalesArea> salesAreas = GetSalesAreasFromDatabase(holiday.SalesAreaNames);

                salesAreas.ForEach(salesArea =>
                {
                    Add(salesArea, holiday.HolidayDateRanges, holiday.HolidayType);
                });

                _salesAreaRepository.Update(salesAreas);
            }

            _salesAreaRepository.SaveChanges();
        }
        public override void Handle(IBulkHolidayDeleted command)
        {
            var salesAreas = _salesAreaRepository.GetAll().ToList();

            foreach (var commandItem in command.Data)
            {
                foreach (var salesArea in salesAreas)
                {
                    salesArea.PublicHolidays?.RemoveAll(c => c.Start >= commandItem.StartDate && c.End <= commandItem.EndDate);
                    salesArea.SchoolHolidays?.RemoveAll(c => c.Start >= commandItem.StartDate && c.End <= commandItem.EndDate);
                }
            }

            _salesAreaRepository.Update(salesAreas);
            _salesAreaRepository.SaveChanges();
        }
Beispiel #5
0
        public IHttpActionResult Post([FromBody] CreateSalesAreaModel command)
        {
            if (command == null || !ModelState.IsValid)
            {
                return(this.Error().InvalidParameters());
            }
            Validate(command.BaseDemographic1, command.BaseDemographic2);

            //Input values are validated by calling Validate method as part of MapFrom
            var salesArea = SalesArea.MapFrom(Guid.NewGuid(),
                                              command.Name,
                                              command.ShortName,
                                              command.CurrencyCode,
                                              command.BaseDemographic1,
                                              command.BaseDemographic2,
                                              command.ChannelGroup,
                                              command.StartOffset,
                                              command.DayDuration);

            _salesAreaRepository.Add(salesArea);
            _salesAreaRepository.SaveChanges();
            return(Ok(_mapper.Map <SalesAreaModel>(salesArea)));
        }