public static void DisplayAllCommodities() { Console.WriteLine("Extracting Commodities information.......\n\n", Color.CornflowerBlue); using var db = new BlobDbContext(); List <Commodity> CommodityCount = db.Commodities.ToList(); int CommodityCount1 = db.Commodities.Count(); Console.WriteLine("Total Number of Commodities found : {0}", CommodityCount1, Color.CornflowerBlue); if (CommodityCount?.Count > 20) { Console.WriteLine("Since commodities count is greater than 20 therefore do you want to send it over e-mail instead ? \n\nChoose : \n 1: yes\n 2: No", Color.CornflowerBlue); String userinput = Console.ReadLine(); if (userinput == "1") { var table = new ConsoleTable("ID", "CommodityCode", "CommodityName", "Unit", "EstimatedQuantity", "ActualQuantity"); foreach (var item in CommodityCount) { table.AddRow($"{item.ID}", $"{ item.CommodityCode}", $"{item.CommodityName}", $"{item.Unit}", $"{item.EstimatedQuantity}", $"{item.ActualQuantity}"); } var EmailInput = table; SendMail(EmailInput); } else { DisplayCommoditiesbyPage(); } } else { DisplayCommoditiesbyPage(); }
public static void DeleteCommodity() { DisplayAllCommodities(); BlobDbContext db = new BlobDbContext(); Commodity com = new Commodity(); Console.WriteLine("Please enter the Commodity ID that you want to delete : "); var input = Console.ReadLine(); Console.WriteLine(); if (Int32.TryParse(input, out int userInput)) { var rowcount = db.Commodities.Find(userInput); if (rowcount != null) { db.Commodities.Remove(rowcount); db.SaveChanges(); Console.WriteLine("Commodity successfully deleted. Returning to main menu..", Color.Green); } else { Console.WriteLine("Not a valid commodity ID, Hit enter to return to main menu", Color.Red); Console.ReadLine(); } } }
static void DisplayCommoditiesbyPage() { try { using var db = new BlobDbContext(); int skip = 0; Console.WriteLine("Please enter the number of records you want to display on one page : ", Color.Violet); var take = Int32.Parse(Console.ReadLine()); if (take == 0) { Console.WriteLine("Page length cannot be 0. Hit enter to return to main menu", Color.Red); Console.Read(); MainApplication(); } Console.WriteLine("Displaying all commodities as per input..", Color.Violet); List <Commodity> CommodityInfo = db.Commodities.Skip(skip).Take(take).ToList(); while (CommodityInfo?.Count > 0) { var table = new ConsoleTable("ID", "CommodityCode", "CommodityName", "Unit", "EstimatedQuantity", "ActualQuantity"); foreach (var item in CommodityInfo) { table.AddRow($"{item.ID}", $"{ item.CommodityCode}", $"{item.CommodityName}", $"{item.Unit}", $"{item.EstimatedQuantity}", $"{item.ActualQuantity}"); } table.Write(); Console.WriteLine("Press Enter to continue with the list of Commodities", Color.Yellow); Console.WriteLine("Type exit to return to Main Menu", Color.AntiqueWhite); String input = Console.ReadLine(); String Linput = input.ToLower(); if (Linput == "exit") { MainApplication(); } else { skip += CommodityInfo.Count; CommodityInfo = db.Commodities.Skip(skip).Take(take).ToList(); } } } catch (Exception ex) { Console.WriteLine("Page length cannot be blank. Hit enter to return to main menu.", Color.Red); Console.ReadLine(); MainApplication(); } }
public static void AddCommodity() { BlobDbContext db = new BlobDbContext(); Console.WriteLine("All fields are mandatory and cannot be blank\n"); Commodity com = new Commodity(); do { Console.WriteLine("Commodity Code: "); com.CommodityCode = Console.ReadLine(); }while (String.IsNullOrEmpty(com.CommodityCode)); do { Console.WriteLine("Commodity Name : "); com.CommodityName = Console.ReadLine(); }while (String.IsNullOrEmpty(com.CommodityName)); do { Console.WriteLine("Unit : "); com.Unit = Console.ReadLine(); }while (String.IsNullOrEmpty(com.Unit)); do { Console.WriteLine("Estimated Quantity : "); com.EstimatedQuantity = Console.ReadLine(); }while (String.IsNullOrEmpty(com.EstimatedQuantity)); do { Console.WriteLine("Actual Quantity : "); com.ActualQuantity = Console.ReadLine(); }while (String.IsNullOrEmpty(com.ActualQuantity)); db.Commodities.Add(com); db.SaveChanges(); Console.WriteLine("\nCommodity added successfully. Hit enter to return to main menu", Color.Green); Console.ReadLine(); }