Example #1
0
        public async Task <bool> RemoveCharacterLinkEntryAsync(CharacterLinkEntryType type, string userId, int characterId, int linkedCharacterId)
        {
            var user = await Context.Users.FindAsync(userId);

            var character = await Context.Characters.FindAsync(characterId);

            var linkedCharacter = await Context.Characters.FindAsync(linkedCharacterId);

            if (user == null || character == null || linkedCharacter == null)
            {
                return(false);
            }

            var linkEntry = character.LinkEntries.FirstOrDefault(e => e.Type == type & e.LinkedCharacter.Id == linkedCharacter.Id && e.User == user);

            if (linkEntry == null)
            {
                return(false);
            }

            character.LinkEntries.Remove(linkEntry);
            Context.Update(character);
            await Context.SaveChangesAsync();

            return(true);
        }
Example #2
0
        public async Task <bool> AddReplaceCharacterLinkEntryAsync(CharacterLinkEntryType type, string userId, int characterId, int linkedCharacterId)
        {
            var character = await Context.Characters.FindAsync(characterId);

            var linkedCharacter = await Context.Characters.FindAsync(linkedCharacterId);

            var user = await Context.Users.FindAsync(userId);

            if (user == null || character == null || linkedCharacter == null || (type != CharacterLinkEntryType.SimilarInGenre && character.Game != linkedCharacter.Game))
            {
                return(false);
            }

            var linkEntry = character.LinkEntries.FirstOrDefault(e => e.Type == type && e.LinkedCharacter.Id == linkedCharacter.Id && e.User == user);

            if (linkEntry != null)
            {
                character.LinkEntries.Remove(linkEntry);
            }

            character.LinkEntries.Add(new CharacterLinkEntry
            {
                Character       = character,
                LinkedCharacter = linkedCharacter,
                User            = user,
                Type            = type
            });
            Context.Update(character);
            await Context.SaveChangesAsync();

            return(true);
        }
Example #3
0
        public async Task <IActionResult> RemoveCharacterLinkEntry(CharacterLinkEntryType entryType, int id, int linkId)
        {
            var userId = this.User.FindFirstValue(ClaimTypes.NameIdentifier);
            await _entryService.RemoveCharacterLinkEntryAsync(entryType, userId, id, linkId);

            return(RedirectToAction("Index", new { id = id }));
        }
Example #4
0
        private CharacterLinkSectionDto BuilderCharacterLinkSection(Character character, CharacterLinkEntryType type, IEnumerable <BaseCharacterDto> characters, string userId)
        {
            var linkEntries = character.LinkEntries
                              .Where(e => e.Type == type)
                              .GroupBy(s => s.LinkedCharacter)
                              .Select(ge => new CharacterLinkDto
            {
                ID           = ge.Key.Id,
                GameId       = ge.Key.GameId,
                GameName     = ge.Key.Game.Name,
                Name         = ge.Key.Name,
                LinkCount    = ge.Count(),
                UserSelected = userId != null && ge.Any(s => s.User.Id == userId)
            });

            characters = type == CharacterLinkEntryType.SimilarInGenre ? characters.Where(c => c.GameId != character.GameId) : characters.Where(c => c.GameId == character.GameId);

            var sectionDto = new CharacterLinkSectionDto
            {
                CharacterId         = character.Id,
                GameId              = character.GameId,
                LinkEntryType       = type,
                Links               = linkEntries,
                AvaliableCharacters = characters.Select(c => new CharacterLinkDto
                {
                    ID           = c.Id,
                    GameId       = c.GameId,
                    GameName     = c.GameName,
                    Name         = c.Name,
                    LinkCount    = linkEntries.SingleOrDefault(l => l.ID == c.Id)?.LinkCount ?? 0,
                    UserSelected = linkEntries.SingleOrDefault(l => l.ID == c.Id)?.UserSelected ?? false
                })
            };

            switch (type)
            {
            case CharacterLinkEntryType.SimilarInGame:
                sectionDto.Title       = "Similar In Game";
                sectionDto.Description = "<b>Similar In Game</b><br/>In this section we link to similar characters based on playstyle/mechanics or theme.<br/><br/>" + SectionDescriptionConstants.CharacterLinkSection;
                break;

            case CharacterLinkEntryType.SimilarInGenre:
                sectionDto.Title       = "Similar In Genre";
                sectionDto.Description = "<b>Similar In Genre</b><br/>In this section we link to similar characters based on playstyle/mechanics or theme. Options for this section are based on the useless network collection of games and characters which should be updated regularly.<br/><br/>" + SectionDescriptionConstants.CharacterLinkSection;
                break;

            case CharacterLinkEntryType.CounteredBy:
                sectionDto.Title       = "Countered By";
                sectionDto.Description = $"<b>Countered By</b><br/>In this section we link to charaters that counter {character.Name}.<br/><br/>" + SectionDescriptionConstants.CharacterLinkSection;
                break;

            case CharacterLinkEntryType.StrongAgainst:
                sectionDto.Title       = "Strong Against";
                sectionDto.Description = $"<b>Strong Against</b><br/>In this section we link to charaters that are strong against {character.Name}.<br/><br/>" + SectionDescriptionConstants.CharacterLinkSection;
                break;

            case CharacterLinkEntryType.SynergizesWith:
                sectionDto.Title       = "Synergizes With";
                sectionDto.Description = $"<b>Synergizes With</b><br/>In this section we link to charaters that synergize well with {character.Name}.<br/><br/>" + SectionDescriptionConstants.CharacterLinkSection;
                break;

            default:
                throw new NotImplementedException();
            }

            return(sectionDto);
        }