Exemplo n.º 1
0
        public async Task <bool> RemoveCharacterStringEntryAsync(CharacterStringEntryType type, string userId, int characterId, int entryId)
        {
            var user = await Context.Users.FindAsync(userId);

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

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

            var value = character.StringEntries.FirstOrDefault(e => e.Type == type && e.Id == entryId && e.User == user);

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

            value.Votes.Clear();
            character.StringEntries.Remove(value);
            Context.Update(character);
            await Context.SaveChangesAsync();

            return(true);
        }
Exemplo n.º 2
0
        public async Task <bool> AddReplaceCharacterStringEntryAsync(CharacterStringEntryType type, string userId, int characterId, string text)
        {
            var character = await Context.Characters.FindAsync(characterId);

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

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

            var value = character.StringEntries.FirstOrDefault(e => e.Type == type && e.Text == text && e.User == user);

            if (value != null)
            {
                character.StringEntries.Remove(value);
            }

            character.StringEntries.Add(new CharacterStringEntry
            {
                Character = character,
                Text      = text,
                User      = user,
                Type      = type
            });
            Context.Update(character);
            await Context.SaveChangesAsync();

            return(true);
        }
Exemplo n.º 3
0
        public async Task <IActionResult> RemoveStringEntryVote(CharacterStringEntryType entryType, int id, int entryId)
        {
            var userId = this.User.FindFirstValue(ClaimTypes.NameIdentifier);
            await _entryService.RemoveCharacterStringEntryVoteAsync(entryType, userId, id, entryId);

            return(RedirectToAction("Index", new { id = id }));
        }
Exemplo n.º 4
0
        public async Task <IActionResult> AddStringEntry(CharacterStringEntryType entryType, int id, string text)
        {
            var userId = this.User.FindFirstValue(ClaimTypes.NameIdentifier);

            if (!string.IsNullOrWhiteSpace(text))
            {
                await _entryService.AddReplaceCharacterStringEntryAsync(entryType, userId, id, text);
            }

            return(RedirectToAction("Index", new { id = id }));
        }
Exemplo n.º 5
0
        public async Task <bool> RemoveCharacterStringEntryVoteAsync(CharacterStringEntryType type, string userId, int characterId, int entryId)
        {
            var character = await Context.Characters.FindAsync(characterId);

            var entry = character?.StringEntries.SingleOrDefault(t => t.Type == type && t.Id == entryId);
            var vote  = entry?.Votes.SingleOrDefault(v => v.User.Id == userId);

            if (character == null || entry == null || vote == null)
            {
                return(false);
            }

            entry.Votes.Remove(vote);
            Context.Update(character);
            await Context.SaveChangesAsync();

            return(true);
        }
Exemplo n.º 6
0
        private CharacterStringSectionDto BuildStringSection(Character character, CharacterStringEntryType type, string userID)
        {
            var characterStrings = character.StringEntries
                                   .Where(s => s.Type == type)
                                   .Select(ge =>
                                           new CharacterStringDto
            {
                ID   = ge.Id,
                Text = ge.Text,
                CreatorDisplayName = string.IsNullOrEmpty(ge.User.DisplayName) ? "Anonymous" : ge.User.DisplayName,
                CreatorAvatarIcon  = ge.User.AvatarIconId,
                UserCreated        = ge.User.Id == userID,
                UserSelected       = ge.Votes.Any(v => v.User.Id == userID),
                ValueCount         = ge.Votes.Count()
            })
                                   .OrderBy(ge => ge.ValueCount);


            var sectionDto = new CharacterStringSectionDto
            {
                CharacterId     = character.Id,
                GameId          = character.GameId,
                StringEntryType = type,
                Values          = characterStrings
            };

            switch (type)
            {
            case CharacterStringEntryType.Tips:
                sectionDto.Title       = "Tips & Tricks";
                sectionDto.Description = $"<b>Tips & Tricks</b><br/>In this section we list tips and tricks for {character.Name}.<br/><br/>" + SectionDescriptionConstants.StringEntrySection;
                break;

            default:
                throw new NotImplementedException();
            }


            return(sectionDto);
        }