コード例 #1
0
ファイル: EmployeeController.cs プロジェクト: hkdilan/MVCDemo
        public ActionResult Detail(int id)
        {
            EmployeeContext empContext = new EmployeeContext();
            Employee employee = empContext.Employees.Single(emp => emp.EmployeeId == id);

            return View(employee);
        }
コード例 #2
0
        public ActionResult EditGet(int? id)
        {
            ActionResult action = RedirectToAction("Index");
            if (id != null)
            {

                EmployeeContext dbContext = new EmployeeContext();
                Employee employee = dbContext.Employees.SingleOrDefault(x => x.EmployeeId == id);
                if (employee != null)
                {
                    action = View(employee);
                }
            }
            return action;
        }
コード例 #3
0
        public ActionResult Delete(int? id)
        {
            EmployeeContext dbContext = new EmployeeContext();
            if (id != null)
            {
                Employee employee = dbContext.Employees.SingleOrDefault(e => e.EmployeeId == id);
                if (employee != null)
                {
                    dbContext.Employees.Remove(employee);
                }
                dbContext.SaveChanges();
            }

            return RedirectToAction("Index");
        }
コード例 #4
0
        public ActionResult CreatePost()
        {
            ActionResult action = View();
            Employee employee = new Employee();
            TryUpdateModel<Employee>(employee);

            if (ModelState.IsValid)
            {
                EmployeeContext dbContext = new EmployeeContext();
                dbContext.Employees.Add(employee);
                dbContext.SaveChanges();

                action = RedirectToAction("Index");
            }
            return action;
        }
コード例 #5
0
 // GET: Department
 public ActionResult Index()
 {
     EmployeeContext dbContext = new EmployeeContext();
     List<Department> departments = dbContext.Departments.ToList();
     return View(departments);
 }
コード例 #6
0
        public ActionResult EditPost()
        {
            ActionResult action = View();
            Employee employee = new Employee();
            TryUpdateModel<Employee>(employee);

            if (ModelState.IsValid)
            {
                EmployeeContext dbContext = new EmployeeContext();
                Employee currentDetails = dbContext.Employees.SingleOrDefault(x => x.EmployeeId == employee.EmployeeId);

                // Name property is black listed
                if (currentDetails != null)
                {
                    currentDetails.Gender = employee.Gender;
                    currentDetails.DateOfBirth = employee.DateOfBirth;
                    currentDetails.City = employee.City;
                    dbContext.SaveChanges();

                }
                action = RedirectToAction("Index");
            }
            return action;
        }
コード例 #7
0
        public ActionResult Index()
        {
            EmployeeContext dbContext = new EmployeeContext();
            List<Employee> employees = dbContext.Employees.ToList();

            return View(employees);
        }