コード例 #1
0
        public void Save(HealthPlanEventZip healthPlanEventZip)
        {
            using (var adapter = PersistenceLayer.GetDataAccessAdapter())
            {
                if (healthPlanEventZip != null && healthPlanEventZip.AccountID > 0)
                {
                    Delete(healthPlanEventZip.AccountID);

                    var entity = Mapper.Map <HealthPlanEventZip, HealthPlanEventZipEntity>(healthPlanEventZip);

                    if (!adapter.SaveEntity(entity, true))
                    {
                        throw new PersistenceFailureException();
                    }
                }
            }
        }
コード例 #2
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);
            }
        }