public ActionResult Save(Employee mEmployee) { var efData = db.tblEmployees.Where(x => x.Id == mEmployee.Id).FirstOrDefault(); if (efData == null) { efData = new tblEmployee(); db.tblEmployees.Add(efData); } efData.Id = mEmployee.Id; efData.Name = mEmployee.Name; efData.Surname = mEmployee.Surname; efData.DeptId = mEmployee.DeptId; efData.Address = mEmployee.Address; efData.Qualification = mEmployee.Qualification; efData.ContactNumber = mEmployee.ContactNumber; efData.IsActive = true; db.SaveChanges(); return(Json("Ok")); }
public ActionResult Save(string deptName, int deptId) { var efData = db.tblDepartments.Where(x => x.Id == deptId).FirstOrDefault(); var data = db.tblDepartments.Where(x => x.Name.ToLower() == deptName.ToLower() && x.IsActive == true).FirstOrDefault(); if (data == null) { if (efData == null) { efData = new tblDepartment(); db.tblDepartments.Add(efData); } efData.Id = deptId; efData.Name = deptName; efData.IsActive = true; db.SaveChanges(); return(Json("Ok")); } else { return(Json("Error")); } }