예제 #1
0
        public ViewResult Detail(int id)
        {
            var             model   = new HomePageViewModel();
            SQLEmployeeData sqlData = new SQLEmployeeData(_context);

            Employee employee = sqlData.Get(id);

            return(View(employee));
        }
예제 #2
0
        // GET: HomeController
        public ViewResult Index()
        {
            var model = new Employee();

            using (var context = new dbContextEmployee())
            {
                SQLEmployeeData sqlData = new SQLEmployeeData(context); //instance of sql employeedata funciton
                sqlData.Add(model);                                     // employee model
            }
            return(View());
        }
예제 #3
0
        public IActionResult Edit(int id, EmployeeEditViewModel input)
        {
            SQLEmployeeData sqlData  = new SQLEmployeeData(_context);
            var             employee = sqlData.Get(id);

            if (employee != null && ModelState.IsValid)
            {
                employee.Name = input.Name;
                _context.SaveChanges();
                return(RedirectToAction("Detail", new { id = employee.ID }));
            }
            return(View(employee));
        }
예제 #4
0
        [AllowAnonymous] // 允许匿名用户访问
        public ViewResult Index()
        {
            //var employee = new Employee { ID = 1, Name = "小白" };
            //return View(employee);
            var model = new HomePageViewModel();

            SQLEmployeeData sqlData = new SQLEmployeeData(_context);

            model.Employees = sqlData.GetAll();


            return(View(model));
        }
예제 #5
0
        public IActionResult Edit(int id)
        {
            var             model   = new HomePageViewModel();
            SQLEmployeeData sqlData = new SQLEmployeeData(_context);

            Employee employee = sqlData.Get(id);

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

            return(View(employee));
        }
예제 #6
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());
        }