void AddAuthorToDatabase(IAuthorBuilderable builder) { if (builder.AuthorBuilder.IsNewPerson)//A new person needs to be added, too { using (LibraryDBEntities context = new LibraryDBEntities()) { Person newPerson = new Person() { FirstName = builder.AuthorBuilder.Author.FirstName, LastName = builder.AuthorBuilder.Author.LastName }; context.People.Add(newPerson); context.SaveChanges(); } //Get the id of the new person using (LibraryDBEntities context = new LibraryDBEntities()) { Person person = (from p in context.People where p.FirstName == builder.AuthorBuilder.Author.FirstName && p.LastName == builder.AuthorBuilder.Author.LastName select p).FirstOrDefault(); builder.AuthorBuilder.SetID(person.PersonID); builder.Book.AuthorID = person.PersonID; } } //Now a new author can be added using (LibraryDBEntities context = new LibraryDBEntities()) { builder.AuthorBuilder.CreateAuthor(); Author newAuthor = new Author() { ID = builder.AuthorBuilder.Author.ID, Bio = builder.AuthorBuilder.Author.Bio }; context.Authors.Add(newAuthor); context.SaveChanges(); } //Now the authorBLL is ready to be added to the collection builder.AuthorBuilder.AddAuthorToCollection(); }
public RequestAuthorBio(IAuthorBuilderable Builder) { InitializeComponent(); builder = Builder; }