public ActionResult SaveRecord(Model.EmployeeViewModel model) { try { FirstWebAplicationDatabaseEntities db = new FirstWebAplicationDatabaseEntities(); Employee employee = new Employee(); employee.Name = model.Name; employee.Department = model.Department; employee.DepartmentId = model.DepartmentId; db.Employees.Add(employee); db.SaveChanges(); int id = employee.Id; } catch (Exception ex) { throw ex; } return(RedirectToAction("Index")); }
public ActionResult Index() { FirstWebAplicationDatabaseEntities db = new FirstWebAplicationDatabaseEntities(); List <Employee> employees = db.Employees.ToList(); ViewBag.NewList = new SelectList(employees, "Id", "Department"); return(View("Index")); }
public ActionResult EmployeeDetail(int id) { using (var db = new FirstWebAplicationDatabaseEntities()) { Employee employee = db.Employees.SingleOrDefault(x => x.Id == id); EmployeeViewModel employeeViewModel = new EmployeeViewModel(); employeeViewModel.Name = employee.Name; employeeViewModel.Id = employee.Id; employeeViewModel.Department = employee.Department; return(View("EmployeeDetail", employeeViewModel)); } }
public ActionResult Index() { FirstWebAplicationDatabaseEntities db = new FirstWebAplicationDatabaseEntities(); Employee employee = db.Employees.SingleOrDefault(x => x.Id == 1); Model.EmployeeViewModel viewModel = new Model.EmployeeViewModel(); viewModel.Id = employee.Id; viewModel.Name = employee.Name; viewModel.Department = employee.Department; return(View(viewModel)); }
public ActionResult Index() { using (var db = new FirstWebAplicationDatabaseEntities()) { var list = db.Employees.Select(x => new EmployeeViewModel { Name = x.Name, Id = x.Id, Department = x.Department }).ToList(); //List<Employee> employees = db.Employees.ToList(); //List<EmployeeViewModel> employeesModel = employees.Select(x => new EmployeeViewModel { Name = x.Name, EmployeeID = x.EmployeeID, DepartmentID = x.DepartmentID }).ToList(); return(View(list)); } }
public ActionResult Index() { FirstWebAplicationDatabaseEntities firstWebAplicationDatabaseEntities = new FirstWebAplicationDatabaseEntities(); List <Employee> employeeList = firstWebAplicationDatabaseEntities.Employees.ToList(); Model.EmployeeViewModel employeeViewModel = new Model.EmployeeViewModel(); List <Model.EmployeeViewModel> employeeViewModelsList = employeeList.Select(x => new Model.EmployeeViewModel { Name = x.Name, Id = x.Id, Department = x.Department }).ToList(); return(View(employeeViewModelsList)); }