static void Main(string[] args) { using (var db = new RabbitDbEntities()) { rabbits = db.Rabbits.ToList(); } Console.WriteLine($"ID Name AGE"); PrintRabbits(); // print each rabbit in tabular form // EXPRESSION TO PRINT OUT RABBIT DATA //rabbits.ForEach(rabbit/*names ourselves the variable*/ => //Console.WriteLine($"{rabbit.RabbitId,-5}" + $"{rabbit.Name,-12} {rabbit.AGE}")); // // "Proper" longer way to write it out //foreach (var rabbit in rabbits) //{ // Console.WriteLine(($"{rabbit.RabbitId,-5}" + $"{rabbit.Name,-12} {rabbit.AGE}")); //} //new Rabbit : WPF Textbox01.text ==> use for Agem Name (2 boxes) // buttonAdd : run this code var newRabbit = new Rabbit() { AGE = 0, Name = $"Rabbit{rabbits.Count + 1}" }; using (var db = new RabbitDbEntities()) { db.Rabbits.Add(newRabbit); db.SaveChanges(); } System.Threading.Thread.Sleep(200); Console.WriteLine("\n====This is db after making rabbits===\n"); // read db from stratch using (var db = new RabbitDbEntities()) { rabbits = db.Rabbits.ToList(); PrintRabbits(); //rabbits.ForEach(rabbit => Console.WriteLine($"{rabbit.RabbitId,-5}" + //$"{rabbit.Name,-12} {rabbit.AGE}")); } Console.ReadLine(); }
static void createNewRabbit() { List <Rabbit> r = updateRabbitList(); var newRabbit = new Rabbit() { Age = 0, Name = $"Rabbit{r.Count + 1}" }; using (var db = new RabbitDbEntities()) { db.Rabbits.Add(newRabbit); db.SaveChanges(); } }
static void Main(string[] args) { void printRabbits() { rabbits.ForEach(rabbit => Console.WriteLine($"{rabbit.RabbitID,-5}" + $"{rabbit.Name,-12}{rabbit.Age}")); } using (var db = new RabbitDbEntities()) { rabbits = db.Rabbits.ToList(); } //print rabbits printRabbits(); //foreach(var rabbit in rabbits) //{ // Console.WriteLine($"{rabbit.RabbitID,-5}{rabbit.Name,-12}{rabbit.Age}"); //} //new rabbt : wpf Textbox01.tect ==> use for Age, Name (2boxes) // button : run this code var newRabbit = new Rabbit() { Age = 0, Name = $"Rabbit{rabbits.Count+1}" }; using (var db = new RabbitDbEntities()) { db.Rabbits.Add(newRabbit); db.SaveChanges(); } //pause to ensure database has finished writing System.Threading.Thread.Sleep(200); Console.ReadLine(); //read db from scratch using (var db = new RabbitDbEntities()) { printRabbits(); } Console.ReadKey(); }
static void Main(string[] args) { DisplayRabbits(); //new rabbit : WPF Textbox01.text ==> use for Age, Name (2 boxes) //button Add : run this code var newRabbit = new Rabbit() { Age = 0, Name = $"Rabbit{rabbits.Count + 1}" }; using (var db = new RabbitDbEntities()) { db.Rabbits.Add(newRabbit); db.SaveChanges(); } System.Threading.Thread.Sleep(200); DisplayRabbits(); }
static void Main(string[] args) { using (var db = new RabbitDbEntities()) { rabbits = db.Rabbits.ToList(); } PrintRabbits(); //foreach(var rabbit in rabbits) //{ // Console.WriteLine($"{rabbit.RabbitId,-5}{rabbit.Name,-12}{rabbit.Age}"); //} // new rabbit : WPF Textbox01.text ==> use for Age, Name (2 boxes) // buttonAdd : run this code var newRabbit = new Rabbit() { Age = 0, Name = $"Rabbit{rabbits.Count+2}" }; using (var db = new RabbitDbEntities()) { db.Rabbits.Add(newRabbit); db.SaveChanges(); } // pause to ensure database has finished writing System.Threading.Thread.Sleep(200); // read db from scratch Console.WriteLine("\n\nAfter adding a rabbit, re-read database"); using (var db = new RabbitDbEntities()) { rabbits = db.Rabbits.ToList(); PrintRabbits(); } }