コード例 #1
0
        private static string GetFromContestant(ContestantModel contestant, string value)
        {
            switch (value)
            {
            case "@firstname":
                return(contestant.FirstName);

            case "@lastname":
                return(contestant.LastName);

            case "@address":
                return(contestant.Address);

            case "@city":
                return(contestant.City);

            case "@state":
                return(contestant.State);

            case "@zip":
                return(contestant.Zip);

            case "@email":
                return(contestant.Email);

            case "@phone":
                return(contestant.Phone);

            default:
                return(string.Empty);
            }
        }
コード例 #2
0
        public ActionResult Delete(int id)
        {
            string          connectionstring = configuration.GetConnectionString("DefaultConnection");
            ContestantModel contestantModel  = new ContestantModel();

            using (SqlConnection connection = new SqlConnection(connectionstring))
            {
                connection.Open();
                SqlCommand sqlcom = new SqlCommand("Delete from Contestants where id=@id", connection);
                sqlcom.Parameters.AddWithValue("@id", id);
                sqlcom.ExecuteNonQuery();
            }
            return(RedirectToAction("index"));
        }
コード例 #3
0
        // GET: Admin/Edit/5
        public ActionResult Edit(int id)
        {
            string          connectionstring = configuration.GetConnectionString("DefaultConnection");
            ContestantModel contestantModel  = new ContestantModel();
            DataTable       dtbl             = new DataTable();

            using (SqlConnection connection = new SqlConnection(connectionstring))
            {
                connection.Open();
                SqlCommand sqlcom = new SqlCommand("UPDATE dbo.Contestants set Approved=1 where id=@id", connection);
                sqlcom.Parameters.AddWithValue("@id", id);
                sqlcom.ExecuteNonQuery();
            }

            return(RedirectToAction("index"));
        }
コード例 #4
0
        public IActionResult Create(ContestantModel contestantModel)
        {
            string connectionstring = configuration.GetConnectionString("DefaultConnection");

            using (SqlConnection sqlCon = new SqlConnection(connectionstring))
            {
                sqlCon.Open();
                string     query  = "Insert into Contestants VALUES(@Name,@LastName, @Time, 0)";
                SqlCommand sqlCmd = new SqlCommand(query, sqlCon);
                sqlCmd.Parameters.AddWithValue("@Name", contestantModel.Name);
                sqlCmd.Parameters.AddWithValue("@LastName", contestantModel.LastName);
                sqlCmd.Parameters.AddWithValue("@Time", contestantModel.Time);
                sqlCmd.ExecuteNonQuery();
            }

            return(RedirectToAction("index"));
        }