public ActionResult InsertNewEmployee(Employee emp) { emp.EmpID = Convert.ToInt32(Request.Form["txtempid"]); emp.EmpName = Request.Form["txtempname"]; emp.Dept = Request.Form["depart"]; emp.Desg = Request.Form["ddldesg"]; emp.Salary = Convert.ToDecimal(Request.Form["txtSalary"]); emp.projid = Convert.ToInt32(Request.Form["ddlpid"]); //this data has to be inserted to DB //ado.net or new technology called entity framework //ModelState.AddModelError() display any msg from controller //in the view ModelState.AddModelError("", emp.EmpID + "," + emp.EmpName + "," + emp.Dept + "," + emp.Desg + "," + emp.Salary + "," + emp.projid); //1. obj of sqlconnection //2.open connection //3. //insert data to emp table through entity framework db.Employees.Add(emp); int res = db.SaveChanges(); if (res > 0) { ModelState.AddModelError("", "new employee inserted"); } return(RedirectToAction("GetEmployees")); //1st way }
public ActionResult Register(usertable u) { u.username = Request.Form["txtname"]; u.email = Request.Form["email"]; u.password = Request.Form["txtpass"]; u.city = Request.Form["city"]; u.mobile = Convert.ToInt32(Request.Form["mobile"]); db.usertables.Add(u); int res = db.SaveChanges(); if (res > 0) { ModelState.AddModelError("", "Registration Complete"); } return(RedirectToAction("Login")); }
public ActionResult InsertNewDepartment(Department dept) { LTIMVCEntities1 db1 = new LTIMVCEntities1(); dept.DeptId = Convert.ToInt32(Request.Form["txtDeptId"]); dept.DeptName = Request.Form["ddldept1"]; dept.DeptLoc = Request.Form["ddllocation"]; ModelState.AddModelError("", dept.DeptId + " " + dept.DeptName + " " + dept.DeptLoc + " "); db1.Departments.Add(dept); int res1 = db1.SaveChanges(); if (res1 > 0) { ModelState.AddModelError("", "New Department Inserted"); } return(View()); }