public ActionResult EditEmpDetails(int id, Models.EmpModel obj) { try { // TODO: Add update logic here EmpRepository EmpRepo = new EmpRepository(); EmpRepo.UpdateEmployee(obj); return(RedirectToAction("GetAllEmpDetails")); } catch { return(View()); } }
private static string conString = "server = localhost; port=3306;database=3dstask;user=root;password=santu672;";//ConfigurationManager.AppSettings. ConnectionStrings["conString"].ToString(); public static void AddEmployee(Models.EmpModel model) { using (MySqlConnection con = new MySqlConnection(conString)) { con.Open(); using (MySqlCommand cmd = new MySqlCommand()) { cmd.Connection = con; cmd.CommandType = CommandType.Text; cmd.CommandText = "Insert into employee(Name,City,Salary) Values(" + model.Name + "," + model.City + "," + model.Salary + ")"; cmd.ExecuteNonQuery(); } } }
public ActionResult AddEmployee(Models.EmpModel Emp) { try { if (ModelState.IsValid) { EmpRepository EmpRepo = new EmpRepository(); if (EmpRepo.AddEmployee(Emp)) { ViewBag.Message = "Employee details added successfully"; } } return(View()); } catch { return(View()); } }