public static void Add(string obj) { using ReScContext context = new ReScContext(); string opt = "1"; while (opt != "0") { Show(obj); Console.Write("Nama " + obj + " / 0 untuk kembali\t: "); opt = Console.ReadLine(); if (opt != "0") { if (obj == "Tugas") { Console.Write("Durasi " + obj + " (Hari) \t\t: "); int b = Convert.ToInt32(Console.ReadLine()); context.listTugas.Add(new Tugas() { Nama = opt, Durasi = b, Deadline = Tugas.GetDead(b), userId = User.getId() }); } else if (obj == "User") { context.Users.Add(new User { Id = 0, Nama = opt }); } context.SaveChanges(); } } }
public static void Delete(string obj) { using ReScContext context = new ReScContext(); string opt = "1"; while (opt != "0") { Show(obj); Console.Write("Pilih Id " + obj + " yang ingin dihapus / 0 untuk kembali: "); opt = Console.ReadLine(); int ops = Convert.ToInt32(opt); if (opt != "0") { bool x = false; if (obj == "Tugas") { Tugas newTu = new Tugas(); foreach (Tugas tugas in context.listTugas) { if (tugas.Id == ops) { newTu = tugas; x = true; break; } } if (!x) { Shows.delay("Id " + ops + " tidak ditemukan!"); Delete(obj); } context.listTugas.Remove(newTu); } else if (obj == "User") { User newUs = new User(); foreach (User user in context.Users) { if (user.Id == ops) { newUs = user; x = true; break; } } if (!x) { Shows.delay("Id " + ops + " tidak ditemukan!"); Delete(obj); } foreach (Tugas tugas in context.listTugas) { if (tugas.userId == ops) { context.listTugas.Remove(tugas); } } context.Users.Remove(newUs); } context.SaveChanges(); Show(obj); } } }