public ActionResult Edit(Guid?id, SysUser _sysUser) { Debug.WriteLine("a"); if (!ModelState.IsValid) { Edit(id); return(View(_sysUser)); } if (id.HasValue) { //清除原有部门数据 _sysDepartmentSysUserService.Delete(a => a.SysUserId.Equals(id.Value)); //清除原有数据 _sysRoleSysUserService.Delete(a => a.SysUserId.Equals(id.Value)); } _sysUserService.Save(id, _sysUser); if (_sysUser.SysDepartmentsId != null) { foreach (Guid sysDepartmentId in _sysUser.SysDepartmentsId) { _sysDepartmentSysUserService.Save(null, new SysDepartmentSysUser { SysUserId = _sysUser.Id, SysDepartmentId = sysDepartmentId }); } } if (_sysUser.SysRolesId != null) { foreach (Guid sysRoleId in _sysUser.SysRolesId) { _sysRoleSysUserService.Save(null, new SysRoleSysUser { SysUserId = _sysUser.Id, SysRoleId = sysRoleId }); } } _unitOfWork.Commit(); return(RedirectToAction("Index")); }
public ActionResult Edit(Guid?id, SysUser collection) { if (!ModelState.IsValid) { Edit(id); return(View(collection)); } if (id.HasValue) { //清除原有部门数据 _sysDepartmentSysUserService.Delete(a => a.SysUserId.Equals(id.Value)); //清除原有数据 _sysRoleSysUserService.Delete(a => a.SysUserId.Equals(id.Value)); } _sysUserService.Save(id, collection); if (collection.SysDepartmentsId != null) { foreach (var sysDepartmentId in collection.SysDepartmentsId) { _sysDepartmentSysUserService.Save(null, new SysDepartmentSysUser { SysUserId = collection.Id, SysDepartmentId = sysDepartmentId }); } } if (collection.SysRolesId != null) { foreach (var sysRoleId in collection.SysRolesId) { _sysRoleSysUserService.Save(null, new SysRoleSysUser { SysUserId = collection.Id, SysRoleId = sysRoleId }); } } _unitOfWork.Commit(); return(RedirectToAction("Index")); }