public int UpdateMHS(int input) { System.Console.Write("MASUKKAN NAMA BARU : "); string Nama = System.Console.ReadLine(); System.Console.Write("MASUKKAN ALAMAT BARU : "); string Alamat = System.Console.ReadLine(); System.Console.Write("MASUKKAN EMAIL BARU : "); string Email = System.Console.ReadLine(); System.Console.Write("MASUKKAN ULANG ID : "); string id_mhs = System.Console.ReadLine(); var getmhs = mhs_context.MAHASISWAs.Find(Convert.ToInt16(id_mhs)); if (getmhs == null) { System.Console.Write("TIDAK ADA ID MAHASISWA : " + id_mhs); } else { MAHASISWA mahasiswa = GetById(input); mahasiswa.NAME = Nama; mahasiswa.ADDRESS = Alamat; mahasiswa.EMAIL = Email; mhs_context.Entry(mahasiswa).State = System.Data.Entity.EntityState.Modified; mhs_context.SaveChanges(); } return(input); }
// =========================================== INSERT ============================================= public void InsertMHS() { Console.Clear(); System.Console.Write("Nama Mahasiswa : "); string Nama_Mahasiswa = System.Console.ReadLine(); System.Console.Write("Alamat Mahasiswa : "); string Alamat_Mahasiswa = System.Console.ReadLine(); System.Console.Write("Email : "); string email = System.Console.ReadLine(); MAHASISWA call = new MAHASISWA(); { call.NAME = Nama_Mahasiswa; call.ADDRESS = Alamat_Mahasiswa; call.EMAIL = email; }; try { mhs_context.MAHASISWAs.Add(call); var result = mhs_context.SaveChanges(); } catch (Exception ex) { System.Console.Write(ex.InnerException); } }