public bool Save(ZipRadiusDistance zipRadiusDistance)
        {
            using (var adapter = PersistenceLayer.GetDataAccessAdapter())
            {
                var entity = Mapper.Map <ZipRadiusDistance, ZipRadiusDistanceEntity>(zipRadiusDistance);

                if (!adapter.SaveEntity(entity, false))
                {
                    throw new PersistenceFailureException();
                }

                return(true);
            }
        }
Esempio n. 2
0
        private EventHostViewData Create(Event eventData, IEnumerable <Pod> pods, ZipCode zipCode,
                                         EventAppointmentStatsModel eventAppointmentStatsModel, IEnumerable <EventTest> testsInEvent,
                                         Host eventHost, IEnumerable <OrderedPair <long, string> > corporateAccountNames = null,
                                         IEnumerable <OrderedPair <long, string> > hospitalPartnerNames = null, IEnumerable <ZipRadiusDistance> zipRadiusDistances = null)
        {
            //var eventHost = _hostRepository.GetHostForEvent(eventData.Id);
            var    totalAppointmentSlotsForThisEvent     = eventAppointmentStatsModel.TotalSlots - eventAppointmentStatsModel.BlockedSlots;
            var    availableAppointmentSlotsForThisEvent = eventAppointmentStatsModel.FreeSlots;
            double distanceFromOriginalZipCode           = 0L;

            if (zipCode != null && eventHost.Address.ZipCode != null)
            {
                ZipRadiusDistance zipRadiusDistance = null;
                if (!zipRadiusDistances.IsNullOrEmpty())
                {
                    zipRadiusDistance = zipRadiusDistances.SingleOrDefault(x => x.SourceZipId == zipCode.Id && x.DestinationZipId == eventHost.Address.ZipCode.Id);
                }

                distanceFromOriginalZipCode = zipRadiusDistance != null
                    ? Math.Round(zipRadiusDistance.Distance, 2)
                    : CalculateDistanceBetweenTwoZips(zipCode, eventHost.Address.ZipCode);
            }

            var hasBreastCancerTest = testsInEvent.Any(te => TestGroup.BreastCancer.Contains(te.TestId));

            string sponseredBy = string.Empty;

            if (!corporateAccountNames.IsNullOrEmpty())
            {
                var sponserName = corporateAccountNames.FirstOrDefault(x => x.FirstValue == eventData.Id);
                if (sponserName != null)
                {
                    sponseredBy = sponserName.SecondValue;
                }
                else
                {
                    if (!hospitalPartnerNames.IsNullOrEmpty())
                    {
                        sponserName = hospitalPartnerNames.FirstOrDefault(x => x.FirstValue == eventData.Id);
                    }
                    sponseredBy = sponserName != null ? sponserName.SecondValue : _settings.CompanyName;
                }
            }
            else
            {
                if (!hospitalPartnerNames.IsNullOrEmpty())
                {
                    var sponserName = hospitalPartnerNames.FirstOrDefault(x => x.FirstValue == eventData.Id);
                    if (sponserName != null)
                    {
                        sponseredBy = sponserName.SecondValue;
                    }
                }
                if (string.IsNullOrEmpty(sponseredBy))
                {
                    sponseredBy = _settings.CompanyName;
                }
            }

            var eventHostViewData = new EventHostViewData(eventData, eventHost, pods, totalAppointmentSlotsForThisEvent,
                                                          availableAppointmentSlotsForThisEvent, distanceFromOriginalZipCode, hasBreastCancerTest, eventAppointmentStatsModel.IsDynamicScheduling, sponseredBy);

            eventHostViewData.BookedSlots    = eventAppointmentStatsModel.FilledSlots;
            eventHostViewData.InvitationCode = eventData.InvitationCode;
            return(eventHostViewData);
        }