public async Task <FriendGuild> AddFriendGuild([FromBody] AddFriendGuild input) { InputValidators.ValidateGuildName(input.GuildName); InputValidators.ValidateRealmName(input.RealmName); input.GuildName = BlizzardService.FormatGuildName(input.GuildName); input.RealmName = BlizzardService.FormatRealmName(input.RealmName); var regionEnum = GameRegionUtilities.GetGameRegionFromString(input.RegionName); var user = await this.userManager.GetUserAsync(HttpContext.User); if (!(await this.UserCanAddRemoveFriendGuilds(input.ProfileId, user))) { throw new UserReportableError($"This user does not have permission to add friend guilds for profile '{input.ProfileId}'.", (int)HttpStatusCode.Unauthorized); } var storedRealm = await this.realmStoreByValues.GetRealmAsync(input.RealmName, regionEnum); if (storedRealm == null) { throw new UserReportableError($"Could not locate realm '{input.RealmName}'.", (int)HttpStatusCode.BadRequest); } var storedGuild = await this.guildStore.GetGuildAsync(input.GuildName, storedRealm, input.ProfileId); if (storedGuild == null) { throw new UserReportableError($"Could not locate guild '{input.GuildName}'.", (int)HttpStatusCode.BadRequest); } var efFriendGuild = await this.dataRepo.AddFriendGuild(input.ProfileId, storedGuild); return(this.mapper.Map <FriendGuild>(efFriendGuild)); }
public async Task <int> CreateGuildProfile([FromBody] CreateNewGuildProfile input) { InputValidators.ValidateProfileName(input.ProfileName); InputValidators.ValidateGuildName(input.GuildName); InputValidators.ValidateRealmName(input.GuildRealmName); input.GuildName = BlizzardService.FormatGuildName(input.GuildName); input.GuildRealmName = BlizzardService.FormatRealmName(input.GuildRealmName); var regionEnum = GameRegionUtilities.GetGameRegionFromString(input.RegionName); var user = await this.userManager.GetUserAsync(HttpContext.User); if (user == null && !input.IsPublic) { throw new UserReportableError("Must be authenticated to create a private profile.", (int)HttpStatusCode.Unauthorized); } var locatedRealm = await this.realmStoreByValues.GetRealmAsync(input.GuildRealmName, regionEnum); if (locatedRealm == null) { throw new UserReportableError($"Couldn't locate realm '{input.GuildRealmName}'.", 404); } var locatedGuild = await this.guildCache.GetGuild(regionEnum, input.GuildName, input.GuildRealmName); if (locatedGuild == null) { throw new UserReportableError("Could not locate this guild.", 404); } return(await this.dataRepo.CreateGuildProfileAsync(user?.Id, input.ProfileName, locatedGuild, locatedRealm, regionEnum, input.IsPublic)); }
public async Task <GuildFound> GuildExists(string region, string guild, string realm) { InputValidators.ValidateGuildName(guild); InputValidators.ValidateRealmName(realm); guild = BlizzardService.FormatGuildName(guild); realm = BlizzardService.FormatRealmName(realm); var regionEnum = GameRegionUtilities.GetGameRegionFromString(region); var locatedGuild = await this.guildCache.GetGuild(regionEnum, guild, realm); if (locatedGuild == null) { return(new GuildFound() { Found = false }); } return(new GuildFound() { Found = true, RealmName = locatedGuild.Realm, GuildName = locatedGuild.Name }); }
public async Task <PlayerFound> PlayerExists(string region, string playerName, string realm) { InputValidators.ValidateRealmName(realm); InputValidators.ValidatePlayerName(playerName); realm = BlizzardService.FormatRealmName(realm); var regionEnum = GameRegionUtilities.GetGameRegionFromString(region); var locatedPlayer = await this.playerCache.GetPlayer(regionEnum, playerName, realm); if (locatedPlayer == null) { return(new PlayerFound() { Found = false }); } return(new PlayerFound() { Found = true, PlayerDetails = locatedPlayer }); }