Example #1
0
        public async Task <int> CreateGuildProfileAsync(
            string creatorId,
            string profileName,
            GuildSlim guild,
            EfModels.StoredBlizzardModels.StoredRealm realm,
            EfEnums.GameRegionEnum region,
            bool isPublic)
        {
            using (var transaction = await this.context.Database.BeginTransactionAsync())
            {
                var newProfile = new EF.Models.GuildProfile()
                {
                    CreatorId   = creatorId,
                    ProfileName = profileName,
                    RealmId     = realm.Id,
                    IsPublic    = isPublic
                };

                this.context.GuildProfile.Add(newProfile);

                await this.context.SaveChangesAsync();

                EfModels.StoredBlizzardModels.StoredGuild storedGuild = new EfModels.StoredBlizzardModels.StoredGuild()
                {
                    Name      = guild.Name,
                    RealmId   = realm.Id,
                    ProfileId = newProfile.Id
                };

                this.context.StoredGuilds.Add(storedGuild);
                newProfile.CreatorGuild = storedGuild;

                if (!isPublic)
                {
                    this.context.User_GuildProfilePermissions.Add(new EF.Models.User_GuildProfilePermissions()
                    {
                        PermissionLevelId = (int)EF.Models.Enums.GuildProfilePermissionLevel.Admin,
                        ProfileId         = newProfile.Id,
                        UserId            = creatorId
                    });
                }

                await this.context.SaveChangesAsync();

                transaction.Commit();

                return(newProfile.Id);
            }
        }
Example #2
0
        public async Task <EfModels.FriendGuild> AddFriendGuild(int profileId, EfModels.StoredBlizzardModels.StoredGuild storedGuild)
        {
            var profile = await this.context.GuildProfile
                          .Include(x => x.FriendGuilds)
                          .FirstOrDefaultAsync(x => x.Id == profileId);

            if (profile.CreatorGuildId == storedGuild.Id)
            {
                throw new UserReportableError("Guild profile is already targeting this guild.", (int)HttpStatusCode.BadRequest);
            }

            if (profile.FriendGuilds.Any(x => x.StoredGuildId == storedGuild.Id))
            {
                throw new UserReportableError("This guild is already associated as a friend guild.", (int)HttpStatusCode.BadRequest);
            }

            string abbreviation = storedGuild.Name.Substring(0, Math.Min(storedGuild.Name.Length, 3)).ToUpper();

            var newFriendGuild = new EfModels.FriendGuild()
            {
                ProfileId     = profileId,
                StoredGuildId = storedGuild.Id
            };

            storedGuild.Abbreviation = abbreviation;

            this.context.FriendGuilds.Add(newFriendGuild);

            await this.context.SaveChangesAsync();

            return(await this.context.FriendGuilds
                   .Include(x => x.Guild)
                   .ThenInclude(x => x.Realm)
                   .ThenInclude(x => x.Region)
                   .SingleAsync(x => x.Id == newFriendGuild.Id));
        }
Example #3
0
        private async Task <IEnumerable <EfBlizzardModels.StoredPlayer> > GetOrInsertProfileGuildMembers(int profileId, EfBlizzardModels.StoredGuild guild, EfBlizzardModels.StoredRealm realm, EfEnums.GameRegionEnum region)
        {
            var members = await this.guildMemberCache.GetMembers(region, realm.Name, guild.Name);

            var realmNames = members.Select(x => x.PlayerRealmName).Distinct();

            var realmsTasks = realmNames.Select(async x => await this.realmStoreByValues.GetRealmAsync(x, region));
            await Task.WhenAll(realmsTasks);

            var realms = realmsTasks.Select(x => x.Result);

            var newPlayers = await this.dataRepo.InsertGuildPlayersIfNeededAsync(members.Select(x =>
                                                                                                new EfBlizzardModels.StoredPlayer()
            {
                Name      = x.PlayerName,
                Class     = x.Class,
                Level     = x.Level,
                GuildId   = guild.Id,
                RealmId   = realms.SingleOrDefault(y => y.Name == x.PlayerRealmName).Id,
                ProfileId = profileId
            }),
                                                                                 profileId,
                                                                                 guild.Id);

            return(newPlayers);
        }