public ActionResult DeleteItem(int id) { tbl_Employees emp = dbContext.tbl_Employees.Where(c => c.EmpId == id).FirstOrDefault(); dbContext.tbl_Employees.Remove(emp); dbContext.SaveChanges(); return(RedirectToAction("List")); }
public ActionResult EditItem(tbl_Employees emp) { tbl_Employees emp1 = dbContext.tbl_Employees.Where(c => c.EmpId == emp.EmpId).FirstOrDefault(); // dbContext.Entry(emp1).CurrentValues.SetValues(emp); emp1.EmpId = emp.EmpId; emp1.EmpName = emp.EmpName; emp1.Address = emp.Address; emp1.Salary = emp.Salary; dbContext.SaveChanges(); return(RedirectToAction("List")); }
private void btnSave_Click(object sender, EventArgs e) { if (edit) { String empId = txtId.Text; var employes = db.tbl_Employees.Find(empId); if (employes != null) { employes.employes_name = txtName.Text; employes.employes_phone = txtPhone.Text; employes.employes_address = txtAddress.Text; employes.email = txtEmail.Text; employes.password = txtPassword.Text; employes.brithday = (dtBrithday.Value); employes.gender = rdGender.Checked; employes.status_Employes = ckStatus.Checked; employes.classifed_id = cbClassifi.SelectedValue.ToString(); db.SaveChanges(); DisplayEmployes(); } else { MessageBox.Show("Mã nhân viên không đúng", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); } } else { if (!ExitEmployesId(txtId.Text)) { tbl_Employees emp = new tbl_Employees(); emp.employes_id = txtId.Text; emp.employes_name = txtName.Text; emp.employes_address = txtAddress.Text; emp.employes_phone = txtPhone.Text; emp.email = txtEmail.Text; emp.password = txtPassword.Text; emp.brithday = dtBrithday.Value; emp.gender = rdGender.Checked; emp.classifed_id = cbClassifi.SelectedValue.ToString(); emp.status_Employes = ckStatus.Checked; db.tbl_Employees.Add(emp); db.SaveChanges(); DisplayEmployes(); } else { MessageBox.Show("Trùng mã nhân viên", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
public ActionResult Create(tbl_Employees emp) { if (ModelState.IsValid) { dbContext.tbl_Employees.Add(emp); dbContext.SaveChanges(); return(View()); } else { return(View(emp)); } }
public ActionResult Delete(int id) { try { tbl_Employees emp = db.tbl_Employees.Where(e => e.ID == id).FirstOrDefault(); if (emp != null) { db.tbl_Employees.Remove(emp); db.SaveChanges(); return(Content("Deleted Successfully!")); } return(Content("Error!")); } catch (Exception ex) { TempData["Msg"] = ex.Message.ToString(); } return(Content("")); }
public ActionResult EditItem(int id) { tbl_Employees emp = dbContext.tbl_Employees.Where(c => c.EmpId == id).FirstOrDefault(); return(View(emp)); }
public ActionResult SearchResults(int id) // Add Partial View { tbl_Employees employee = dbContext.tbl_Employees.Where(c => c.EmpId == id).FirstOrDefault(); return(PartialView(employee)); }