Exemplo n.º 1
0
        public ViewResult Detail(int id)
        {
            var             model   = new HomePageViewModel();
            SQLEmployeeData sqlData = new SQLEmployeeData(_context);

            Employee employee = sqlData.Get(id);

            return(View(employee));
        }
Exemplo n.º 2
0
        public ViewResult Detail(int id)
        {
            var model = new HomePageViewModel();
            //var employee = new Employee() { ID = 1, Name = "张三" };
            //return View(employee);

            SQLEmployeeData sqlData  = new SQLEmployeeData(_context);
            Employee        employee = sqlData.Get(id);

            return(View(employee));
        }
Exemplo n.º 3
0
        public IActionResult Edit(int id, EmployeeEditViewModel input)
        {
            SQLEmployeeData sqlData  = new SQLEmployeeData(_context);
            var             employee = sqlData.Get(id);

            if (null != employee && ModelState.IsValid)
            {
                employee.Name = input.Name;
                _context.SaveChanges();
                return(RedirectToAction("Detail", new { id = employee.ID }));
            }
            return(View(employee));
        }
Exemplo n.º 4
0
        public IActionResult Edit(int id)
        {
            var             model    = new HomePageViewModel();
            SQLEmployeeData sqlData  = new SQLEmployeeData(_context);
            Employee        employee = sqlData.Get(id);

            if (null == employee)
            {
                return(RedirectToAction("Index"));
            }

            return(View(employee));
        }
Exemplo n.º 5
0
        public IActionResult Create(EmployeeEditViewModel model)
        {
            if (ModelState.IsValid)
            {
                var employee = new Employee();
                employee.Name = model.Name;

                SQLEmployeeData sqlData = new SQLEmployeeData(_context);
                sqlData.Add(employee);
                return(RedirectToAction("Detail", new { id = employee.ID }));
            }
            return(View());
        }
Exemplo n.º 6
0
        public ViewResult Index()
        {
            var model = new HomePageViewModel();
            //var employee = new Employee() { ID = 1, Name = "张三" };
            //return View(employee);

            SQLEmployeeData sqlData = new SQLEmployeeData(_context);

            model.Employees = sqlData.GetAll();


            return(View(model));
        }
Exemplo n.º 7
0
        public IActionResult Create(EmployeeEditViewModel input)
        {
            if (ModelState.IsValid)
            {
                var employee = new Employee
                {
                    Name = input.Name
                };

                SQLEmployeeData sqlData = new SQLEmployeeData(_context);
                sqlData.Add(employee);

                return(RedirectToAction("Index"));
            }

            return(View());
        }
Exemplo n.º 8
0
        [AllowAnonymous] //允许不登录访问
        public ViewResult Index()
        {
            //var employee = new Employee { ID = 1, Name = "语非" };
            //return View(employee);
            //var model = new HomePageViewModel();
            //using (var context = new HelloWorldDBContext())
            //{
            //    SQLEmployeeData sqlData = new SQLEmployeeData(context);
            //    model.Employees = sqlData.GetAll();
            //}
            var             model   = new HomePageViewModel();
            SQLEmployeeData sqlData = new SQLEmployeeData(_context);

            model.Employees = sqlData.GetAll();


            return(View(model));
        }
Exemplo n.º 9
0
        public ViewResult Index()
        {
            //return Content("hello world;这条消息来自使用了 Action Result 的 Home 控制器!");

            //var employee = new Employee { ID = 1, Name = "阿黄" };
            ////return new ObjectResult(employee);
            //ViewData["emp"] = employee.Name;
            //ViewBag.emp = employee.Name;
            //return View(employee);

            var model = new HomePageViewModel();

            SQLEmployeeData sqlData = new SQLEmployeeData(_context);

            model.Employees = sqlData.GetEmployees();

            return(View(model));
        }