static void UpdateAuthor() { int authorID; string newfirstName, newlastName, newphoneNo, newAddress, newCity, newState; try { using (var context = new BookDatabaseEntities()) { Console.WriteLine("Enter author id to change auhtor detail:"); authorID = Int32.Parse(Console.ReadLine()); var au = context.Authors.Find(authorID); Console.WriteLine("Enter new author first name:"); newfirstName = Console.ReadLine(); Console.WriteLine("Enter new author last name:"); newlastName = Console.ReadLine(); Console.WriteLine("Enter new author phone number:"); newphoneNo = Console.ReadLine(); Console.WriteLine("Enter new author address:"); newAddress = Console.ReadLine(); Console.WriteLine("Enter new author city:"); newCity = Console.ReadLine(); Console.WriteLine("Enter new author state:"); newState = Console.ReadLine(); au.FirstName = newfirstName; au.LastName = newlastName; au.Phone = newphoneNo; au.Address = newAddress; au.City = newCity; au.State = newState; context.SaveChanges(); Console.WriteLine("Author detail Successfully updated"); Console.WriteLine(""); ViewAuthor(); Console.ReadKey(); } } catch (Exception exception) { Console.WriteLine( $"Unexpected error: { exception.Message }"); Console.ReadKey(); } finally { Console.WriteLine("goodbye"); } }
static void AddAuthor() { string firstName, lastName, phoneNo, address, city, state; try { using (var context = new BookDatabaseEntities()) { Console.WriteLine("Enter author first name:"); firstName = Console.ReadLine(); Console.WriteLine("Enter author last name:"); lastName = Console.ReadLine(); Console.WriteLine("Enter author phone number:"); phoneNo = Console.ReadLine(); Console.WriteLine("Enter author address:"); address = Console.ReadLine(); Console.WriteLine("Enter author city"); city = Console.ReadLine(); Console.WriteLine("Enter auhtor state"); state = Console.ReadLine(); var au = new Author(); au.FirstName = firstName; au.LastName = lastName; au.Phone = phoneNo; au.Address = address; au.City = city; au.State = state; context.Authors.Add(au); context.SaveChanges(); Console.WriteLine("Author Detial Successfully Added"); Console.WriteLine(""); ViewAuthor(); Console.ReadKey(); } } catch (Exception exception) { Console.WriteLine( $"Unexpected error: { exception.Message }"); Console.ReadKey(); } finally { Console.WriteLine("goodbye"); } }