コード例 #1
0
ファイル: EmployeeController.cs プロジェクト: jmt4/MVC
        //
        // GET: /Employee/
        public ActionResult Details()
        {
            Employee employee = new Employee()
            {
                EmployeeId = 101,
                Name = "John",
                Gender = "Male",
                City = "London",
            };

            return View(employee);
        }
コード例 #2
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;
        }
コード例 #3
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;
        }