public async Task Remove(CommandContext context, [Description(Descriptions.WowCharacter)] UserWowCharacter character, [Description(Descriptions.WowProfession)] WowProfession profession, [Description("Confirm that you would like to remove this profession and all associated recipes.")] bool removeAllRecipes) { if (!removeAllRecipes) { ResponseString = "You must pass 'true' for removeAllRecipes to confirm."; return; } var charProfession = character.Character.WowCharacterProfessions .FirstOrDefault(x => x.WowProfessionId == profession.Id); if (charProfession != null) { var recipes = character.Character.WowCharacterProfessions .Where(x => x.WowProfessionId == profession.Id) .SelectMany(x => x.WowCharacterRecipes); m_dbContext.WowCharacterRecipes.RemoveRange(recipes); m_dbContext.WowCharacterProfessions.Remove(charProfession); await m_dbContext.SaveChangesAsync(); } }
public async Task Add(CommandContext context, [Description(Descriptions.WowCharacter)] UserWowCharacter character, [Description(Descriptions.WowProfession)] WowProfession profession, [Description(Descriptions.WowItemRecipe)][RemainingText] WowItemRecipe recipe) { var characterProfession = character.Character.WowCharacterProfessions .FirstOrDefault(x => x.WowProfessionId == profession.Id); if (characterProfession == null) { ResponseString = $"{character.Character} does not know {profession}"; return; } var charRecipe = character.Character.WowCharacterProfessions .FirstOrDefault(x => x.WowProfessionId == profession.Id) ?.WowCharacterRecipes .FirstOrDefault(x => x.RecipeId == recipe.Recipe.Id); if (charRecipe != null) { return; } charRecipe = new WowCharacterRecipe() { WowCharacterProfession = characterProfession, Recipe = recipe.Recipe, }; m_dbContext.WowCharacterRecipes.Add(charRecipe); await m_dbContext.SaveChangesAsync(); }
public Task List(CommandContext context, [Description(Descriptions.WowProfession)] WowProfession profession) { var characters = Guild.WowServer.WowCharacters .Where(x => x.WowCharacterProfessions .Any(x => x.WowProfessionId == profession.Id)); StringBuilder message = new StringBuilder($"__**{profession}**__\n"); foreach (var character in characters) { message.Append($"{character}\n"); } ResponseString = message.ToString(); return(Task.CompletedTask); }
public async Task Add(CommandContext context, [Description(Descriptions.WowCharacter)] UserWowCharacter character, [Description(Descriptions.WowProfession)] WowProfession profession) { if (character.Character.WowCharacterProfessions.Any(x => x.WowProfessionId == profession.Id)) { return; } m_dbContext.WowCharacterProfessions.Add(new WowCharacterProfession() { WowCharacterId = character.Character.Id, WowProfessionId = profession.Id, }); await m_dbContext.SaveChangesAsync(); }
public async Task Remove(CommandContext context, [Description(Descriptions.WowCharacter)] UserWowCharacter character, [Description(Descriptions.WowProfession)] WowProfession profession, [Description(Descriptions.WowItemRecipe)][RemainingText] WowItemRecipe recipe) { var charRecipe = character.Character.WowCharacterProfessions .FirstOrDefault(x => x.WowProfessionId == profession.Id) ?.WowCharacterRecipes .FirstOrDefault(x => x.RecipeId == recipe.Recipe.Id); if (charRecipe != null) { m_dbContext.WowCharacterRecipes.Remove(charRecipe); await m_dbContext.SaveChangesAsync(); } else { ResponseString = "Recipe not found"; return; } }
public async Task <WowTrackerUser> AddOrUpdateProfession(ulong guildSnowflake, ulong userSnowflake, WowProfession professionType, int level) { if (level < 0 || level > 300) { throw new ArgumentException("Profession levels must be between 1 and 300"); } var user = await _db.Users .Include(u => u.Professions) .Where(u => u.Guild.Snowflake == guildSnowflake) .FirstOrDefaultAsync(u => u.Snowflake.Equals(userSnowflake)); var profession = user.Professions.FirstOrDefault(p => p.ProfessionType == professionType); if (profession == null) { profession = new Profession { ProfessionType = professionType, Level = level }; user.Professions.Add(profession); _db.Professions.Add(profession); } else { profession.Level = level; _db.Professions.Update(profession); } var updatedUser = _db.Users.Update(user); await _db.SaveChangesAsync().ConfigureAwait(false); return(updatedUser.Entity); }
public async Task DeleteProfession(ulong guildSnowflake, ulong userSnowflake, WowProfession professionType) { var user = await _db.Users .Include(u => u.Professions) .Where(u => u.Guild.Snowflake == guildSnowflake) .FirstOrDefaultAsync(u => u.Snowflake == userSnowflake); if (user == null) { return; } var profession = user.Professions.FirstOrDefault(p => p.ProfessionType == professionType); user.Professions.Remove(profession); await _db.SaveChangesAsync().ConfigureAwait(false); }
public async Task <IEnumerable <ProfessionTopResult> > GetProfessionTop5(ulong guildSnowflake, WowProfession professionType) { return(await _db.Professions .Include(p => p.User) .Where(p => p.User.Guild.Snowflake == guildSnowflake) .Where(p => p.ProfessionType == professionType) .OrderByDescending(p => p.Level) .Take(5) .Select(p => new ProfessionTopResult { Profession = p.ProfessionType, level = p.Level, Snowflake = p.User.Snowflake }) .ToListAsync().ConfigureAwait(false)); }