Exemplo n.º 1
0
        private static ICollection<ProviderOrgUnitService> SetServices(ObjectContext context, ProviderOrgUnitV2 source, Provider provider, ICollection<ProviderOrgUnitService> existingServices)
        {
            if (source.Services == null)
                return existingServices;

            try
            {
                //Delete existing services to be sure they are not duplicated.
                existingServices.ToList().ForEach(s => context.DeleteObject(s));

                var Services = context.CreateObjectSet<Service>();
                var providerOrgUnitServices = new List<ProviderOrgUnitService>();

                foreach (ProviderOrgUnitServiceV2 item in source.Services)
                {
                    if (string.IsNullOrEmpty(item.Name))
                        continue;

                    //Ensure Service Exists
                    var service = Services.FirstOrDefault(s => s.Name == item.Name);
                    if (service == null)
                    {
                        service = new Service
                        {
                            Name = item.Name,
                            IsEnabled = true
                        };
                        Services.AddObject(service);
                    }

                    providerOrgUnitServices.Add(new ProviderOrgUnitService(service));
                }

                return providerOrgUnitServices;
            }
            catch (Exception ex)
            {
                throw new BusinessException("Error processing services for provider '" + provider.Name + "' - " + ex.Message, ex);
            }
        }
Exemplo n.º 2
0
        private static ICollection<ProviderOrgUnitInsurance> SetInsurances(ObjectContext context, ProviderOrgUnitV2 source, Provider provider, int orgUnitId, ICollection<ProviderOrgUnitInsurance> existingInsurances)
        {
            if (source.Insurances == null)
                return existingInsurances;

            try
            {
                //Delete existing insurances to be sure they are not duplicated.
                existingInsurances.ToList().ForEach(i => context.DeleteObject(i));

                var insurances = context.CreateObjectSet<Insurance>();
                var orgUnits = context.CreateObjectSet<OrgUnit>();
                var providerOrgUnitInsurances = new List<ProviderOrgUnitInsurance>();

                foreach (ProviderOrgUnitInsuranceV2 item in source.Insurances)
                {
                    if (string.IsNullOrEmpty(item.Name))
                        continue;

                    //Ensure Insurance Exists
                    var insurance = insurances.FirstOrDefault(s => s.Name == item.Name);
                    if (insurance == null)
                    {
                        insurance = new Insurance(item.Name, true);
                        insurances.AddObject(insurance);
                    }

                    if (!orgUnits.Single(ou => ou.Id == orgUnitId).OrgUnitPublished.InsurancesOrgUnit.OrgUnitInsurances.Any(i => i.InsuranceId == insurance.Id))
                        providerOrgUnitInsurances.Add(new ProviderOrgUnitInsurance(insurance));
                }

                return providerOrgUnitInsurances;
            }
            catch (Exception ex)
            {
                throw new BusinessException("Error processing insurances for provider '" + provider.Name + "' - " + ex.Message, ex);
            }
        }
Exemplo n.º 3
0
        private static ICollection<ProviderOrgUnitSchedule> SetSchedules(ObjectContext context, ProviderOrgUnitV2 item, ICollection<ProviderOrgUnitSchedule> existingSchedules)
        {
            if (item.Schedules == null)
                return existingSchedules;

            //Delete existing schedules to be sure they are not duplicated.
            existingSchedules.ToList().ForEach(s => context.DeleteObject(s));

            var list = new List<ProviderOrgUnitSchedule>();

            foreach (ProviderOrgUnitScheduleV2 schedule in item.Schedules)
            {
                list.Add(new ProviderOrgUnitSchedule(new ScheduleTimeSpan(ResolveOpenTime(schedule), ResolveOpenHours(schedule))));
            }
            return list;
        }
Exemplo n.º 4
0
        private static ICollection<ProviderOrgUnitInsurancesInheritedDisabled> SetDisabledInheritedInsurances(ObjectContext context, ProviderOrgUnitV2 source, Provider provider, ICollection<ProviderOrgUnitInsurancesInheritedDisabled> existingInsurancesDisabled)
        {
            if (source.DisabledInheritedInsurances == null)
                return existingInsurancesDisabled;

            try
            {
                //Delete existing insurances to be sure they are not duplicated.
                existingInsurancesDisabled.ToList().ForEach(i => context.DeleteObject(i));

                var insurances = context.CreateObjectSet<Insurance>();
                var disabledInheritedInsurances = new List<ProviderOrgUnitInsurancesInheritedDisabled>();

                foreach (DisabledInheritedInsuranceV2 item in source.DisabledInheritedInsurances)
                {
                    //Ensure Insurance Exists
                    var insurance = insurances.FirstOrDefault(s => s.Name == item.Name);
                    if (insurance == null)
                    {
                        continue;
                    }

                    disabledInheritedInsurances.Add(new ProviderOrgUnitInsurancesInheritedDisabled
                    {
                        Insurance = insurance
                    });
                }

                return disabledInheritedInsurances;
            }
            catch (Exception ex)
            {
                throw new BusinessException("Error processing disabled inherited insurances for provider '" + provider.Name + "' - " + ex.Message, ex);
            }
        }