public void EditEmployee(EmployeeDetails empDet) { EmployeeEntity empContext = new EmployeeEntity(); var jobObj = empContext.JobDetails.FirstOrDefault(x => x.JobID == empDet.EmployeeJobID); if (jobObj != null) { // jobObj.Name = empDet.JobDetails.Name; var empObj = empContext.EmployeeDetails.SingleOrDefault(x => x.EmpID == empDet.EmpID); if (empObj != null) { empObj.Name = empDet.Name; empObj.Address = empDet.Address; empObj.Age = empDet.Age; empObj.EmployeeJobID = jobObj.JobID; // jobObj.Name = empDet.JobDetails.Name; } } else { var empObj = empContext.EmployeeDetails.SingleOrDefault(x => x.EmpID == empDet.EmpID); if (empObj != null) { empObj.Name = empDet.Name; empObj.Address = empDet.Address; empObj.Age = empDet.Age; empObj.JobDetails = empDet.JobDetails; } } empContext.SaveChanges(); }
public ActionResult Create([Bind(Include = "EmployeeID,Name,City,Gender,DepartmentID")] Employee employee) { if (string.IsNullOrEmpty(employee.Name)) { ModelState.AddModelError("Name", "Name field is requred"); } if (ModelState.IsValid) { db.Employees.Add(employee); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.DepartmentID = new SelectList(db.Departments, "DepartmentID", "Name", employee.DepartmentID); return(View(employee)); }
public void DeleteEmployee(int empId) { EmployeeEntity empContext = new EmployeeEntity(); var emp = empContext.EmployeeDetails.Where(x => x.EmpID == empId).FirstOrDefault(); empContext.Entry(emp).State = System.Data.Entity.EntityState.Deleted; empContext.SaveChanges(); }
public IHttpActionResult PostEmployee(TABLE_EMPLOYEE emp) { if (ModelState.IsValid) { context.PROC_EMP(emp.EMPLOYEENAME, emp.EMPLOYEESURNAME, emp.EMPLOYEEAGE, emp.EMPLOYEEMAIL); context.SaveChanges(); } return(Ok()); }
public ValuesController(EmployeeEntity context) { _context = context; if (_context.Employees.Count() == 0) { _context.Employees.Add(new Employee { FirstName = "Dummy Employee", MiddleName = "Dummy Employee", Salary = 0.0, JoiningDate = DateTime.Now.Date }); _context.SaveChanges(); } }
public ActionResult Post(Employee employee) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _context.Employees.Add(new Employee { FirstName = employee.FirstName, MiddleName = employee.MiddleName, Salary = employee.Salary, JoiningDate = employee.JoiningDate }); _context.SaveChanges(); return(new OkObjectResult("Employee created")); }
public void SaveJob() { EmployeeEntity empContext = new EmployeeEntity(); EmployeeDetails ed1 = new EmployeeDetails() { Name = "Ardhra", Address = "Bla bla", Age = 29, Salary = 20000 }; EmployeeDetails ed2 = new EmployeeDetails() { Name = "Jwala", Address = "Bla bla", Age = 29, Salary = 20000 }; List <EmployeeDetails> lstempl = new List <EmployeeDetails>(); lstempl.Add(ed1); lstempl.Add(ed2); JobDetails jb = new JobDetails() { Name = "Part-Time", Employees = lstempl }; empContext.JobDetails.Add(jb); empContext.SaveChanges(); }
public void Save() { _context.SaveChanges(); }