Exemplo n.º 1
0
        /// <summary>
        /// Removes specified data object.
        /// </summary>
        /// <param name="context">ObjectContext object</param>
        /// <param name="obj">Data object to remove</param>
        /// <returns>
        /// entity set name
        /// </returns>
        public static void RemoveObject(ObjectContext context,
            DataObject obj)
        {
            Debug.Assert(context != null);

            context.DeleteObject(DataObjectHelper.GetEntityObject(obj));
        }
Exemplo n.º 2
0
 protected void DeleteObject(ObjectContext context, object entity)
 {
     try
     {
         context.DeleteObject(entity);
     }
     catch (Exception ex)
     {
         throw new EntityContextException("DeleteObject failed.", ex);
     }
 }
        public static void UpdateEventType(Event target, IEnumerable<int> eventTypeIds, ObjectContext objectContext)
        {
            if (eventTypeIds.Count() > 0)
            {
                target.EventTypeAssociations.ToList().ForEach(e => objectContext.DeleteObject(e));

                foreach (var typeId in eventTypeIds)
                    target.EventTypeAssociations.Add(new EventTypeAssociation() { EventTypeId = typeId, EventId = target.Id });
            }
            else
                throw new BusinessException("Event Type requires at least one value");
        }
Exemplo n.º 4
0
        /// <summary>
        /// Registers the attended for the specific event.
        /// </summary>
        /// <param name="occurence">The event occurence.</param>
        /// <param name="registration">The event registration.</param>
        /// <param name="attendee">The attendee.</param>
        /// <param name="amountPaid">The amount paid.</param>
        /// <param name="userProfile">The user profile.</param>
        /// <param name="sessionId">The session id.</param>
        /// <param name="context">The Object Context</param>
        /// <param name="discountCode">The Discount Code used</param>
        /// <param name="forcePayLater">Flag weather or not to force the PaymentRequired to true</param>
        public static void Add(EventOccurrence occurence, EventRegistration registration, EventAttendee attendee, decimal amountPaid, UserProfile userProfile, string sessionId, ObjectContext context, string discountCode, bool forcePayLater)
        {
            if (!string.IsNullOrEmpty(discountCode))
                attendee.DiscountCodeId = FindDiscountCodeId(discountCode, occurence.Id, context);

            var paymentRequired = (forcePayLater || occurence.AllowPayOnSite && amountPaid == 0 && occurence.Cost > 0) ? true : false;
            occurence.RegisterAttendee(registration, attendee, amountPaid, paymentRequired);
            AddActivity(userProfile, attendee.Name, occurence, sessionId);

            UpdateProfileEventCart(userProfile);

            var notificationSubscriber = occurence.EventOccurrenceNotifications.SingleOrDefault(n => string.Equals(n.Email, attendee.Email.Value, System.StringComparison.OrdinalIgnoreCase));
            if (notificationSubscriber != null)
                context.DeleteObject(notificationSubscriber);
        }
Exemplo n.º 5
0
        public static void AddExternalIdMapping(ObjectContext context, EventV2 source, Event theEvent)
        {
            if (!string.IsNullOrEmpty(source.EventExternalId))
            {
                var existingMappings = context.CreateObjectSet<DataImportEntityIdMap>()
                    .Where(m => m.EntityName == "Event" && m.InternalId == theEvent.Id)
                    .ToList();

                if (existingMappings.Count == 1)
                {
                    if (existingMappings[0].ExternalId != source.EventExternalId)
                    {
                        // Update ExternalId on existing mapping
                        existingMappings[0].ExternalId = source.EventExternalId;
                    }
                }
                else
                {
                    // Remove ambiguous mappings (if any)
                    if (existingMappings.Count > 1)
                    {
                        foreach (var mapping in existingMappings)
                        {
                            context.DeleteObject(mapping);
                        }
                    }

                    // Create new mapping
                    context.AddObject("DataImportEntityIdMaps", new DataImportEntityIdMap
                    {
                        EntityName = "Event",
                        DataImportId = 2,
                        InternalId = theEvent.Id,
                        ExternalId = source.EventExternalId
                    });
                }
            }
        }
Exemplo n.º 6
0
        public static void SetProviderSpecialties(ObjectContext context, ProviderV2 source, Provider provider)
        {
            if (source.Specialties == null)
                return;

            try
            {
                foreach (var item in provider.ProviderSpecialties.ToArray())
                    context.DeleteObject(item);

                var specialtiesObjectSet = context.CreateObjectSet<Specialty>();

                //Get all referenced parent specialties
                var uniqueParentSpecialties = source.Specialties
                    .Where(s => !string.IsNullOrEmpty(s.ParentSpecialtyName))
                    .Select(s => new KeyValuePair<string, string>(s.ParentSpecialtyName, s.SpecialtyType))
                    .Distinct();

                //Ensure parent specialties exist
                var parentSpecialties = EnsureParentSpecialtiesExist(uniqueParentSpecialties, specialtiesObjectSet);

                var providerSpecialties = new List<ProviderSpecialty>();

                foreach (var item in source.Specialties)
                {
                    var specialty = specialtiesObjectSet.FirstOrDefault(s => s.Name == item.SpecialtyName);

                    if (specialty == null)
                    {
                        specialty = parentSpecialties.FirstOrDefault(s => s.Name == item.SpecialtyName);

                        if (specialty == null)
                        {
                            var specialtyType = string.IsNullOrEmpty(item.SpecialtyType) ? SpecialtyType.Specialty : item.SpecialtyType;

                            specialty = new Specialty() { Name = item.SpecialtyName, IsEnabled = true, SpecialtyType = specialtyType };
                            if (!string.IsNullOrEmpty(item.ParentSpecialtyName))
                            {
                                specialty.ParentSpecialty = parentSpecialties.FirstOrDefault(s => s.Name == item.ParentSpecialtyName && s.SpecialtyType == specialtyType);
                            }
                            specialtiesObjectSet.AddObject(specialty);
                        }
                    }

                    providerSpecialties.Add(new ProviderSpecialty(provider, specialty)
                    {
                        IsBoardCertified = ConvertToBool(item.IsBoardCertified, false, "Specialty/IsBoardCertified", provider.FullName),
                        IsPrimary = ConvertToBool(item.IsPrimary, false, "Specialty/IsPrimary", provider.FullName),
                    });
                }

                provider.ProviderSpecialties = providerSpecialties;
            }
            catch (Exception ex)
            {
                throw new BusinessException("Error processing specialties for provider '" + provider.Name + "' - " + ex.Message, ex);
            }
        }
Exemplo n.º 7
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);
            }
        }
Exemplo n.º 8
0
        public static void SetProviderOrgUnits(ObjectContext context, ProviderV2 source, Provider provider)
        {
            if (source.OrgUnits == null)
                return;

            if (source.OrgUnits.Where(o => ConvertToBool(o.IsPrimary, false, "OrgUnit/IsPrimary", provider.FullName)).Count() > 1)
                throw new BusinessException("Only 1 org unit can be specified as the primary org unit.");

            try
            {
                var providerOrgUnits = provider.ProviderOrgUnits.ToArray();
                List<int> currentOrgUnitIds = new List<int>();

                CheckForDuplicateOrgUnits(source);

                foreach (var item in source.OrgUnits)
                {
                    int orgUnitId = 0;

                    if (string.IsNullOrEmpty(item.OrgUnitId) && string.IsNullOrEmpty(item.OrgUnitExternalId))
                        throw new BusinessException("Please supply either the OrgUnitId or the OrgUnitExternalId");

                    if (!string.IsNullOrEmpty(item.OrgUnitExternalId))
                        orgUnitId = LookupInternalId(context, item.OrgUnitExternalId, "OrgUnit");
                    else if (!string.IsNullOrEmpty(item.OrgUnitId))
                        orgUnitId = ConvertToInt(item.OrgUnitId, "OrgUnitId", provider.FullName);

                    currentOrgUnitIds.Add(orgUnitId);

                    var existingProviderOrgUnit = providerOrgUnits.SingleOrDefault(pou => pou.OrgUnitId == orgUnitId);
                    if (existingProviderOrgUnit != null)
                    {
                        existingProviderOrgUnit.Phone = item.Phone;
                        existingProviderOrgUnit.IsPrimary = ConvertToBool(item.IsPrimary, false, "OrgUnit/IsPrimary", provider.FullName);
                        existingProviderOrgUnit.Fax = item.Fax;
                        existingProviderOrgUnit.IsAcceptingNewPatients = ConvertToBool(item.IsAcceptingNewPatients, false, "OrgUnit/IsAcceptingNewPatients", provider.FullName);
                        existingProviderOrgUnit.OrgUnitExternalId = item.OrgUnitExternalId;
                        existingProviderOrgUnit.ProviderOrgUnitInsurances = SetInsurances(context, item, provider, orgUnitId, existingProviderOrgUnit.ProviderOrgUnitInsurances);
                        existingProviderOrgUnit.ProviderOrgUnitServices = SetServices(context, item, provider, existingProviderOrgUnit.ProviderOrgUnitServices);
                        existingProviderOrgUnit.ProviderOrgUnitInsurancesInheritedDisableds = SetDisabledInheritedInsurances(context, item, provider, existingProviderOrgUnit.ProviderOrgUnitInsurancesInheritedDisableds);
                        existingProviderOrgUnit.Schedules = SetSchedules(context, item, existingProviderOrgUnit.Schedules);
                        existingProviderOrgUnit.AllowAppointmentRequests = ConvertToBool(item.AllowAppointmentRequests, true, "OrgUnit/AllowAppointmentRequests", provider.FullName);

                    }
                    else
                    {
                        var orgUnit = context.CreateObjectSet<OrgUnit>().SingleOrDefault(o => o.Id == orgUnitId);

                        if (orgUnit == null)
                            throw new BusinessException("Unable to find Org Unit with Internal Id of " + orgUnitId);

                        var providerOrgUnit = new ProviderOrgUnit(provider, orgUnit)
                        {
                            Phone = item.Phone,
                            IsPrimary = ConvertToBool(item.IsPrimary, false, "OrgUnit/IsPrimary", provider.FullName),
                            Fax = item.Fax,
                            IsAcceptingNewPatients = ConvertToBool(item.IsAcceptingNewPatients, false, "OrgUnit/IsAcceptingNewPatients", provider.FullName),
                            AllowAppointmentRequests = ConvertToBool(item.AllowAppointmentRequests, true, "OrgUnit/AllowAppointmentRequests", provider.FullName),
                            OrgUnitExternalId = item.OrgUnitExternalId,
                            ProviderOrgUnitInsurances = SetInsurances(context, item, provider, orgUnitId, new List<ProviderOrgUnitInsurance>()),
                            ProviderOrgUnitServices = SetServices(context, item, provider, new List<ProviderOrgUnitService>()),
                            ProviderOrgUnitInsurancesInheritedDisableds = SetDisabledInheritedInsurances(context, item, provider, new List<ProviderOrgUnitInsurancesInheritedDisabled>()),
                            Schedules = SetSchedules(context, item, new List<ProviderOrgUnitSchedule>())
                        };
                        provider.ProviderOrgUnits.Add(providerOrgUnit);
                    }
                }

                //Remove necessary org units
                var orgUnitIdsToDelete = providerOrgUnits.Select(o => o.OrgUnitId).Except(currentOrgUnitIds);
                var providerOrgUnitsToDelete = provider.ProviderOrgUnits.Where(o => orgUnitIdsToDelete.Contains(o.OrgUnitId)).ToList();
                foreach (var pou in providerOrgUnitsToDelete)
                    pou.ProfileProviderOrgUnits.ToList().ForEach(p => context.DeleteObject(p));
                providerOrgUnitsToDelete.ForEach(p => context.DeleteObject(p));
            }
            catch (Exception ex)
            {
                throw new BusinessException("Error processing org units for provider '" + provider.Name + "' - " + ex.Message, ex);
            }
        }
Exemplo n.º 9
0
        public static void SetProviderProviderTypes(ObjectContext context, ProviderV2 source, Provider provider)
        {
            if (source.ProviderTypes == null)
                return;

            try
            {
                var existingProviderTypes = provider.ProviderProviderTypes.ToArray();
                foreach (var item in existingProviderTypes)
                    context.DeleteObject(item);

                var providerTypes = context.CreateObjectSet<ProviderType>();
                var providerProviderTypes = new List<ProviderProviderType>();

                foreach (var item in source.ProviderTypes)
                {
                    //Ensure Provider Type Exists
                    var pt = providerTypes.FirstOrDefault(s => s.Name == item.Name);
                    if (pt == null)
                    {
                        pt = new ProviderType
                        {
                            Name = item.Name,
                            IsEnabled = true
                        };
                        providerTypes.AddObject(pt);
                    }

                    var addedProviderType = new ProviderProviderType(provider, pt);
                    providerProviderTypes.Add(addedProviderType);
                }

                provider.ProviderProviderTypes = providerProviderTypes;
            }
            catch (Exception ex)
            {
                throw new BusinessException("Error processing provider types for provider '" + provider.Name + "' - " + ex.Message, ex);
            }
        }
 public void PersistDeletionOf(IAggregateRoot entity)
 {
     _objectContext.DeleteObject(entity);
 }
Exemplo n.º 11
0
        public static void SetProviderOrgUnitAffiliations(ObjectContext context, ProviderV2 source, Provider provider)
        {
            if (source.OrgUnitAffiliations == null)
                return;

            try
            {
                var existingOrgUntiAffiliation = provider.ProviderOrgUnitAffiliations.ToArray();
                foreach (var item in existingOrgUntiAffiliation)
                    context.DeleteObject(item);

                var providerOrgUnitAffiliations = new List<ProviderOrgUnitAffiliation>();
                var services = context.CreateObjectSet<Service>();

                foreach (var item in source.OrgUnitAffiliations)
                {
                    var orgUnitId = ConvertToInt(item.OrgUnitId, "HospitalAffiliation/OrgUnitId", provider.FullName);
                    var orgUnitTypeId = ConvertToInt(item.OrgUnitTypeId, "HospitalAffiliation/OrgUnitId", provider.FullName);
                    var orgUnit = context.CreateObjectSet<OrgUnit>().SingleOrDefault(o => o.Id == orgUnitId && o.OrgUnitTypeAssociations.Any(t => t.OrgUnitType.Id == orgUnitTypeId));
                    if (orgUnit == null)
                        throw new BusinessException("No org unit exists for org unit id '" + item.OrgUnitId + "' and org unit type id '" + item.OrgUnitTypeId + "'");

                    var service = services.SingleOrDefault(s => s.Name == item.Service);
                    if (service == null)
                    {
                        service = new Service
                        {
                            Name = item.Service,
                            Description = item.Service,
                            IsEnabled = true
                        };
                        services.AddObject(service);
                    }

                    providerOrgUnitAffiliations.Add(new ProviderOrgUnitAffiliation
                        {
                            OrgUnitId = orgUnitId,
                            OrgUnitTypeId = orgUnitTypeId,
                            Service = service
                        });
                }

                provider.ProviderOrgUnitAffiliations = providerOrgUnitAffiliations;
            }
            catch (Exception ex)
            {
                throw new BusinessException("Error processing clinical interests for provider '" + provider.Name + "' - " + ex.Message, ex);
            }
        }
Exemplo n.º 12
0
        public static void SetProviderClinicalInterests(ObjectContext context, ProviderV2 source, Provider provider)
        {
            if (source.ClinicalInterests == null)
                return;

            try
            {
                var existingClinicalInterests = provider.ProviderClinicalInterests.ToArray();
                foreach (var item in existingClinicalInterests)
                    context.DeleteObject(item);

                var clinicalInterests = context.CreateObjectSet<ClinicalInterest>();
                var providerClinicalInterests = new List<ProviderClinicalInterest>();

                foreach (var item in source.ClinicalInterests)
                {
                    //Ensure Clinical Interest Exists
                    var clinicalInterest = clinicalInterests.FirstOrDefault(s => s.Name == item.Name);
                    if (clinicalInterest == null)
                    {
                        clinicalInterest = new ClinicalInterest(item.Name, true);
                        clinicalInterests.AddObject(clinicalInterest);
                    }

                    providerClinicalInterests.Add(new ProviderClinicalInterest(provider, clinicalInterest));
                }

                provider.ProviderClinicalInterests = providerClinicalInterests;
            }
            catch (Exception ex)
            {
                throw new BusinessException("Error processing clinical interests for provider '" + provider.Name + "' - " + ex.Message, ex);
            }
        }
Exemplo n.º 13
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.º 14
0
        public static void SetOccurrenceDates(ObjectContext context, EventOccurrenceV2 source, EventOccurrence target)
        {
            if (source.EventOccurrenceDates == null)
                return;

            try
            {
                //remove all dates, we add all dates in source below
                var existingDates = target.EventOccurrenceDates.ToArray();
                foreach (var item in existingDates)
                    context.DeleteObject(item);

                //Add occurrence date to the target
                foreach (var item in source.EventOccurrenceDates)
                {
                    target.AddOccurrenceDate(GetDateTime(item.StartDate).Value, GetDateTime(item.EndDate));
                }
            }
            catch (Exception ex)
            {
                throw new BusinessException("Error processing event occurrence dates - " + ex.Message, ex);
            }
        }
Exemplo n.º 15
0
        public static void SetProviderCertificationAgencies(ObjectContext context, ProviderV2 source, Provider provider)
        {
            if (source.CertificationAgencies == null)
                return;

            try
            {
                var existingCertificationSpecialties = provider.ProviderCertificationSpecialties.ToArray();
                foreach (var item in existingCertificationSpecialties)
                    context.DeleteObject(item);

                var providerCertificationSpecialties = new List<ProviderCertificationSpecialty>();

                foreach (var certificationAgency in source.CertificationAgencies)
                {
                    var agencies = context.CreateObjectSet<CertificationAgency>();

                    //Ensure Agency Exists
                    var agency = agencies.FirstOrDefault(s => s.Name == certificationAgency.AgencyName);
                    if (agency == null)
                    {
                        agency = new CertificationAgency(certificationAgency.AgencyName);
                        agencies.AddObject(agency);
                    }

                    foreach (var certificationBoard in certificationAgency.CertificationBoards)
                    {
                        var boards = agency.CertificationBoards;

                        //Ensure Board Exists
                        var board = boards.FirstOrDefault(s => s.Name == certificationBoard.BoardName);
                        if (board == null)
                        {
                            board = agency.AddCertificationBoard(certificationBoard.BoardName);
                        }

                        foreach (var certificationSpecialty in certificationBoard.CertificationSpecialties)
                        {
                            var specialties = board.CertificationSpecialties;

                            //Ensure Specialty Exists
                            var specialty = specialties.FirstOrDefault(s => s.Name == certificationSpecialty.Name);
                            if (specialty == null)
                            {
                                specialty = board.AddCertificationSpecialty(certificationSpecialty.Name);
                                specialty.IsSubspecialty = ConvertToBool(certificationSpecialty.IsSubSpecialty, false, "CertificationSpecialty/IsSubSpecialty", provider.FullName);
                            }

                            providerCertificationSpecialties.Add(new ProviderCertificationSpecialty(provider, specialty, certificationSpecialty.YearOfIssuance));
                        }
                    }
                }

                provider.ProviderCertificationSpecialties = providerCertificationSpecialties;
            }
            catch (Exception ex)
            {
                throw new BusinessException("Error processing certification specialties for provider '" + provider.Name + "' - " + ex.Message, ex);
            }
        }
Exemplo n.º 16
0
        public static void SetOrgUnitDiscountCodes(ObjectContext context, OrgUnitV2 source, OrgUnit orgUnit)
        {
            //ignore null values
            if (source.OrgUnitDiscountCodes == null)
                return;

            try
            {
                var existingOrgUnitDiscountCodes = orgUnit.OrgUnitDiscountCodes.ToArray();
                foreach (var item in existingOrgUnitDiscountCodes)
                    context.DeleteObject(item);

                var discountCodes = context.CreateObjectSet<DiscountCode>();
                var orgUnitDiscountCodes = new List<OrgUnitDiscountCode>();

                foreach (var item in source.OrgUnitDiscountCodes)
                {
                    //Check if discount code exists
                    var discountCode = discountCodes.FirstOrDefault(i => i.Code == item.Code);

                    //If the discount code doesn't exist, create a new one
                    if (discountCode == null)
                    {
                        discountCode = new DiscountCode()
                        {
                            Code = item.Code,
                            Description = item.Description,
                            DiscountTypeId = LookupDiscountType(context, item.DiscountType),
                            IsEnabled = item.IsEnabled.ToString().ToUpperInvariant() == "TRUE" ? true : false,
                            IsFromOrgUnit = true,
                            IsGroupCode = item.IsGroupCode.ToString().ToUpperInvariant() == "TRUE" ? true : false,
                        };
                        int requiredGroupSize;
                        if (int.TryParse(item.RequiredGroupSize.ToString(), out requiredGroupSize))
                            discountCode.RequiredGroupSize = requiredGroupSize;

                        decimal discountValue;
                        if (decimal.TryParse(item.DiscountValue, out discountValue))
                            discountCode.DiscountValue = discountValue;

                        DateTime startDate;
                        if (DateTime.TryParse(item.StartDate, out startDate))
                            discountCode.StartDate = startDate;

                        DateTime endDate;
                        if (DateTime.TryParse(item.EndDate, out endDate))
                            discountCode.EndDate = endDate;

                        discountCodes.AddObject(discountCode);
                    }
                    else
                    {
                        //Ensure existing discount code is not an Event discount code
                        if (!discountCode.IsFromOrgUnit)
                        {
                            throw new BusinessException("Discount code already in use by an Event.");
                        }
                        UpdateExistingCode(context, discountCode, item);
                    }

                    var newOrgUnitDiscountCode = new OrgUnitDiscountCode();
                    var codeWithId = discountCodes.FirstOrDefault(d => d.Code == discountCode.Code);

                    newOrgUnitDiscountCode.DiscountCodeId = codeWithId == null ? 0 : codeWithId.Id;
                    newOrgUnitDiscountCode.DiscountCode = discountCode;

                    int orgUnitId;
                    if (int.TryParse(source.CopiedInternalId, out orgUnitId))
                        newOrgUnitDiscountCode.OrgUnitId = orgUnitId;

                    orgUnitDiscountCodes.Add(newOrgUnitDiscountCode);
                }

                orgUnit.OrgUnitDiscountCodes = orgUnitDiscountCodes;
            }
            catch (Exception ex)
            {
                throw new BusinessException("Error processing OrgUnitDiscountCodes for orgUnit '" + orgUnit.Name + "' - " + ex.Message, ex);
            }
        }
Exemplo n.º 17
0
 public void Borrar(ObjectContext contexto, SaveOptions saveOptions)
 {
     contexto.DeleteObject(this);
     contexto.SaveChanges(saveOptions);
 }
Exemplo n.º 18
0
        void Delete <T>(T entity)
        {
            ObjectContext context = ((IObjectContextAdapter)this).ObjectContext;

            context.DeleteObject(entity);
        }
Exemplo n.º 19
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.º 20
0
        public static void SetDiscountCodes(ObjectContext context, EventV2 source, Event theEvent)
        {
            foreach (var eventCode in theEvent.EventDiscountCodes.ToList())
            {
                context.DeleteObject(eventCode);
            }

            if (source.DiscountCodes == null || !source.DiscountCodes.Any())
                return;

            var discountCodes = context.CreateObjectSet<DiscountCode>();

            foreach (var discount in source.DiscountCodes)
            {
                if (string.IsNullOrEmpty(discount.Code))
                    throw new BusinessException("Code for discount code is required");

                DiscountCode code = new DiscountCode();

                //Check if org unit discount code exists
                if (theEvent.OrgUnitId.HasValue)
                    code = FindOrgUnitDiscountCode(context, theEvent, discount);

                if (code == null)
                {
                    //Check if event discount code exists
                    code = FindEventDiscountCode(context, discount);
                    if (code == null)
                    {
                        //If no discount with the given code is found, create a new event discount code
                        if (string.IsNullOrEmpty(discount.DiscountType))
                            throw new BusinessException("Unable to add discount code.  DiscountType is required");
                        if (string.IsNullOrEmpty(discount.DiscountValue))
                            throw new BusinessException("Unable to add discount code.  DiscountValue is required");

                        code = CreateEventDiscountCode(context, discount);

                        if (code.StartDate.HasValue && code.EndDate.HasValue && code.EndDate < code.StartDate)
                            throw new BusinessException("Unable to add discount code.  EndDate must be after StartDate");

                        if (theEvent.EventDiscountCodes.Any(c => c.DiscountCode.Code.ToUpper(CultureInfo.InvariantCulture) == code.Code.ToUpper(CultureInfo.InvariantCulture)))
                            throw new BusinessException("Event discount codes must be unique");

                        discountCodes.AddObject(code);

                        var codeWithId = discountCodes.FirstOrDefault(d => d.Code == code.Code);
                        code.Id = codeWithId == null ? 0 : codeWithId.Id;
                    }
                    else
                    {
                        //If event discount code exists, update existing discount code
                        UpdateExistingCode(context, code, discount);
                    }
                }
                else
                {
                    //If org unit discount code exists, just attach existing org unit code to event.
                    //Org unit codes are not editable from the Event API.
                    var codeWithId = discountCodes.FirstOrDefault(d => d.Code == code.Code);
                    code.Id = codeWithId == null ? 0 : codeWithId.Id;
                }
                theEvent.EventDiscountCodes.Add(new EventDiscountCode
                {
                    Event = theEvent,
                    DiscountCode = code,
                    DiscountCodeId = code.Id,
                });
            }
        }
Exemplo n.º 21
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.º 22
0
        public static void SetOrgUnitTypes(ObjectContext context, OrgUnitV2 source, OrgUnit orgUnit)
        {
            //ignore null values
            if (source.OrgUnitTypes == null)
                return;

            try
            {
                var existingOrgUnitTypes = orgUnit.OrgUnitTypeAssociations.ToArray();
                foreach (var item in existingOrgUnitTypes)
                    context.DeleteObject(item);

                var orgUnitTypes = context.CreateObjectSet<OrgUnitType>();
                var orgUnitTypeAssociations = new List<OrgUnitTypeAssociation>();

                foreach (var item in source.OrgUnitTypes)
                {
                    //Ensure orgUnitTypes Exists
                    var orgUnitType = orgUnitTypes.FirstOrDefault(i => i.Name == item.Name);
                    if (orgUnitType == null)
                    {
                        orgUnitType = new OrgUnitType()
                        {
                            Name = item.Name,
                            ImageUrl = item.ImageUrl,
                            IsEnabled = true
                        };
                        orgUnitTypes.AddObject(orgUnitType);
                    }

                    orgUnitTypeAssociations.Add(new OrgUnitTypeAssociation
                    {
                        OrgUnitType = orgUnitType,
                        OrgUnit = orgUnit,
                        IsPrimaryOrgUnitType = item.IsPrimaryOrgUnitType
                    });
                }

                orgUnit.OrgUnitTypeAssociations = orgUnitTypeAssociations;
            }
            catch (Exception ex)
            {
                throw new BusinessException("Error processing orgUnitTypes for orgUnit '" + orgUnit.Name + "' - " + ex.Message, ex);
            }
        }
Exemplo n.º 23
0
        public static void SetOrgUnitAssociation(ObjectContext context, OrgUnitV2 source, OrgUnit orgUnit, bool isAddingOrgUnit)
        {
            var secondaryId = orgUnit.Id;
            int? primaryId = null;

            if (source.ParentInternalIdAsInt.HasValue)
            {
                primaryId = source.ParentInternalIdAsInt.Value;
            }
            else if (source.ParentExternalId != null)
            {
                var mappings = context.CreateObjectSet<DataImportEntityIdMap>()
                    .SingleOrDefault(m => m.ExternalId == source.ParentExternalId && m.EntityName == "OrgUnit");

                if (mappings == null)
                    throw new BusinessException(string.Format(CultureInfo.InvariantCulture, "OrgUnit with ParentExternalId of {0} not found", source.ParentExternalId));

                primaryId = mappings.InternalId;
            }

            if (source.ParentInternalId != null || source.ParentExternalId != null || isAddingOrgUnit)
            {
                var orgUnitsObjectContext = context.CreateObjectSet<OrgUnit>();
                var orgUnitAssociationsObjectContext = context.CreateObjectSet<OrgUnitAssociation>();

                // Validate primary/parent org unit
                if (primaryId > 0)
                {
                    var primaryOrgUnit = orgUnitsObjectContext.SingleOrDefault(o => o.Id == primaryId.Value);

                    if (primaryOrgUnit == null)
                    {
                        throw new BusinessException(string.Format(CultureInfo.InvariantCulture, "OrgUnit with ParentInternalId of {0} not found",
                            primaryId.Value.ToString(CultureInfo.InvariantCulture)));
                    }
                }
                else
                {
                    primaryId = null;
                }

                // Delete any existing association
                var oldAssocation = orgUnitAssociationsObjectContext.FirstOrDefault(a => a.SecondaryId == secondaryId);
                if (oldAssocation != null)
                {
                    context.DeleteObject(oldAssocation);
                }

                // Add new association
                var association = new OrgUnitAssociation()
                {
                    PrimaryId = primaryId,
                    OrgUnitSecondary = orgUnit,
                    IsEnabled = true
                };

                orgUnitAssociationsObjectContext.AddObject(association);
            }
        }
Exemplo n.º 24
0
 public void Remove(EntityObject entity)
 {
     _context.DeleteObject(entity);
 }
Exemplo n.º 25
0
        public static void SetProviderEducationTypes(ObjectContext context, ProviderV2 source, Provider provider)
        {
            if (source.EducationTypes == null)
                return;

            try
            {
                var existingEducationTypes = provider.ProviderEducations.ToArray();
                foreach (var item in existingEducationTypes)
                    context.DeleteObject(item);

                var educationTypes = context.CreateObjectSet<EducationType>();
                var providerEducations = new List<ProviderEducation>();

                foreach (var item in source.EducationTypes)
                {
                    //Ensure Education Type Exists
                    var education = educationTypes.FirstOrDefault(s => s.Name == item.EducationTypeName);
                    if (education == null)
                    {
                        education = new EducationType(item.EducationTypeName, true);
                        educationTypes.AddObject(education);
                    }

                    var addedEducation = new ProviderEducation(provider, education, item.InstitutionName);
                    addedEducation.SetYearCompleted(item.YearCompleted);

                    if (ConvertToBool(item.IsComplete, false, "Education/IsCompleted", provider.Name) || !string.IsNullOrEmpty(item.YearCompleted))
                        addedEducation.IsCompleted = true;

                    providerEducations.Add(addedEducation);
                }

                provider.ProviderEducations = providerEducations;
            }
            catch (Exception ex)
            {
                throw new BusinessException("Error processing educations for provider '" + provider.Name + "' - " + ex.Message, ex);
            }
        }
Exemplo n.º 26
0
        public static void SetOrgUnitServices(ObjectContext context, OrgUnitV2 source, OrgUnit orgUnit)
        {
            //ignore null values
            if (source.OrgUnitServices == null)
                return;

            try
            {
                var existingServices = orgUnit.OrgUnitServices.ToArray();
                foreach (var item in existingServices)
                    context.DeleteObject(item);

                var services = context.CreateObjectSet<Service>();
                var orgUnitServices = new List<OrgUnitService>();

                foreach (var item in source.OrgUnitServices)
                {
                    //Ensure service Exists
                    var service = services.FirstOrDefault(i => i.Name == item.Name);
                    if (service == null)
                    {
                        service = new Service()
                        {
                            Name = item.Name,
                            IsEnabled = true
                        };
                        services.AddObject(service);
                    }

                    orgUnitServices.Add(new OrgUnitService
                    {
                        Service = service,
                        OrgUnit = orgUnit
                    });
                }

                orgUnit.OrgUnitServices = orgUnitServices;
            }
            catch (Exception ex)
            {
                throw new BusinessException("Error processing services for orgUnit '" + orgUnit.Name + "' - " + ex.Message, ex);
            }
        }
Exemplo n.º 27
0
        public static void SetProviderLanguages(ObjectContext context, ProviderV2 source, Provider provider)
        {
            if (source.Languages == null)
                return;

            try
            {
                var existingLanguages = provider.ProviderLanguages.ToArray();
                foreach (var item in existingLanguages)
                    context.DeleteObject(item);

                var languages = context.CreateObjectSet<Language>();
                var providerLanguages = new List<ProviderLanguage>();

                foreach (var item in source.Languages)
                {
                    //Ensure Language Exists
                    var language = languages.FirstOrDefault(s => s.Name == item.LanguageName);
                    if (language == null)
                    {
                        language = new Language(true, 0, item.LanguageName, true);
                        languages.AddObject(language);
                    }

                    providerLanguages.Add(new ProviderLanguage(provider, language, ConvertToBool(item.IsPrimary, false, "Language/IsPrimary", provider.FullName))
                    {
                        IsFluent = ConvertToBool(item.IsFluent, false, "Language/IsFluent", provider.FullName)
                    });
                }

                provider.ProviderLanguages = providerLanguages;
            }
            catch (Exception ex)
            {
                throw new BusinessException("Error processing languages for provider '" + provider.Name + "' - " + ex.Message, ex);
            }
        }
Exemplo n.º 28
0
 /// <summary>
 /// Delete data from context
 /// </summary>
 /// <typeparam name="E"></typeparam>
 /// <param name="entity"></param>
 public void Delete(E entity)
 {
     _ctx.DeleteObject(entity);
 }