public override void Handle(IBulkRatingsPredictionSchedulesCreated command)
        {
            var ratingsPredictionSchedules = new List <RatingsPredictionSchedule>();

            foreach (var ratingsPredictionScheduleModel in command.Data)
            {
                var ratingsPredictionSchedule = _ratingsScheduleRepository.GetSchedule(ratingsPredictionScheduleModel.ScheduleDay.Date, ratingsPredictionScheduleModel.SalesArea);
                if (ratingsPredictionSchedule != null)
                {
                    _ratingsScheduleRepository.Remove(ratingsPredictionSchedule);
                }

                ratingsPredictionSchedules.Add(_mapper.Map <RatingsPredictionSchedule>(ratingsPredictionScheduleModel, opts => opts.UseEntityCache(_salesAreaByIdCache)));
            }

            _ratingsScheduleRepository.Insert(ratingsPredictionSchedules, false);
            _ratingsScheduleRepository.SaveChanges();
        }
Exemple #2
0
        public IHttpActionResult Post([FromBody] List <CreateRatingsPredictionSchedule> command)
        {
            if (command == null || !ModelState.IsValid || !command.Any())
            {
                return(this.Error().InvalidParameters("Invalid Ratings Prediction Schedule parameters"));
            }

            // Create list of RatingsPredictionSchedule instances to add
            var ratingsPredictionSchedules = new List <RatingsPredictionSchedule>();

            foreach (var ratingsPredictionScheduleModel in command)
            {
                var ratingsPredictionSchedule = _ratingsScheduleRepository.GetSchedule(ratingsPredictionScheduleModel.ScheduleDay.Date, ratingsPredictionScheduleModel.SalesArea);
                if (ratingsPredictionSchedule != null)          // Exists already, remove it
                {
                    _ratingsScheduleRepository.Remove(ratingsPredictionSchedule);
                }
                ratingsPredictionSchedules.Add(_mapper.Map <RatingsPredictionSchedule>(ratingsPredictionScheduleModel));
            }

            // Add
            _ratingsScheduleRepository.Insert(ratingsPredictionSchedules);
            return(Ok());
        }