/// <summary> /// Adds a given author to the database, if there isn't a person entry already it will be created. /// </summary> /// <param name="author"></param> public void AddAuthorToDatabase(AuthorBLL author) { using (LibraryDBEntities context = new LibraryDBEntities()) { Person person = (from p in context.People where p.PersonID == author.ID select p).FirstOrDefault(); if (person == null) { person = new Person() { PersonID = author.ID, FirstName = author.FirstName, LastName = author.LastName }; context.People.Add(person); } Author newAuthor = new Author() { ID = author.ID, Bio = author.Bio }; context.Authors.Add(newAuthor); context.SaveChanges(); } PopulatePeople(); }
/// <summary> /// Finishes the authorBLL creation. /// </summary> public void CreateAuthor() { Author = new AuthorBLL() { FirstName = firstName, LastName = lastName, Bio = bio, ID = iD }; }
public AuthorBuilder(PersonBLLCollection People, string FirstName, string LastName) { people = People; firstName = FirstName; lastName = LastName; //This is just for UI purposes during author creation Author = new AuthorBLL() { FirstName = firstName, LastName = lastName }; }
/// <summary> /// Creates a list of business logic layer objects from the database tables /// </summary> public void PopulatePeople() { using (LibraryDBEntities context = new LibraryDBEntities()) { List <PersonBLL> newPeople = new List <PersonBLL>(); //Add the librarians LibrarianBLL librarian = null; foreach (Librarian l in context.Librarians) { librarian = new LibrarianBLL() { ID = l.Person.PersonID, FirstName = l.Person.FirstName, LastName = l.Person.LastName, Phone = l.Phone, UserID = l.UserID, Password = l.Password }; newPeople.Add(librarian); } //Add the authors AuthorBLL author = null; foreach (Author a in context.Authors) { author = new AuthorBLL() { ID = a.Person.PersonID, FirstName = a.Person.FirstName, LastName = a.Person.LastName, Bio = a.Bio }; newPeople.Add(author); } //Add cardholders CardholderBLL cardholder = null; foreach (Cardholder c in context.Cardholders) { cardholder = new CardholderBLL() { ID = c.Person.PersonID, FirstName = c.Person.FirstName, LastName = c.Person.LastName, Phone = c.Phone, LibraryCardID = c.LibraryCardID }; newPeople.Add(cardholder); } people = newPeople; } Sort(); }
/// <summary> /// Finds the Person objects and populates the fields. /// </summary> void FindAuthor() { FoundPersons = (from p in people where p.FirstName == FirstName && p.LastName == LastName select p).ToList(); if (FoundPersons.Count > 0) { foreach (PersonBLL p in FoundPersons) { if (p is AuthorBLL a) { //If an author is found then the Author property will hold a reference to them. Author = a; break; } } } }