Ejemplo n.º 1
0
        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");
            }
        }
Ejemplo n.º 2
0
        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");
            }
        }
Ejemplo n.º 3
0
        static void ViewAuthor()
        {
            using (var context = new BookDatabaseEntities())
            {
                var query = (from au in context.Authors
                             select au);
                Console.WriteLine($"{"AuthorID",-10} {"FirstName",-16} {"LastName",-18} {"PhoneNo",-13}  {"Address ",-20} {"City",-12} {"State",8}");

                foreach (var au in query)
                {
                    Console.WriteLine("----------------------------------------------------------------------------------------------------------------------");
                    Console.WriteLine($"{au.AuthorID,-12}{au.FirstName,-17}{au.LastName,-17 }{au.Phone,-15}{au.Address,-22}{au.City,-17 }{au.State,-3}");
                }
                Console.ReadKey();
            }
        }