// GET: Test public ActionResult Index() { MVCTutorial2Entities db = new MVCTutorial2Entities(); List <Department> list = db.Departments.ToList(); //List<Employee> l = db.Employees.ToList(); //ViewBag.EmployeeList = new SelectList(l, "EmployeeId", "Emri"); ViewBag.DepartmentList = new SelectList(list, "DepartmentId", "DepartmentName"); return(View()); }
// GET: Test public ActionResult Index() { MVCTutorial2Entities db = new MVCTutorial2Entities(); List <Employee> list = db.Employees.ToList(); EmployeeViewModel em = new EmployeeViewModel(); List <EmployeeViewModel> employee = list.Select(x => new EmployeeViewModel { Emri = x.Emri, EmployeeId = x.EmployeeId }).ToList(); return(View(employee)); }
public ActionResult EmployeeDetail(int EmployeeId) { MVCTutorial2Entities db = new MVCTutorial2Entities(); Employee em = db.Employees.SingleOrDefault(x => EmployeeId == x.EmployeeId); EmployeeViewModel employee = new EmployeeViewModel(); employee.Emri = em.Emri; employee.EmployeeId = em.EmployeeId; employee.Address = em.Address; employee.DepartmentId = em.DepartmentId; employee.DepartmentName = em.Department.DepartmentName; return(View(employee)); }
public ActionResult SaveRecord(EmployeeViewModel model) { try { MVCTutorial2Entities db = new MVCTutorial2Entities(); Employee emp = new Employee(); emp.EmployeeId = model.EmployeeId; emp.Emri = model.Emri; emp.Address = model.Address; emp.DepartmentId = model.DepartmentId; db.Employees.Add(emp); db.SaveChanges(); int lastEmployeeId = emp.EmployeeId; } catch (Exception ex) { throw ex; } return(RedirectToAction("Index")); }