public IActionResult KelolaDataAkademikTerakhir(KelolaDataAkademikTerakhir model) { if (!ModelState.IsValid) { TempData["Pesan"] = "Data tidak valid"; return(RedirectToAction(nameof(KelolaDataAkademikTerakhir))); } else { string noPendaftaran = User.Identity.Name; var newData = new AkademikTerakhir() { AlamatSekolah = model.AlamatSekolah, JenisSekolah = model.JenisSekolah, NamaSekolah = model.NamaSekolah, NoPesertaUn = model.NoPesertaUn, NoSeriIjazah = model.NoSeriIjazah, NoSeriSkhun = model.NoSeriSkhun, StatusSekolah = model.StatusSekolah }; _calonSiswaService.SaveDataAkademikTerakhir(noPendaftaran, newData); TempData["Pesan"] = "Data berhasil disimpan"; return(RedirectToAction(nameof(Biodata))); } }
public void SaveDataAkademikTerakhir(string noPendaftaran, AkademikTerakhir newData) { newData.CalonSiswaId = GetCalonSiswaId(noPendaftaran); bool isExist = CekExist(newData.CalonSiswaId, "AkademikTerakhir"); string sqlQuery; if (!isExist) { sqlQuery = @"INSERT INTO AkademikTerakhir(CalonSiswaId, NamaSekolah, JenisSekolah, StatusSekolah, AlamatSekolah, NoPesertaUn, NoSeriSkhun, NoSeriIjazah) VALUES(@CalonSiswaId, @NamaSekolah, @JenisSekolah, @StatusSekolah, @AlamatSekolah, @NoPesertaUn, @NoSeriSkhun, @NoSeriIjazah)"; } else { sqlQuery = @"UPDATE AkademikTerakhir SET NamaSekolah = @NamaSekolah, JenisSekolah = JenisSekolah, StatusSekolah = StatusSekolah, AlamatSekolah=@AlamatSekolah, NoPesertaUn = @NoPesertaUn, NoSeriSkhun = @NoSeriSkhun, NoSeriIjazah=@NoSeriIjazah WHERE CalonSiswaId = @CalonSiswaId"; } using (var connection = new SqlConnection(_connectionHelper.GetConnectionString())) { connection.Open(); connection.Execute(sql: sqlQuery, param: newData); } }