// ********************************* // GET: Cohorts/Delete/5 // ********************************* public ActionResult Delete(int id) { Cohort cohort = GetCohortById(id); CohortDeleteViewModel viewModel = new CohortDeleteViewModel { CohortName = cohort.CohortName }; return(View(viewModel)); }
// GET: Cohorts/Delete/5 public ActionResult Delete(int id) { Cohort cohort = GetCohortById(id); if (cohort == null) { return(NotFound()); } CohortDeleteViewModel viewModel = new CohortDeleteViewModel { Cohort = cohort }; return(View(viewModel)); }
public ActionResult Delete(int id, CohortDeleteViewModel viewModel) { try { using (SqlConnection conn = Connection) { conn.Open(); using (SqlCommand cmd = conn.CreateCommand()) { cmd.CommandText = @"DELETE FROM Cohort WHERE Id = @id"; cmd.Parameters.Add(new SqlParameter("@id", id)); int rowsAffected = cmd.ExecuteNonQuery(); return(RedirectToAction(nameof(Index))); } } } catch { return(View(viewModel)); } }