Esempio n. 1
0
        private void InsertHealthplanEventZipCode(long accountId, string tag, ILogger logger)
        {
            var currentDate  = DateTime.Today.AddDays(1);
            var rangeInMiles = _settings.ZipRangeInMiles;

            var events   = _eventRepository.GetEventsByAccountIdAndDate(accountId, currentDate, null, true);
            var eventIds = events.Select(e => e.Id);

            if (!eventIds.IsNullOrEmpty())
            {
                try
                {
                    var zipIds   = new List <long>();
                    var hostList = _hostRepository.GetEventHosts(eventIds);

                    foreach (var host in hostList)
                    {
                        //var zipcodes = _zipCodeRepository.GetZipCodesInRadius(host.Address.ZipCode.Zip, rangeInMiles);
                        //var hostZipIds = zipcodes.Select(x => x.Id);
                        //if (!zipcodes.IsNullOrEmpty())
                        //    zipIds.AddRange(hostZipIds);

                        //var hostEvents = events.Where(x => x.HostId == host.Id);
                        //foreach (var hostEvent in hostEvents)
                        //{
                        //    _healthPlanFillEventCallQueueRepository.DeleteEventZipByEventId(hostEvent.Id);
                        //    foreach (var zipId in hostZipIds)
                        //    {
                        //        _healthPlanFillEventCallQueueRepository.SaveEventZips(hostEvent.Id, zipId);
                        //    }
                        //}

                        var zipcodes = _zipRadiusDistanceRepository.GetBySourceZipIdAndRadius(host.Address.ZipCode.Id, rangeInMiles);
                        if (!zipcodes.IsNullOrEmpty())
                        {
                            var hostZipIds = zipcodes.Select(x => x.DestinationZipId);
                            zipIds.AddRange(hostZipIds);
                            if (!hostZipIds.IsNullOrEmpty())
                            {
                                var hostEvents = events.Where(x => x.HostId == host.Id);
                                foreach (var hostEvent in hostEvents)
                                {
                                    _healthPlanFillEventCallQueueRepository.DeleteEventZipByEventId(hostEvent.Id);
                                    foreach (var zipId in hostZipIds)
                                    {
                                        _healthPlanFillEventCallQueueRepository.SaveEventZips(hostEvent.Id, zipId);
                                    }
                                }
                            }
                        }
                    }

                    //var stringZipIds = string.Empty;

                    //if (!zipIds.IsNullOrEmpty())
                    //{
                    //    stringZipIds = string.Join(",", zipIds.Distinct().ToArray());
                    //}

                    _accountEventZipReposiory.Save(accountId, zipIds.Distinct().ToArray());

                    logger.Info("Successfully Saved Healthplan Event Zip Data For Account ID: " + accountId);
                }
                catch (Exception ex)
                {
                    logger.Error(string.Format("Error Occurred While Saving Account Zip Data For Account ID: {0}.\n Message {1} \n Stack Trace {2}", accountId, ex.Message, ex.StackTrace));
                }
            }

            try
            {
                var healthPlanEventZip = new HealthPlanEventZip()
                {
                    AccountID        = accountId,
                    AccountTag       = tag,
                    DateCreated      = currentDate,
                    IsQueueGenerated = true
                };

                _healthPlanEventZipRepository.Save(healthPlanEventZip);
            }
            catch (Exception exception)
            {
                logger.Error("some error occurred while saving HealthPlanEventZip");
                logger.Error("Message: " + exception.Message);
                logger.Error("Stack trace: " + exception.StackTrace);
            }
        }
        private void InsertAccountEventZip(long accountId, string tag, AccountEventZipSetting generationSetting)
        {
            var fromDate     = DateTime.Today.AddDays(1);
            var rangeInMiles = _settings.ZipRangeInMiles;

            var events = _eventRepository.GetEventsByAccountIdAndDate(accountId, fromDate, null, true);
            var eventAppointmentStatsModels = _eventAppointmentStatsService.GetStats(events);

            var eventIds = !eventAppointmentStatsModels.IsNullOrEmpty() ? eventAppointmentStatsModels.Where(x => x.FreeSlots > 0 || x.IsDynamicScheduling).Select(x => x.EventId) : null;

            if (eventIds.IsNullOrEmpty())
            {
                _logger.Info("No events found.");
                return;
            }

            _logger.Info("Events found : " + eventIds.Count());

            var zipIds   = new List <long>();
            var hostList = _hostRepository.GetEventHosts(eventIds);

            foreach (var host in hostList)
            {
                var zipcodes = _zipRadiusDistanceRepository.GetBySourceZipIdAndRadius(host.Address.ZipCode.Id, rangeInMiles);

                if (!zipcodes.IsNullOrEmpty())
                {
                    var hostZipIds = zipcodes.Select(x => x.DestinationZipId);
                    zipIds.AddRange(hostZipIds);

                    var recentlyCreatedEvents = events.Where(x => x.HostId == host.Id && x.DataRecorderMetaData.DateCreated > generationSetting.LastGenerationDateTime);

                    _logger.Info("Generating event zip for recently created events. Count : " + recentlyCreatedEvents.Count());

                    foreach (var recentlyCreatedEvent in recentlyCreatedEvents)
                    {
                        if (_healthPlanFillEventCallQueueRepository.IsEventZipAlreadyGenerated(recentlyCreatedEvent.Id))
                        {
                            _logger.Info("Event Zip already generated for EventID : " + recentlyCreatedEvent.Id);
                            continue;
                        }

                        _healthPlanFillEventCallQueueRepository.DeleteEventZipByEventId(recentlyCreatedEvent.Id);
                        foreach (var zipId in hostZipIds)
                        {
                            _healthPlanFillEventCallQueueRepository.SaveEventZips(recentlyCreatedEvent.Id, zipId);
                        }
                    }
                }
            }

            if (generationSetting.LastGeneratedTable == AccountEventZipGenerationType.AccountEventZipSubstitute.ToString())
            {
                _accountEventZipReposiory.Save(accountId, zipIds.Distinct().ToArray());
            }
            else
            {
                _accountEventZipReposiory.SaveSubstitute(accountId, zipIds.Distinct().ToArray());
            }

            //var healthPlanEventZip = new HealthPlanEventZip()
            //{
            //    AccountID = accountId,
            //    AccountTag = tag,
            //    DateCreated = DateTime.Now,
            //    IsQueueGenerated = true
            //};

            //_healthPlanEventZipRepository.Save(healthPlanEventZip);
        }