public void Update(UserDto model) { var entity = _userRepository.GetById(model.Id); entity = model.MapTo(entity); //删除之前的中间数据(改成真删) var oldUserRoleIds = _userRoleRepository.GetAll().Where(m => m.IsDeleted == false && m.UserId == entity.Id).Select(m => m.Id).ToList(); _userRoleRepository.DeleteList(oldUserRoleIds); var newRoleIds = model.SelectedRoleIds.ToList(); foreach (var newRoleId in newRoleIds) { var userRole = new UserRole() { UserId = entity.Id, RoleId = newRoleId, CreateId = entity.CreateId, CreateBy = entity.CreateBy, CreateTime = DateTime.Now, ModifyId = entity.ModifyId, ModifyBy = entity.ModifyBy, ModifyTime = DateTime.Now }; _userRoleRepository.Insert(userRole); } _userRepository.Update(entity); }
public void Create(UserDto model) { model.PwdErrorCount = 0; model.LoginCount = 0; model.RegisterTime = DateTime.Now; var entity = model.MapTo <User>(); foreach (int roleId in model.SelectedRoleIds) { if (_roleRepository.GetAll().Any(t => t.Id == roleId)) { entity.UserRole.Add( new UserRole() { UserId = entity.Id, RoleId = roleId, CreateId = entity.CreateId, CreateBy = entity.CreateBy, CreateTime = DateTime.Now, ModifyId = entity.ModifyId, ModifyBy = entity.ModifyBy, ModifyTime = DateTime.Now }); } } _userRepository.Insert(entity); }
public void Create(UserDto model) { model.PwdErrorCount = 0; model.LoginCount = 0; model.RegisterTime = DateTime.Now; var entity = model.MapTo<User>(); foreach (int roleId in model.SelectedRoleIds) { if (_roleRepository.GetAll().Any(t => t.Id == roleId)) { entity.UserRole.Add( new UserRole() { UserId = entity.Id, RoleId = roleId, CreateId = entity.CreateId, CreateBy = entity.CreateBy, CreateTime = DateTime.Now, ModifyId = entity.ModifyId, ModifyBy = entity.ModifyBy, ModifyTime = DateTime.Now }); } } _userRepository.Insert(entity); }