private CharacterValueSectionDto BuildValueSection(Character character, CharacterValueEntryType type, string userId) { var characterValues = character.ValueEntries .Where(v => v.Type == type) .GroupBy(s => s.Value) .Select(ge => new CharacterValueDto { ID = ge.Key, Name = GetValueName(ge.Key, type), ValueCount = ge.Count(), UserSelected = userId != null && ge.Any(s => s.User.Id == userId) }).OrderBy(ge => ge.ValueCount); var sectionDto = new CharacterValueSectionDto { CharacterId = character.Id, GameId = character.GameId, ValueEntryType = type, }; switch (type) { case CharacterValueEntryType.Tier: sectionDto.Title = "Tier List"; sectionDto.Description = $"<b>Tier List</b><br/>In this section we select one of the tiers to indicate the overall strength of {character.Name}.<br/><br/>" + SectionDescriptionConstants.EnumEntrySection; sectionDto.Values = characterValues.Union(CharacterTier.A.GetListForEnum().Where(e => !characterValues.Select(ce => ce.ID).Contains(e.ID))).OrderBy(ce => ce.ID); break; default: throw new NotImplementedException(); } return(sectionDto); }
public async Task <bool> AddReplaceCharacterValueEntryAsync(CharacterValueEntryType type, string userId, int characterId, int valueValue) { var character = await Context.Characters.FindAsync(characterId); var user = await Context.Users.FindAsync(userId); if (user == null || character == null) { return(false); } var enumEntry = character.ValueEntries.FirstOrDefault(e => e.Type == type && e.User == user); if (enumEntry != null) { character.ValueEntries.Remove(enumEntry); } character.ValueEntries.Add(new CharacterValueEntry { Character = character, Value = valueValue, User = user, Type = type }); Context.Update(character); await Context.SaveChangesAsync(); return(true); }
public async Task <IActionResult> RemoveValueEntry(CharacterValueEntryType entryType, int id, int val) { var userId = this.User.FindFirstValue(ClaimTypes.NameIdentifier); await _entryService.RemoveCharacterValueEntryAsync(entryType, userId, id, val); return(RedirectToAction("Index", new { id = id })); }
private string GetValueName(int value, CharacterValueEntryType type) { switch (type) { case CharacterValueEntryType.Tier: return(((CharacterTier)value).GetDisplayName()); default: throw new NotImplementedException(); } }
public async Task <bool> RemoveCharacterValueEntryAsync(CharacterValueEntryType type, string userId, int characterId, int enumVal) { var user = await Context.Users.FindAsync(userId); var character = await Context.Characters.FindAsync(characterId); if (user == null || character == null) { return(false); } var value = character.ValueEntries.FirstOrDefault(e => e.Type == type && e.Value == enumVal && e.User == user); if (value == null) { return(false); } character.ValueEntries.Remove(value); Context.Update(character); await Context.SaveChangesAsync(); return(true); }