public SystemUserDTO GetSystemUserByUId(int uid) { var query = systemUserRepository.GetById(uid); SystemUserDTO returnUser = (query == null ? null : AutoMapper.Mapper.Map <SystemUserDTO>(query)); if (returnUser != null && query.System_User_Role.Count > 0) { var roleList = query.System_User_Role.Select(x => x.System_Role).ToList(); returnUser.RoleList = AutoMapper.Mapper.Map <List <SystemRoleDTO> >(roleList); } return(returnUser); }
public void updateLastLoginDate(int UID) { var user = systemUserRepository.GetById(UID); if (user != null) { user.LastLoginDate = DateTime.Now; try { unitOfWork.Commit(); } catch (Exception e) { } } }
/// <summary> /// 根据用户id获取具有权限的菜单 /// </summary> /// <param name="userId"></param> /// <returns></returns> public async Task <IEnumerable <TreeEntity> > GetSystemPermissionMenuByUserId(Guid userId) { IList <TreeEntity> treeEntities = new List <TreeEntity>(); string cacheKey = USER_MENU_CACHE_KEY + userId; treeEntities = this._cache.Get <List <TreeEntity> >(cacheKey); if (treeEntities == null) { var userInfo = await _userRepository.GetById(userId); //判断当前用户是否是超级管理员:若是超级管理员则显示所有菜单 if (userInfo != null) { //如果是超级管理员 if (userInfo.IsAdmin) { treeEntities = (await _menuRepository.GetAllMenu(true, true)).ToList(); return(treeEntities); } treeEntities = (await _systemPermissionRepository.GetSystemPermissionMenuByUserId(userInfo.UserId)).ToList(); } } return(treeEntities); }
/// <summary> /// Edit user profile by ID, if you don't want to change some of the fields just put null there. /// </summary> /// <param name="Id"></param> /// <param name="UserName"></param> /// <param name="password"></param> /// <param name="email"></param> /// <param name="image"></param> /// <param name="moneyToAdd">a delta, can also be negative</param> /// <param name="rankToAdd">a delta, can also be negative</param> /// <param name="playedAnotherGame"></param> /// <returns>true if user has been edited succesfully</returns> public bool EditUserById(int Id, string UserName, string password, string email, Image image, int?moneyToAdd, int?rankToAdd, bool playedAnotherGame) { string imagesDirectory = String.Empty; if (image != null) { string filePath = String.Join("_", Guid.NewGuid(), UserName, "updated"); imagesDirectory = Path.Combine(Environment.CurrentDirectory, "images", filePath); // Save image to disc. (produces error but saves it anyway. we will just wrap it with a 'try' clause. try { image.Save(imagesDirectory); } catch { } } Database.Domain.SystemUser user = systemUserRepository.GetById(Id); if (UserName != null) { user.UserName = UserName; } if (password != null) { user.Salt = generateSalt(); user.Password = GetMd5Hash(password + user.Salt); } if (email != null) { user.Email = email; } if (image != null) { user.Email = email; } if (image != null) { user.Image = imagesDirectory; } if (moneyToAdd != null) { user.Money = Math.Max(0, user.Money + (int)moneyToAdd); } if (rankToAdd != null) { user.Rank = Math.Max(0, user.Rank + (int)rankToAdd); } if (playedAnotherGame) { user.GamesPlayed++; } if (!systemUserRepository.Update(user)) { return(false); } var updatedUser = databaseSystemUserToBackendSystemUser(systemUserRepository.GetById(Id)); if (image != null) { updatedUser.userImageByteArray = imageToByteArray(image); } systemUserCache.addOrUpdate(updatedUser); return(true); //SqlConnection connection = new SqlConnection(connectionString); //SqlCommand cmd = new SqlCommand(); //int psikCount = -1 + //(UserName == null ? 0 : 1) + //(password == null ? 0 : 1) + //(email == null ? 0 : 1) + //(image == null ? 0 : 1) + //(money == null ? 0 : 1) + //(rankToAdd == null ? 0 : 1) + //(playedAnotherGame ? 1 : 0); //cmd.CommandText = "Update SystemUsers SET " + // (UserName == null ? "" : "UserName=@UserName" + (psikCount-- > 0 ? "," : "")) + // (password == null ? "" : "password=HASHBYTES(\'MD5\', CONCAT(@password,@salt)),salt=@salt" + (psikCount-- > 0 ? "," : "")) + // (email == null ? "" : "email=@email" + (psikCount-- > 0 ? "," : "")) + // (image == null ? "" : "image=@image" + (psikCount-- > 0 ? "," : "")) + // (money == null ? "" : "money=money+@money" + (psikCount-- > 0 ? "," : "")) + // (rankToAdd == null ? "" : "rank=(CASE WHEN rank+@rankToAdd > 0 THEN rank+@rankToAdd ELSE 0 END)" + (psikCount-- > 0 ? "," : "")) + // (!playedAnotherGame ? "" : "gamesPlayed=gamesPlayed+1") + // " WHERE Id=@Id"; //cmd.CommandType = CommandType.Text; //cmd.Connection = connection; //cmd.Parameters.AddWithValue("@Id", Id); //if (UserName != null) cmd.Parameters.AddWithValue("@UserName", UserName); //if (password != null) cmd.Parameters.AddWithValue("@password", password); //if (email != null) cmd.Parameters.AddWithValue("@email", email); //if (image != null) cmd.Parameters.AddWithValue("@image", image); //if (password != null) cmd.Parameters.AddWithValue("@salt", getRandomSalt()); //if (money != null) cmd.Parameters.AddWithValue("@money", money); //if (rankToAdd != null) cmd.Parameters.AddWithValue("@rankToAdd", rankToAdd); //connection.Open(); //bool ans = cmd.ExecuteNonQuery() > 0; //connection.Close(); //return ans; }
public SystemUserViewModel GetById(int id) { return(_mapper.Map <SystemUser, SystemUserViewModel>(_systemUserRepository.GetById(id))); }