コード例 #1
0
        public IActionResult Edit(int id)
        {
            SQLEmployeeData sqlData = new SQLEmployeeData(_context);
            var             model   = sqlData.Get(id);

            if (model == null)
            {
                return(RedirectToAction("Index"));
            }
            return(View(model));
        }
コード例 #2
0
        public ViewResult Index()
        {
            var model = new HomePageViewModel();

            if (_context != null)
            {
                SQLEmployeeData sqlData = new SQLEmployeeData(_context);
                model.Employees = sqlData.GetAll();
            }

            return(View(model));
        }
コード例 #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("Details", new { id = employee.Id }));
            }
            return(View(employee));
        }
コード例 #4
0
        public IActionResult Create(EmployeeEditViewModel model)
        {
            if (ModelState.IsValid)
            {
                var employee = new Employee();
                employee.Name = model.Name;
                var context = _context;

                SQLEmployeeData sqlData = new SQLEmployeeData(context);
                sqlData.Add(employee);
                return(RedirectToAction("Details", new { id = employee.Id }));
            }
            return(View());
        }