private void ReadAllAssetsFromDB() { if (_db.Assets.Count() <= 0) { WriterExtensions.WriteInGreen("Welcome to ATS, your new Asset Tracking System".ToUpper()); WriterExtensions.WriteInYellow("Press 'C' to Create and Add an asset to your ATS!"); } else { Console.Clear(); PrintHeaderWithId(); // MotorCompany comp = _db.Companies.Where(comp => comp.Name.Contains("Lenny")).Include(comp => comp.Cars).FirstOrDefault(); assetsList = _db.Assets.Where(asset => asset.Id != null).Include(asset => asset.Office).ToList(); //Office off = new Office(assetsList[0].Office); // //Data is now IN Memory //DB Sorting by Category Thenby PurchaseDate //Asset assTest = _db.Assets.Find(1); assetsList = (List <Asset>)assetsList.OrderBy(a => a.Category).ThenByDescending(b => b.PurchaseDate).ToList(); foreach (Asset assetItem in assetsList) { //If purchaseDate older then 33 months from today's DateTime, WriteLine in RED else WriteLine normal. if ((DateTime.Now > assetItem.PurchaseDate.AddMonths(33))) { WriterExtensions.WriteInRed(Tab(assetItem.Id.ToString()) + Tab(assetItem.Category) + Tab(assetItem.BrandAndModel) + Tab(Convert.ToDateTime(assetItem.PurchaseDate).ToShortDateString()) + Tab((assetItem.Office.Name).ToString()) + Tab(assetItem.PurchasePrice.ToString())); } else { Console.WriteLine(Tab(assetItem.Id.ToString()) + Tab(assetItem.Category) + Tab(assetItem.BrandAndModel) + Tab(Convert.ToDateTime(assetItem.PurchaseDate).ToShortDateString()) + Tab((assetItem.Office.Name).ToString()) + Tab(assetItem.PurchasePrice.ToString())); } } } }
private void MainMenu() { ReadAllAssetsFromDB(); Console.WriteLine(""); WriterExtensions.WriteInGreen("Main Menu".ToUpper()); WriterExtensions.WriteInYellow("C) Create an asset"); WriterExtensions.WriteInYellow("R) Read DB & Go to Main Menu"); WriterExtensions.WriteInYellow("U) Update an asset"); WriterExtensions.WriteInYellow("D) Delete an asset"); Console.WriteLine(""); WriterExtensions.WriteInRed("X) Exit Application"); Console.WriteLine(""); ConsoleKey command = Console.ReadKey(true).Key; if (command == ConsoleKey.C) { CreateAssets(); } if (command == ConsoleKey.U) { UpdateAssets(); } if (command == ConsoleKey.R) { MainMenu(); } if (command == ConsoleKey.D) { DeleteAssets(); } if (command == ConsoleKey.X) { ExitApplication(); } }