Ejemplo n.º 1
0
        //
        // GET: /Employee/
        public ActionResult Details()
        {
            Employee employee = new Employee()
            {
                EmployeeId = 101,
                Name = "John",
                Gender = "Male",
                City = "London",
            };

            return View(employee);
        }
Ejemplo n.º 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;
        }
Ejemplo n.º 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;
        }