private CharacterTagSectionDto BuildTagSection(Character character, CharacterTagEntryType type, string userId) { var sectionDto = new CharacterTagSectionDto { CharacterId = character.Id, GameId = character.GameId, TagEntryType = type, Tags = character.TagEntries .Where(t => t.Type == type) .GroupBy(s => s.LinkedTag) .Select(ge => new CharacterTagDto { ID = ge.Key.Id, Name = ge.Key.Name, Type = ge.Key.Type, Timestamp = ((DateTimeOffset)ge.Key.CreatedDate).ToUnixTimeSeconds(), TagCount = ge.Count(), UserSelected = userId != null && ge.Any(s => s.User.Id == userId) }) }; switch (type) { case CharacterTagEntryType.Main: sectionDto.Title = "Tags"; sectionDto.Description = "<b>Main Tags</b><br/>In this section we add tags related to playstyle, mechanics or theme.<br/><br/>" + SectionDescriptionConstants.TagEntrySection; break; default: throw new NotImplementedException(); } return(sectionDto); }
public async Task <bool> RemoveCharacterTagEntryAsync(CharacterTagEntryType type, string userId, int characterId, int tagId) { var user = await Context.Users.FindAsync(userId); var character = await Context.Characters.FindAsync(characterId); var tag = await Context.Tags.FindAsync(tagId); if (user == null || character == null || tag == null) { return(false); } var mainTag = character.TagEntries.FirstOrDefault(e => e.Type == type && e.LinkedTag.Id == tag.Id && e.User == user); if (mainTag == null) { return(false); } character.TagEntries.Remove(mainTag); Context.Update(character); await Context.SaveChangesAsync(); await _tagService.TryDeleteAsync(tag.Id); return(true); }
public async Task <bool> AddReplaceCharacterTagEntryAsync(CharacterTagEntryType type, string userId, int characterId, string tagText) { var character = await Context.Characters.FindAsync(characterId); var tag = await _tagService.GetOrCreateTagAsync(tagText); var user = await Context.Users.FindAsync(userId); if (user == null || character == null || tag == null) { return(false); } var mainTag = character.TagEntries.FirstOrDefault(e => e.Type == type && e.LinkedTag.Id == tag.Id && e.User == user); if (mainTag != null) { character.TagEntries.Remove(mainTag); } character.TagEntries.Add(new CharacterTagEntry { Character = character, LinkedTag = tag, User = user, Type = type }); Context.Update(character); await Context.SaveChangesAsync(); return(true); }
public async Task <IActionResult> RemoveTagEntry(CharacterTagEntryType entryType, int id, int tagId) { var userId = this.User.FindFirstValue(ClaimTypes.NameIdentifier); await _entryService.RemoveCharacterTagEntryAsync(entryType, userId, id, tagId); return(RedirectToAction("Index", new { id = id })); }