コード例 #1
0
        public void UpdateAuthorID(string firstName, string lastName)
        {
            //First, retirve the names of the author already associated with the book

            if (firstName != FirstName || lastName != LastName)
            {
                //The author entered is different from the current author
                //Find the ID of the new author
                AuthorSearch search = new AuthorSearch(people, firstName, lastName);
                if (search.Author == null)
                {
                    AuthorBuilder = new AuthorBuilder(people, firstName, lastName);
                    if (search.FoundPersons.Count == 0)
                    {
                        //This is an entirely new person
                        AuthorBuilder.IsNewPerson = true;
                    }
                    else
                    {
                        //This person is already in the database, but not as an author yet.
                        AuthorBuilder.IsNewAuthor = true;
                        AuthorID = search.FoundPersons[0].ID;
                        AuthorBuilder.SetID(AuthorID);
                    }
                }
                else
                {
                    AuthorID = search.Author.ID;
                }
                ChangeAuthorID = true;
            }
        }
コード例 #2
0
        /// <summary>
        /// Checks the given names, if the author exists the ID will be retrived now, or a new author will be created.
        /// </summary>
        /// <param name="FirstName"></param>
        /// <param name="LastName"></param>
        public void CheckNames(string FirstName, string LastName)
        {
            authorFirstName = FirstName;
            authorLastName  = LastName;
            List <PersonBLL> personBLLs = (from p in people
                                           where p.FirstName == authorFirstName && p.LastName == authorLastName
                                           select p).ToList();

            if (personBLLs.Count == 0)
            {
                //There is no one in the collection with this name, this is an entirely new person
                AuthorBuilder             = new AuthorBuilder(people, authorFirstName, authorLastName);
                AuthorBuilder.IsNewPerson = true;
            }
            else
            {
                bool authorFound = false;
                //There is someone with this name combination, check if they are already an author
                foreach (PersonBLL p in personBLLs)
                {
                    if (p is AuthorBLL a)
                    {
                        //An author with this name was found.
                        authorFound   = true;
                        authorID      = p.ID;
                        Book.AuthorID = p.ID;
                    }
                }
                if (!authorFound)
                {
                    AuthorBuilder             = new AuthorBuilder(people, authorFirstName, authorLastName);
                    AuthorBuilder.IsNewAuthor = true;
                    authorID      = personBLLs[0].ID;
                    Book.AuthorID = authorID;
                    AuthorBuilder.SetID(authorID);
                }
            }
        }