public void Seed() { var encryptor = new HashPasswordEncryptor(); var admiRole = new Role(Guid.NewGuid(), "Administrator"); var basicRole = new Role(Guid.NewGuid(), "Basic"); var userEmailLogin = new UserEmailLogin("Test User", "*****@*****.**", encryptor.Encrypt("password"), "615-555-1212"); userEmailLogin.AddRol(basicRole); var administratorUser = new UserEmailLogin("Admin User", "*****@*****.**", encryptor.Encrypt("password"), "123"); administratorUser.AddRol(admiRole); administratorUser.AddRol(basicRole); var userAbility = new UserAbility("Developer"); _session.Save(userAbility); userEmailLogin.AddAbility(userAbility); _session.Save(admiRole); _session.Save(basicRole); _session.Save(userEmailLogin); _session.Save(administratorUser); }
public async Task Handle(IUserSession userIssuingCommand, AddAbilitiesToUser command) { User user = await _userReadRepo.GetById <User>(command.UserId); var abilities = new List <UserAbility>(); foreach (Guid abilityId in command.Abilities) { UserAbility userAbility = await _abilityReadRepo.GetById(abilityId); abilities.Add(userAbility); user.AddAbility(userAbility); } await _userReadRepo.Update(user); NotifyObservers(new UserAbilitiesAdded(user.Id, abilities.Select(x => x.Id))); }
/// <summary> /// 添加玩家魂技 /// </summary> /// <param name="abilityId"></param> /// <param name="userId"></param> public static void AddUserAbility(int abilityId, int userId, int generalID, int position) { var userAbility = _cacheSetAbility.FindKey(userId.ToString()); var ability = userAbility != null && userAbility.AbilityList != null ? userAbility.AbilityList.Find(s => s.AbilityID == abilityId) : null; var abilityLv = new ShareCacheStruct <AbilityLvInfo>().FindKey(abilityId, 1); int experienceNum = abilityLv != null ? abilityLv.Experience : 0; if (userAbility == null) { userAbility = new UserAbility(userId); ability = new Ability(); userAbility.CreateDate = DateTime.Now; ability.UserItemID = Guid.NewGuid().ToString(); ability.AbilityID = abilityId; ability.AbilityLv = 1; ability.GeneralID = generalID; ability.ExperienceNum = experienceNum; ability.Position = position; userAbility.AbilityList.Add(ability); _cacheSetAbility.Add(userAbility); // 添加到玩家集邮册 UserAlbumHelper.AddUserAlbum(userId.ToString(), AlbumType.Ability, abilityId); } else { ability = new Ability(); ability.UserItemID = Guid.NewGuid().ToString(); userAbility.CreateDate = DateTime.Now; ability.AbilityID = abilityId; ability.AbilityLv = 1; ability.GeneralID = generalID; ability.Position = position; ability.ExperienceNum = experienceNum; userAbility.AbilityList.Add(ability); // 添加到玩家集邮册 UserAlbumHelper.AddUserAlbum(userId.ToString(), AlbumType.Ability, abilityId); } UserAlbumHelper.AddUserAlbum(userId.ToString(), AlbumType.General, generalID); }
public async Task Handle(IUserSession userIssuingCommand, CreateEmailLoginUser command) { var userCreated = new UserEmailLogin(Guid.NewGuid(), command.Name, command.Email, command.EncryptedPassword, command.PhoneNumber); foreach (UserAbility ability in command.Abilities) { UserAbility userAbility = await _abilityReadRepo.GetById(ability.Id); userCreated.AddAbility(userAbility); } Role basicRole = await _roleReadRepo.First(x => x.Description == "Basic"); userCreated.AddRole(basicRole); User userSaved = await _userRepo.Create(userCreated); NotifyObservers(new UserEmailCreated(userSaved.Id, command.Email, command.Name, command.PhoneNumber)); }
/// <summary> /// 添加玩家魂技 /// </summary> /// <param name="abilityId"></param> /// <param name="userId"></param> private void AddUserAbility(int abilityId, int userId, int generalID, int position) { GameDataCacheSet <UserAbility> _cacheSetAbility = new GameDataCacheSet <UserAbility>(); var userAbility = _cacheSetAbility.FindKey(userId.ToString()); var ability = userAbility != null && userAbility.AbilityList != null ? userAbility.AbilityList.Find(s => s.AbilityID == abilityId) : null; var abilityLv = new ConfigCacheSet <AbilityLvInfo>().FindKey(abilityId, 1); int experienceNum = abilityLv != null ? abilityLv.Experience : 0; if (userAbility == null) { userAbility = new UserAbility(userId); ability = new Ability(); userAbility.CreateDate = DateTime.Now; ability.UserItemID = Guid.NewGuid().ToString(); ability.AbilityID = abilityId; ability.AbilityLv = 1; ability.GeneralID = generalID; ability.ExperienceNum = experienceNum; ability.Position = position; userAbility.AbilityList.Add(ability); _cacheSetAbility.Add(userAbility, GameEnvironment.CacheUserPeriod); } else { ability = new Ability(); ability.UserItemID = Guid.NewGuid().ToString(); userAbility.CreateDate = DateTime.Now; ability.AbilityID = abilityId; ability.AbilityLv = 1; ability.GeneralID = generalID; ability.Position = position; ability.ExperienceNum = experienceNum; userAbility.AbilityList.Add(ability); } }
public async Task <IActionResult> Index() { //从数据库提取用户 User user = await _context.User.SingleOrDefaultAsync(m => m.name == User.Identity.Name); //从数据库中提取人员基本信息表, var bodyAbility = from bb in _context.BodyAbility select bb; bodyAbility = bodyAbility.Where(m => m.user_id == User.Identity.Name); List <BodyAbility> b = await bodyAbility.AsNoTracking().ToListAsync(); UserAbility list = new UserAbility(user, b); foreach (var x in b) { list.listtime.Add(x.create_time.Date.ToString("yyyy-MM-dd")); List <string> item1 = new List <string>(); List <List <string> > temp = new List <List <string> >(); item1.Add(x.bfp.ToString()); item1.Add(x.bmi.ToString()); item1.Add((x.weight * 1000000).ToString()); item1.Add(x.user_id.ToString()); item1.Add(x.create_time.Date.ToString("yyyy-MM-dd")); temp.Add(item1); list.series.Add(temp); } return(View(list)); }
public override void ExecuteCommand(EvtChatCommandArgs args) { List <string> arguments = args.Command.ArgumentsAsList; if (arguments.Count != 3 && arguments.Count != 6) { QueueMessage(UsageMessage); return; } //Get the user calling this string thisUserName = args.Command.ChatMessage.Username.ToLowerInvariant(); string abilityUserName = arguments[0].ToLowerInvariant(); string abilityName = arguments[1].ToLowerInvariant(); string abilityEnabledStr = arguments[2].ToLowerInvariant(); User thisUser = DataHelper.GetUser(thisUserName); User abilityUser = DataHelper.GetUser(abilityUserName); if (abilityUser == null) { QueueMessage("This user doesn't exist in the database!"); return; } PermissionAbility permAbility = null; using (BotDBContext context = DatabaseManager.OpenContext()) { permAbility = context.PermAbilities.FirstOrDefault(p => p.Name == abilityName); } if (permAbility == null) { QueueMessage($"There is no permission ability named \"{abilityName}\"."); return; } if (thisUser.Name != abilityUser.Name && thisUser.Level <= abilityUser.Level) { QueueMessage("You cannot modify abilities for other users with levels greater than or equal to yours!"); return; } if ((long)permAbility.AutoGrantOnLevel > thisUser.Level) { QueueMessage("This ability isn't available to your level, so you cannot grant it!"); return; } if ((long)permAbility.MinLevelToGrant > thisUser.Level) { QueueMessage($"You need to be at least level {(long)permAbility.MinLevelToGrant}, {permAbility.MinLevelToGrant}, to grant this ability."); return; } if (bool.TryParse(abilityEnabledStr, out bool enabledState) == false) { QueueMessage("Invalid enabled state."); return; } string valueStrArg = string.Empty; string valueIntArg = string.Empty; string expirationArg = string.Empty; int valueInt = 0; using (BotDBContext context = DatabaseManager.OpenContext()) { UserAbility newUserAbility = null; abilityUser = DataHelper.GetUserNoOpen(abilityUserName, context); abilityUser.TryGetAbility(abilityName, out newUserAbility); bool shouldAdd = false; if (newUserAbility == null) { //TRBotLogger.Logger.Information($"New ability {abilityName}"); newUserAbility = new UserAbility(); shouldAdd = true; } newUserAbility.PermabilityID = permAbility.ID; newUserAbility.UserID = abilityUser.ID; newUserAbility.GrantedByLevel = thisUser.Level; newUserAbility.SetEnabledState(enabledState); //If there are only three arguments, enable/disable the ability if (arguments.Count == 3) { if (shouldAdd == true) { //TRBotLogger.Logger.Information($"Adding ability {abilityName}"); abilityUser.UserAbilities.Add(newUserAbility); } if (enabledState == true) { QueueMessage($"Enabled the \"{abilityName}\" ability for {abilityUser.Name}!"); } else { QueueMessage($"Disabled the \"{abilityName}\" ability for {abilityUser.Name}!"); } //Save and exit here context.SaveChanges(); return; } valueStrArg = arguments[3]; valueIntArg = arguments[4]; expirationArg = arguments[5].ToLowerInvariant(); newUserAbility.ValueStr = valueStrArg; //Validate arguments if (int.TryParse(valueIntArg, out valueInt) == false) { QueueMessage("Invalid value_int argument."); return; } newUserAbility.ValueInt = valueInt; if (expirationArg == NULL_EXPIRATION_ARG) { newUserAbility.Expiration = null; } else { if (Helpers.TryParseTimeModifierFromStr(expirationArg, out TimeSpan timeFromNow) == false) { QueueMessage("Unable to parse expiration time from now."); return; } //Set the time to this amount from now newUserAbility.Expiration = DateTime.UtcNow + timeFromNow; } //Add if we should if (shouldAdd == true) { abilityUser.UserAbilities.Add(newUserAbility); } //Save changes context.SaveChanges(); } if (enabledState == true) { QueueMessage($"Enabled the \"{abilityName}\" ability to {abilityUser.Name} with values ({valueStrArg}, {valueInt}) and expires in {expirationArg}!"); } else { QueueMessage($"Disabled the \"{abilityName}\" ability on {abilityUser.Name} with values ({valueStrArg}, {valueInt}) and expires in {expirationArg}!"); } }
public virtual void AddAbility(UserAbility ability) { ((IList <UserAbility>)_userAbilities).Add(ability); }
public override void ExecuteCommand(EvtChatCommandArgs args) { List <string> arguments = args.Command.ArgumentsAsList; //This supports listing another user's abilities if provided as an argument, but only one user at a time if (arguments.Count > 1) { QueueMessage(UsageMessage); return; } //Get the user calling this string thisUserName = args.Command.ChatMessage.Username.ToLowerInvariant(); string listedName = thisUserName; //Check to list another user's abilities if (arguments.Count == 1) { listedName = arguments[0].ToLowerInvariant(); } StringBuilder strBuilder = null; using (BotDBContext context = DatabaseManager.OpenContext()) { User user = DataHelper.GetUserNoOpen(listedName, context); if (user == null) { QueueMessage("A user with this name does not exist in the database!"); return; } //No abilities if (user.UserAbilities.Count == 0) { QueueMessage($"{user.Name} has no abilities!"); return; } DateTime now = DateTime.UtcNow; strBuilder = new StringBuilder(250); strBuilder.Append(user.Name).Append("'s abilities: "); for (int i = 0; i < user.UserAbilities.Count; i++) { UserAbility ability = user.UserAbilities[i]; //if (ability.IsEnabled == false && ability.HasExpiration == false) //{ // continue; //} strBuilder.Append(ability.PermAbility.Name); if (ability.IsEnabled == false) { strBuilder.Append(" (disabled)"); } if (ability.HasExpired == false && ability.HasExpiration == true) { strBuilder.Append(" (exp: ").Append(ability.Expiration.Value.ToString()).Append(" UTC)"); } strBuilder.Append(',').Append(' '); } } strBuilder.Remove(strBuilder.Length - 2, 2); int maxCharCount = (int)DataHelper.GetSettingInt(SettingsConstants.BOT_MSG_CHAR_LIMIT, 500L); QueueMessageSplit(strBuilder.ToString(), maxCharCount, ", "); }