public ActionResult Create(Employee employee) { //if (ModelState.IsValid) //{ // context.Employees.Add(employee); // context.SaveChanges(); // return RedirectToAction("Index"); //} //return View(employee); employee.Id = "BD123"; employee.JoiningDt = DateTime.Now; if (ModelState.IsValid) { unitOfWork.EmployeeRepository.InsertOrUpdate(employee); unitOfWork.Save(); return RedirectToAction("Index"); } return View(employee); }
public void InsertOrUpdate(Employee employee) { //if (employee.Id == default(string)) //{ // // New entity // context.Employees.Add(employee); //} //else //{ // // Existing entity // context.Entry(employee).State = System.Data.Entity.EntityState.Modified; //} if (employee.Gid == default(long)) { // New entity context.Employees.Add(employee); } else { // Existing entity context.Entry(employee).State = System.Data.Entity.EntityState.Modified; } }