public PartialViewResult Edit(Employee emp, string EmpId) { ObjectId empId; var isValid = ObjectId.TryParse(EmpId, out empId); if (isValid) { var collections = mongoDatabase.GetCollection<Employee>("Employee"); var getQuery = Query<Employee>.EQ(e => e.EmpId, empId); var existingemp = collections.FindOne(getQuery); existingemp.LastName = emp.LastName; existingemp.FirstName = emp.FirstName; existingemp.Email = emp.Email; existingemp.Designation = emp.Designation; existingemp.ReportingTo = emp.ReportingTo; existingemp.Department = emp.Department; existingemp.DateOfBirth = emp.DateOfBirth; existingemp.Gender = emp.Gender; existingemp.Salary = emp.Salary; existingemp.IsReportingHead = emp.IsReportingHead; existingemp.IsActive = emp.IsActive; collections.Save(existingemp); return GetAll(); } else { return PartialView("Edit"); } }
public PartialViewResult Create(Employee emp) { if (ModelState.IsValid) { var _employee = mongoDatabase.GetCollection<Employee>("Employee"); string empId = emp.ReportingTo; ObjectId pmId; var isValid = ObjectId.TryParse(empId, out pmId); if (isValid) { var getQuery = Query<Employee>.EQ(e => e.EmpId, pmId); var rtemp = _employee.FindOne(getQuery); if (rtemp != null) { emp.ReportingHead = rtemp.Fullname; } } _employee.Insert(emp); var id = emp.EmpId; return GetAll(); } else { return PartialView(emp); } }