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(); } } }
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(); }