コード例 #1
0
        /// <summary>
        ///     Adds a new relation to the person.
        /// </summary>
        /// <param name="p">Person</param>
        /// <param name="division">Stb division.</param>
        /// <param name="comment">Comment</param>
        private void AddStbRelationToPerson(Person p, StbDivision division, string comment, RelationType type)
        {
            Relation r = new Relation();

            r.SubjectiveEntity = division;
            r.RelationType     = type;
            r.ObjectiveEntity  = p;
            r.Note             = comment;

            _ctx.Relations.Add(r);
        }
コード例 #2
0
        /// <summary>
        ///     Gets a StbDivision named @name or creates one if it doesn't exist. May return null if @name is empty or null.
        /// </summary>
        /// <param name="name">Name of the Stb division.</param>
        /// <returns>StbDivision</returns>
        private StbDivision GetStbDivisionByName(string name)
        {
            if (name == null || name.Equals(""))
            {
                return(null);
            }

            IQueryable <StbDivision> divisions         = _ctx.Entities.OfType <StbDivision> ();
            IQueryable <StbDivision> selectedDivisions = divisions.Where(p => p.Name.Equals(name));

            if (selectedDivisions.Count() == 0)
            {
                // Center not found, create one
                StbDivision division = new StbDivision();
                division.Name = name;
                _ctx.Entities.Add(division);
                _ctx.SaveChanges();
                return(division);
            }

            return(selectedDivisions.First());
        }
コード例 #3
0
        /// <summary>
        ///     Parses the XML node and imports it.
        /// </summary>
        /// <param name="rowNode">The node.</param>
        protected void ProcessRow(XmlNode rowNode)
        {
            XmlNodeList cells = rowNode.ChildNodes;

            if (cells.Count != kNumberOfColumns)
            {
                Console.WriteLine("ERROR: Wrong number of columns in row {0}", rowNode.ToString());
                return;
            }


            //------------ Add to DB
            string lastName  = cells[kLastNameColumnIndex].InnerText;
            string firstName = cells[kFirstNameColumnIndex].InnerText;

            if (firstName == null || firstName.Equals(""))
            {
                firstName = "Nezname";
            }

            string birthYear = cells[kBirthYearColumnIndex].InnerText;

            string birthPlace = cells[kBirthPlaceColumnIndex].InnerText;

            string[] countryStrings = new string[2];
            countryStrings[0] = cells[kStateFirstColumnIndex].InnerText;
            countryStrings[1] = cells[kStateSecondColumnIndex].InnerText;
            List <Country> countries = ConvertStringCountriesToCountryArray(countryStrings);

            string dbAdditionYear = cells[kAddedToDatabaseYearColumnIndex].InnerText;

            string sexValue = cells[kSexColumnIndex].InnerText;
            Sex    sex      = Sex.Male;

            if (sexValue != null)
            {
                sex = sexValue.Equals(kMaleSexIdentifier) ? Sex.Male : Sex.Female;
            }
            string department            = cells[kDepartmentColumnIndex].InnerText;
            string departmentComment     = cells[kDepartmentCommentColumnIndex].InnerText;
            string administration        = cells[kAdministrationColumnIndex].InnerText;
            string administrationComment = cells[kAdministrationCommentColumnIndex].InnerText;
            string pozorka1 = cells[kPozorkaFirstColumnIndex].InnerText;
            string pozorka2 = cells[kPozorkaSecondColumnIndex].InnerText;



            Person p = TryToFindPerson(firstName, lastName, birthYear, sex, birthPlace);

            if (p == null)
            {
                // Need to create a new person
                p           = new Person();
                p.FirstName = firstName;
                p.Surname   = lastName;
                if (birthYear != null && !birthYear.Equals(""))
                {
                    p.BirthDate = birthYear;
                }
                p.Sex         = sex;
                p.Nationality = Nationality.Unknown;
                p.Note        = string.Format("{0} {1}\n{2} {3}\n{4} {5}\n{6} {7}",
                                              kPlaceOfBirthNoteCaption, birthPlace,
                                              kPozorka1NoteCaption, pozorka1,
                                              kPozorka2NoteCaption, pozorka2,
                                              kAddedToStbDatabaseNoteCaption, dbAdditionYear);

                if (countries.Count > 0)
                {
                    p.Citizenships = countries;
                }

                _ctx.Entities.Add(p);
            }

            StbDivision StbDepartment     = GetStbDivisionByName(department);
            StbDivision StbAdministration = GetStbDivisionByName(administration);

            Relation departmentRelation     = null;
            Relation administrationRelation = null;

            ICollection <Relation> relations = p.ObjectiveRelations;

            if (relations != null)
            {
                foreach (Relation r in relations)
                {
                    if (StbDepartment != null && r.SubjectiveEntityId == StbDepartment.Id)
                    {
                        departmentRelation = r;
                    }
                    else if (StbAdministration != null && r.SubjectiveEntityId == StbAdministration.Id)
                    {
                        administrationRelation = r;
                    }
                }
            }

            if (departmentRelation == null && StbDepartment != null)
            {
                // Need to add a relation
                AddStbRelationToPerson(p, StbDepartment, departmentComment, GetRelationType(kRelationDepartmentType));
            }
            if (administrationRelation == null && StbAdministration != null)
            {
                // Need to add a relation
                AddStbRelationToPerson(p, StbAdministration, administrationComment, GetRelationType(kRelationAdministrativeType));
            }

            _ctx.SaveChanges();
        }