示例#1
0
        public IActionResult Edit(EmployeeViewModel employee)
        {
            if (!ModelState.IsValid)
            {
                return(View(employee));
            }
            if (employee.Id > -1)
            {
                EmployeeViewModel oldEmployee = _db.GetById(employee.Id);
                if (oldEmployee == null)
                {
                    return(NotFound());
                }
                oldEmployee.FirstName  = employee.FirstName;
                oldEmployee.LastName   = employee.LastName;
                oldEmployee.Patronymic = employee.Patronymic;
            }
            else
            {
                _db.AddNew(employee);
            }
            _db.Commit();

            return(RedirectToAction(nameof(Index)));
        }