private static void Delete() { try { using (AcademyContext db = new AcademyContext()) { Read("delete"); int id = -1; bool t = true; while (t) { Console.Write("ID: "); if (int.TryParse(Console.ReadLine(), out id)) { var item = db.Item.Find(id); if (item != null) { db.Item.Remove(item); if (db.SaveChanges() > 0) { Successful("Successfully removed"); } else { Error("Error : something went wrong"); } } break; } } } } catch (Exception ex) { Error($"Error: {ex.Message}"); } finally { PressAnyKey(); } }
private static void Update() { try { using (AcademyContext db = new AcademyContext()) { Read("update"); Console.Write("Item Id: "); int id = int.Parse(Console.ReadLine()); var item = db.Item.Find(id); if (item != null) { Console.Write("Item Price: "); var price = Console.ReadLine().Trim(); item.Price = price; if (db.SaveChanges() > 0) { Successful("Successfully updated"); } else { Error("Error : something went wrong"); } } } } catch (Exception ex) { Error($"Error: {ex.Message}"); } finally { PressAnyKey(); } }