コード例 #1
0
        // *********************************
        //      GET: Cohorts/Delete/5
        // *********************************
        public ActionResult Delete(int id)
        {
            Cohort cohort = GetCohortById(id);

            CohortDeleteViewModel viewModel = new CohortDeleteViewModel
            {
                CohortName = cohort.CohortName
            };

            return(View(viewModel));
        }
コード例 #2
0
        // 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));
        }
コード例 #3
0
        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));
            }
        }