public JsonResult Create(Person createData1, CompanyUnit createData2) { using (EmployeeData2Entities db = new EmployeeData2Entities()) { db.Person.Add(createData1); db.SaveChanges(); createData2.EmpID = createData1.EmpID; db.CompanyUnit.Add(createData2); db.SaveChanges(); } return(Json(JsonRequestBehavior.AllowGet)); }
public ActionResult Remove(int empid) { using (EmployeeData2Entities db = new EmployeeData2Entities()) { //Person pedata = db.Person.Where(x => x.EmpID == empid).FirstOrDefault(); [上下兩個與法都可以用] Person pedata = db.Person.Find(empid); db.Person.Remove(pedata); //CompanyUnit comdata = db.CompanyUnit.Where(y => y.EmpID == empid).FirstOrDefault(); CompanyUnit comdata = db.CompanyUnit.Find(empid); db.CompanyUnit.Remove(comdata); db.SaveChanges(); return(RedirectToAction("ShowAllData")); } }
public JsonResult Edit(DataEmp getdata) { //if (!string.IsNullOrWhiteSpace(Convert.ToString(getdata.EmpID))) { using (EmployeeData2Entities db = new EmployeeData2Entities()) { Person pedata = db.Person.Where(x => x.EmpID == getdata.EmpID).FirstOrDefault(); pedata.EmpName = getdata.EmpName; pedata.EmpBirthday = getdata.EmpBirthday; pedata.Gender = getdata.Gender; pedata.BuildDate = getdata.BuildDate; pedata.LogingDate = getdata.LogingDate; CompanyUnit comdata = db.CompanyUnit.Where(y => y.EmpID == getdata.EmpID).FirstOrDefault(); comdata.JobTitle = getdata.JobTitle; comdata.UnitID = getdata.UnitID; comdata.UnitName = getdata.UnitName; comdata.Seniority = getdata.Seniority; db.SaveChanges(); } return(Json(getdata)); }