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); } }
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")); }
// 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")); }
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")); }