public int Save(Mahasiswa obj) { var result = 0; // cek nilai npm yang diinputkan tidak boleh kosong if (string.IsNullOrEmpty(obj.npm)) { MessageBox.Show("NPM harus diisi !!!", "Peringatan", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return(0); } // cek nilai nama yang diinputkan tidak boleh kosong if (string.IsNullOrEmpty(obj.nama)) { MessageBox.Show("Nama harus diisi !!!", "Peringatan", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return(0); } // membuat objek context menggunakan blok using using (var context = new DbContext()) { // membuat objek dari class repository _repository = new MahasiswaRepository(context); // panggil method Save yang ada di dalam class repository result = _repository.Save(obj); } if (result > 0) { MessageBox.Show("Data mahasiswa berhasil disimpan !", "Informasi", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("Data mahasiswa gagal disimpan !!!", "Peringatan", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } return(result); }
public int Save(Mahasiswa obj) { var result = 0; if (string.IsNullOrEmpty(obj.npm)) { MessageBox.Show("NPM harus Diisi !!!"); return(0); } if (string.IsNullOrEmpty(obj.nama)) { MessageBox.Show("Nama harus Diisi !!!"); return(0); } using (var context = new DbContext()) { _repository = new MahasiswaRepository(context); result = _repository.Save(obj); } return(result); }