Example #1
0
        /// <summary>
        /// Maps CPR Numbers to UUIDs
        /// </summary>
        /// <param name="cprNumbers"></param>
        /// <returns></returns>
        public static Guid?[] AssignGuids(params string[] cprNumbers)
        {
            Guid?[] ret = new Guid?[cprNumbers.Length];

            using (PartDataContext dataContext = new PartDataContext())
            {
                var foundPersons = dataContext.PersonMappings.AsQueryable();

                foundPersons = foundPersons.Where(p => cprNumbers.Contains(p.CprNumber));

                var foundPersonsArray = foundPersons.ToArray();

                for (int iPerson = 0; iPerson < cprNumbers.Length; iPerson++)
                {
                    var cprNumber     = cprNumbers[iPerson];
                    var personMapping = (from d in foundPersonsArray where d.CprNumber == cprNumber select d).FirstOrDefault();

                    if (personMapping != null)
                    {
                        ret[iPerson] = personMapping.UUID;
                    }
                }
            }
            return(ret);
        }
        public static IEnumerable <PersonRegistrationKey> GetByCriteria(PartDataContext dataContext, SoegObjektType soegObject, params Guid[] personRegistrationIds)
        {
            var elements = PersonRegistration.CreateXQueryElements(soegObject);

            if (personRegistrationIds != null)
            {
                if (personRegistrationIds.Length == 0)
                {
                    return(new PersonRegistrationKey[0]);
                }
                else
                {
                    elements.Add(
                        new InWhereCondition()
                    {
                        ColumnName = "PersonRegistrationId",
                        Values     = personRegistrationIds.Select(
                            id => id.ToString()
                            ).ToArray()
                    });
                }
            }
            var byCriteria = WhereCondition.GetMatchingObjects <PersonRegistrationKey>(dataContext, elements, "PersonRegistration", new string[] { "PersonRegistrationId", "UUID" });

            return(byCriteria);
        }
Example #3
0
        public static void SetChildLoadOptions(PartDataContext dataContext)
        {
            // Do Nothing, because setting load options slows down the loading
            return;

            /*
             * DataLoadOptions loadOptions = new DataLoadOptions();
             * SetChildLoadOptions(loadOptions);
             * dataContext.LoadOptions = loadOptions;
             */
        }
Example #4
0
        public static IEnumerable <Guid> GetUuidsByCriteria(PartDataContext dataContext, SoegObjektType soegObject, int startIndex, int maxCount)
        {
            var elements = PersonRegistration.CreateXQueryElements(soegObject);

#if Mono
            var byCriteriaStr = WhereCondition.GetMatchingObjects <object>(dataContext, elements, "PersonRegistration", true, new string[] { "UUID" }, startIndex, maxCount, "UUID");
            var byCriteria    = byCriteriaStr.Select(o => new Guid(o.ToString()));
#else
            var byCriteria = WhereCondition.GetMatchingObjects <Guid>(dataContext, elements, "PersonRegistration", true, new string[] { "UUID" }, startIndex, maxCount, "UUID");
#endif

            return(byCriteria);
        }
Example #5
0
        /// <summary>
        /// Maps a person UUID to a PersonIdentifier object.
        /// Returns null if no match is found.
        /// </summary>
        /// <param name="uuid"></param>
        /// <returns></returns>
        public static PersonIdentifier GetPersonIdentifier(Guid uuid)
        {
            PersonIdentifier ret = null;

            using (var dataContext = new PartDataContext())
            {
                ret =
                    (
                        from pm in dataContext.PersonMappings
                        where pm.UUID == uuid
                        select new PersonIdentifier()
                {
                    CprNumber = pm.CprNumber,
                    UUID = uuid
                }
                    ).FirstOrDefault();
            }
            return(ret);
        }
Example #6
0
        public static PersonIdentifier[] GetPersonIdentifiers(Guid[] uuidArray)
        {
            using (var dataContext = new PartDataContext())
            {
                var dbIdentifiers =
                    (
                        from pm in dataContext.PersonMappings
                        where uuidArray.Contains(pm.UUID)
                        select new PersonIdentifier()
                {
                    CprNumber = pm.CprNumber,
                    UUID = pm.UUID
                }
                    ).ToArray();

                return(uuidArray
                       .Select(uuid => dbIdentifiers.Where(db => db.UUID == uuid).FirstOrDefault())
                       .ToArray());
            }
        }
Example #7
0
        public static Expression <Func <PersonRegistration, bool> > CreateWhereExpression(PartDataContext dataContext, CprBroker.Schemas.Part.SoegInputType1 searchCriteria)
        {
            var pred = PredicateBuilder.True <Data.Part.PersonRegistration>();

            if (searchCriteria.SoegObjekt != null)
            {
                if (!string.IsNullOrEmpty(searchCriteria.SoegObjekt.UUID))
                {
                    var personUuid = new Guid(searchCriteria.SoegObjekt.UUID);
                    pred = pred.And(p => p.UUID == personUuid);
                }
                // Search by cpr number
                if (!string.IsNullOrEmpty(searchCriteria.SoegObjekt.BrugervendtNoegleTekst))
                {
                    pred = pred.And(pr => pr.Person.UserInterfaceKeyText == searchCriteria.SoegObjekt.BrugervendtNoegleTekst);
                }
                if (searchCriteria.SoegObjekt.SoegAttributListe != null)
                {
                    if (searchCriteria.SoegObjekt.SoegAttributListe.SoegEgenskab != null)
                    {
                        foreach (var prop in searchCriteria.SoegObjekt.SoegAttributListe.SoegEgenskab)
                        {
                            if (prop != null && prop.NavnStruktur != null)
                            {
                                if (prop.NavnStruktur.PersonNameStructure != null)
                                {
                                    // Search by name
                                    var name = prop.NavnStruktur.PersonNameStructure;
                                    if (!name.IsEmpty)
                                    {
                                        // TODO: Test name lookup after new struture (multiple attribuutes)

                                        /*
                                         * var cprNamePred = PredicateBuilder.True<Data.Part.PersonRegistration>();
                                         * if (!string.IsNullOrEmpty(name.PersonGivenName))
                                         * {
                                         *  cprNamePred = cprNamePred.And((pt) => pt.PersonAttributes.Where(attr => attr.PersonProperties != null && attr.PersonProperties.PersonName.FirstName == name.PersonGivenName).FirstOrDefault() != null);
                                         * }
                                         * if (!string.IsNullOrEmpty(name.PersonMiddleName))
                                         * {
                                         *  cprNamePred = cprNamePred.And((pt) => pt.PersonAttributes.Where(attr => attr.PersonProperties != null && attr.PersonProperties.PersonName.MiddleName == name.PersonMiddleName).FirstOrDefault() != null);
                                         * }
                                         * if (!string.IsNullOrEmpty(name.PersonSurnameName))
                                         * {
                                         *  cprNamePred = cprNamePred.And((pt) => pt.PersonAttributes.Where(attr => attr.PersonProperties != null && attr.PersonProperties.PersonName.LastName == name.PersonSurnameName).FirstOrDefault() != null);
                                         * }
                                         * pred = pred.And(cprNamePred);
                                         */
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return(pred);
        }