From 81d3be7dd87d4e974eb0976ba86ab1f598ff8b34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karol=20G=C3=B3rzy=C5=84ski?= Date: Tue, 12 Jan 2021 22:22:56 +0100 Subject: [PATCH] SES-155 Added endpoint that retuns basic infor for template character --- .../JsonData/characters_templates.json | 985 ++++++++++++++++++ .../SessionCompanion.Database.csproj | 4 - .../Intefraces/ICharacterService.cs | 3 + .../Services/CharacterService.cs | 30 +- .../CharacterFromTemplatesSimpleViewModel.cs | 28 + .../Controllers/CharacterController.cs | 31 +- 6 files changed, 1075 insertions(+), 6 deletions(-) create mode 100644 SessionCompanion/SessionCompanion.Database/JsonData/characters_templates.json create mode 100644 SessionCompanion/SessionCompanion.ViewModels/CharacterViewModels/CharacterFromTemplatesSimpleViewModel.cs diff --git a/SessionCompanion/SessionCompanion.Database/JsonData/characters_templates.json b/SessionCompanion/SessionCompanion.Database/JsonData/characters_templates.json new file mode 100644 index 0000000..c739b8f --- /dev/null +++ b/SessionCompanion/SessionCompanion.Database/JsonData/characters_templates.json @@ -0,0 +1,985 @@ +[ + { + "id": 1, + "userId": -1, + "statistics": { + "ExperiencePoints": 0, + "Level": 1, + "Speed": 4, + "Initiative": 2, + "HealthPoints": 8, + "CurrentHealthPoints": 8, + "ArmorClass": 5, + "Proficiency": 2 + }, + "biography": { + "Name": "Ulora", + "ClassId": 2, + "RaceId": 3, + "AlignmentId": "LawfulGood", + "BackgroundId": 2, + "Sex": "Female", + "Languages": "Common", + "background": { + "Origin": "No origin", + "History": "Nothing much" + } + }, + "characterWeapons": [ + { + "WeaponId": 11, + "InUse": true, + "HoldInRightHand": true, + "HoldInLeftHand": false + }, + { + "WeaponId": 12, + "InUse": false, + "HoldInRightHand": false, + "HoldInLeftHand": false + } + ], + "characterSpells": [ + { + "SpellId": 44 + }, + { + "SpellId": 57 + } + ], + "charisma": { + "Value": 5, + "Modification": -2, + "SavingThrows": 0, + "CanSavingThrows": false, + "Deception": 0, + "CanDeception": false, + "Intimidation": 0, + "CanIntimidation": false, + "Performance": 0, + "CanPerformance": false, + "Persuasion": 0, + "CanPersuasion": false + }, + "constitution": { + "Value": 12, + "Modification": 2, + "SavingThrows": 2, + "CanSaveThrows": true + }, + "dexterity": { + "Value": 15, + "Modification": 2, + "SavingThrows": 3, + "CanSaveThrows": true, + "Acrobatics": 3, + "CanAcrobatics": true, + "SleightOfHand": 2, + "CanSleightOfHand": true, + "Stealth": 3, + "canStealth": true + }, + "intelligence": { + "Value": 14, + "Modification": 4, + "SavingThrows": 2, + "CanSaveThrows": true, + "arcana": 2, + "canArcana": true, + "History": 4, + "CanHistory": true, + "Investigation": 3, + "CanInvestigation": true, + "Nature": 1, + "CanNature": true, + "Religion": 0, + "canReligion": false + }, + "strength": { + "Value": 8, + "Modification": -1, + "SavingThrows": 0, + "CanSaveThrows": false, + "Athletics": 0, + "canAthletics": false + }, + "wisdom": { + "Value": 10, + "Modification": 0, + "SavingThrows": 0, + "CanSaveThrows": false, + "AnimalHandling": 1, + "CanAnimalHandling": true, + "Insight": 0, + "canInsight": false, + "medicine": 0, + "CanMedicine": false, + "Perception": 2, + "CanPerception": true, + "Survival": 0, + "CanSurvival": false + } + }, + { + "id": 2, + "userId": -1, + "statistics": { + "ExperiencePoints": 0, + "Level": 1, + "Speed": 3, + "Initiative": 5, + "HealthPoints": 12, + "CurrentHealthPoints": 11, + "ArmorClass": 4, + "Proficiency": 1 + }, + "biography": { + "Name": "Nucate", + "ClassId": 1, + "RaceId": 1, + "AlignmentId": "LawfulGood", + "BackgroundId": 1, + "Sex": "Male", + "Languages": "Common", + "background": { + "Origin": "No origin", + "History": "Nothing much" + } + }, + "characterWeapons": [ + { + "WeaponId": 30, + "InUse": true, + "HoldInRightHand": true, + "HoldInLeftHand": false + }, + { + "WeaponId": 25, + "InUse": false, + "HoldInRightHand": false, + "HoldInLeftHand": false + } + ], + "characterSpells": [ + { + "SpellId": 2 + }, + { + "SpellId": 42 + } + ], + "charisma": { + "Value": 10, + "Modification": 3, + "SavingThrows": 0, + "CanSavingThrows": false, + "Deception": 0, + "CanDeception": false, + "Intimidation": 1, + "CanIntimidation": true, + "Performance": 2, + "CanPerformance": true, + "Persuasion": 0, + "CanPersuasion": false + }, + "constitution": { + "Value": 11, + "Modification": 4, + "SavingThrows": 2, + "CanSaveThrows": true + }, + "dexterity": { + "Value": 10, + "Modification": 1, + "SavingThrows": 4, + "CanSaveThrows": true, + "Acrobatics": 3, + "CanAcrobatics": true, + "SleightOfHand": 1, + "CanSleightOfHand": true, + "Stealth": 2, + "canStealth": true + }, + "intelligence": { + "Value": 6, + "Modification": -2, + "SavingThrows": 1, + "CanSaveThrows": true, + "arcana": 1, + "canArcana": true, + "History": 4, + "CanHistory": true, + "Investigation": 0, + "CanInvestigation": false, + "Nature": 1, + "CanNature": true, + "Religion": 3, + "canReligion": true + }, + "strength": { + "Value": 10, + "Modification": 1, + "SavingThrows": 0, + "CanSaveThrows": false, + "Athletics": 2, + "canAthletics": true + }, + "wisdom": { + "Value": 11, + "Modification": 3, + "SavingThrows": 1, + "CanSaveThrows": true, + "AnimalHandling": 2, + "canAnimalHandling": true, + "Insight": 1, + "canInsight": true, + "medicine": 0, + "CanMedicine": false, + "Perception": 5, + "CanPerception": true, + "Survival": 2, + "CanSurvival": true + } + }, + { + "id": 3, + "userId": -1, + "statistics": { + "ExperiencePoints": 0, + "Level": 1, + "Speed": 4, + "Initiative": 2, + "HealthPoints": 17, + "CurrentHealthPoints": 16, + "ArmorClass": 6, + "Proficiency": 3 + }, + "biography": { + "Name": "Muraraj", + "ClassId": 2, + "RaceId": 2, + "AlignmentId": "LawfulGood", + "BackgroundId": 1, + "Sex": "Male", + "Languages": "Common", + "background": { + "Origin": "No origin", + "History": "Nothing much" + } + }, + "characterWeapons": [ + { + "WeaponId": 1, + "InUse": true, + "HoldInRightHand": true, + "HoldInLeftHand": false + }, + { + "WeaponId": 2, + "InUse": false, + "HoldInRightHand": false, + "HoldInLeftHand": false + }, + { + "WeaponId": 10, + "InUse": false, + "HoldInRightHand": false, + "HoldInLeftHand": false + } + ], + "characterSpells": [ + { + "SpellId": 42 + } + ], + "charisma": { + "Value": 15, + "Modification": 2, + "SavingThrows": 2, + "CanSaveThrows": true, + "Deception": 1, + "CanDeception": true, + "Intimidation": 4, + "CanIntimidation": true, + "Performance": 2, + "CanPerformance": true, + "Persuasion": 2, + "CanPersuasion": true + }, + "constitution": { + "Value": 15, + "Modification": 4, + "SavingThrows": 2, + "CanSaveThrows": true + }, + "dexterity": { + "Value": 8, + "Modification": -1, + "SavingThrows": 0, + "CanSaveThrows": false, + "Acrobatics": 0, + "CanAcrobatics": false, + "SleightOfHand": 0, + "CanSleightOfHand": false, + "Stealth": 0, + "canStealth": false + }, + "intelligence": { + "Value": 8, + "Modification": -1, + "SavingThrows": 0, + "CanSaveThrows": false, + "arcana": 0, + "canArcana": false, + "History": 0, + "CanHistory": false, + "Investigation": 0, + "CanInvestigation": false, + "Nature": 0, + "CanNature": false, + "Religion": 0, + "canReligion": false + }, + "strength": { + "Value": 18, + "Modification": 4, + "SavingThrows": 3, + "CanSaveThrows": true, + "Athletics": 5, + "canAthletics": true + }, + "wisdom": { + "Value": 6, + "Modification": -3, + "SavingThrows": 0, + "CanSaveThrows": false, + "AnimalHandling": 0, + "CanAnimalHandling": false, + "Insight": 0, + "canInsight": false, + "medicine": 0, + "CanMedicine": false, + "Perception": 0, + "CanPerception": false, + "Survival": 0, + "CanSurvival": false + } + }, + { + "id": 5, + "userId": -1, + "statistics": { + "ExperiencePoints": 0, + "Level": 1, + "Speed": 8, + "Initiative": 7, + "HealthPoints": 7, + "CurrentHealthPoints": 7, + "ArmorClass": 2, + "Proficiency": 3 + }, + "biography": { + "Name": "Amarena", + "ClassId": 2, + "RaceId": 1, + "AlignmentId": "LawfulGood", + "BackgroundId": 2, + "Sex": "Female", + "Languages": "Common", + "background": { + "Origin": "No origin", + "History": "Nothing much" + } + }, + "characterWeapons": [ + { + "WeaponId": 2, + "InUse": true, + "HoldInRightHand": true, + "HoldInLeftHand": false + }, + { + "WeaponId": 14, + "InUse": false, + "HoldInRightHand": false, + "HoldInLeftHand": false + }, + { + "WeaponId": 4, + "InUse": false, + "HoldInRightHand": false, + "HoldInLeftHand": false + } + ], + "characterSpells": [ + { + "SpellId": 2 + } + ], + "charisma": { + "Value": 7, + "Modification": -2, + "SavingThrows": 0, + "CanSavingThrows": false, + "Deception": 0, + "CanDeception": false, + "Intimidation": 0, + "CanIntimidation": false, + "Performance": 0, + "CanPerformance": false, + "Persuasion": 0, + "CanPersuasion": false + }, + "constitution": { + "Value": 11, + "Modification": 1, + "SavingThrows": 1, + "CanSaveThrows": true + }, + "dexterity": { + "Value": 17, + "Modification": 4, + "SavingThrows": 3, + "CanSaveThrows": true, + "Acrobatics": 4, + "CanAcrobatics": true, + "SleightOfHand": 2, + "CanSleightOfHand": true, + "Stealth": 5, + "canStealth": true + }, + "intelligence": { + "Value": 10, + "Modification": 0, + "SavingThrows": 0, + "CanSaveThrows": false, + "arcana": 0, + "canArcana": false, + "History": 0, + "CanHistory": false, + "Investigation": 0, + "CanInvestigation": false, + "Nature": 0, + "CanNature": false, + "Religion": 0, + "canReligion": false + }, + "strength": { + "Value": 14, + "Modification": 2, + "SavingThrows": 1, + "CanSaveThrows": true, + "Athletics": 3, + "canAthletics": true + }, + "wisdom": { + "Value": 7, + "Modification": 0, + "SavingThrows": 0, + "CanSaveThrows": false, + "AnimalHandling": 0, + "canAnimalHandling": false, + "Insight": 0, + "canInsight": false, + "medicine": 0, + "CanMedicine": false, + "Perception": 0, + "CanPerception": false, + "Survival": 0, + "CanSurvival": false + } + }, + { + "id": 6, + "userId": -1, + "statistics": { + "ExperiencePoints": 0, + "Level": 1, + "Speed": 2, + "Initiative": 3, + "HealthPoints": 17, + "CurrentHealthPoints": 17, + "ArmorClass": 5, + "Proficiency": 1 + }, + "biography": { + "Name": "Yaz' uw Emul", + "ClassId": 1, + "RaceId": 3, + "AlignmentId": "LawfulGood", + "BackgroundId": 3, + "Sex": "Male", + "Languages": "Common", + "background": { + "Origin": "No origin", + "History": "Nothing much" + } + }, + "characterWeapons": [ + { + "WeaponId": 16, + "InUse": true, + "HoldInRightHand": true, + "HoldInLeftHand": false + }, + { + "WeaponId": 14, + "InUse": false, + "HoldInRightHand": false, + "HoldInLeftHand": false + } + ], + "characterSpells": [ + { + "SpellId": 2 + }, + { + "SpellId": 65 + }, + { + "SpellId": 44 + } + ], + "charisma": { + "Value": 10, + "Modification": 0, + "SavingThrows": 0, + "CanSavingThrows": false, + "Deception": 1, + "CanDeception": true, + "Intimidation": 2, + "CanIntimidation": true, + "Performance": 0, + "CanPerformance": false, + "Persuasion": 0, + "CanPersuasion": false + }, + "constitution": { + "Value": 14, + "Modification": 4, + "SavingThrows": 1, + "CanSaveThrows": true + }, + "dexterity": { + "Value": 6, + "Modification": -3, + "SavingThrows": 0, + "CanSaveThrows": false, + "Acrobatics": 0, + "CanAcrobatics": false, + "SleightOfHand": 0, + "CanSleightOfHand": false, + "Stealth": 0, + "canStealth": false + }, + "intelligence": { + "Value": 11, + "Modification": 1, + "SavingThrows": 1, + "CanSaveThrows": true, + "arcana": 0, + "canArcana": false, + "History": 2, + "CanHistory": true, + "Investigation": 1, + "CanInvestigation": true, + "Nature": 0, + "CanNature": false, + "Religion": 4, + "canReligion": true + }, + "strength": { + "Value": 18, + "Modification": 4, + "SavingThrows": 2, + "CanSaveThrows": true, + "Athletics": 4, + "canAthletics": true + }, + "wisdom": { + "Value": 9, + "Modification": -1, + "SavingThrows": 0, + "CanSaveThrows": false, + "AnimalHandling": 0, + "canAnimalHandling": false, + "Insight": 0, + "canInsight": false, + "medicine": 0, + "CanMedicine": false, + "Perception": 0, + "CanPerception": false, + "Survival": 0, + "CanSurvival": false + } + }, + { + "id": 7, + "userId": -1, + "statistics": { + "ExperiencePoints": 0, + "Level": 1, + "Speed": 5, + "Initiative": 4, + "HealthPoints": 13, + "CurrentHealthPoints": 13, + "ArmorClass": 2, + "Proficiency": 1 + }, + "biography": { + "Name": "Kamul", + "ClassId": 2, + "RaceId": 1, + "AlignmentId": "LawfulGood", + "BackgroundId": 1, + "Sex": "Female", + "Languages": "Common", + "background": { + "Origin": "No origin", + "History": "Nothing much" + } + }, + "characterWeapons": [ + { + "WeaponId": 18, + "InUse": true, + "HoldInRightHand": true, + "HoldInLeftHand": false + }, + { + "WeaponId": 1, + "InUse": false, + "HoldInRightHand": false, + "HoldInLeftHand": false + } + ], + "characterSpells": [ + { + "SpellId": 3 + }, + { + "SpellId": 85 + }, + { + "SpellId": 94 + } + ], + "charisma": { + "Value": 10, + "Modification": 0, + "SavingThrows": 0, + "CanSavingThrows": false, + "Deception": 2, + "CanDeception": true, + "Intimidation": 0, + "CanIntimidation": false, + "Performance": 1, + "CanPerformance": true, + "Persuasion": 2, + "CanPersuasion": true + }, + "constitution": { + "Value": 8, + "Modification": -2, + "SavingThrows": 0, + "CanSaveThrows": false + }, + "dexterity": { + "Value": 12, + "Modification": 1, + "SavingThrows": 1, + "CanSaveThrows": true, + "Acrobatics": 2, + "CanAcrobatics": true, + "SleightOfHand": 1, + "CanSleightOfHand": true, + "Stealth": 0, + "canStealth": false + }, + "intelligence": { + "Value": 15, + "Modification": 4, + "SavingThrows": 2, + "CanSaveThrows": true, + "arcana": 4, + "canArcana": true, + "History": 1, + "CanHistory": true, + "Investigation": 1, + "CanInvestigation": true, + "Nature": 6, + "CanNature": true, + "Religion": 0, + "canReligion": false + }, + "strength": { + "Value": 13, + "Modification": 1, + "SavingThrows": 1, + "CanSaveThrows": true, + "Athletics": 2, + "canAthletics": true + }, + "wisdom": { + "Value": 13, + "Modification": 2, + "SavingThrows": 2, + "CanSaveThrows": true, + "AnimalHandling": 1, + "canAnimalHandling": true, + "Insight": 4, + "canInsight": true, + "medicine": 2, + "CanMedicine": true, + "Perception": 5, + "CanPerception": true, + "Survival": 2, + "CanSurvival": true + } + }, + { + "id": 8, + "userId": -1, + "statistics": { + "ExperiencePoints": 0, + "Level": 1, + "Speed": 9, + "Initiative": 6, + "HealthPoints": 7, + "CurrentHealthPoints": 7, + "ArmorClass": 4, + "Proficiency": 1 + }, + "biography": { + "Name": "Mu", + "ClassId": 1, + "RaceId": 3, + "AlignmentId": "LawfulGood", + "BackgroundId": 2, + "Sex": "Male", + "Languages": "Common", + "background": { + "Origin": "No origin", + "History": "Nothing much" + } + }, + "characterWeapons": [ + { + "WeaponId": 1, + "InUse": true, + "HoldInRightHand": true, + "HoldInLeftHand": false + }, + { + "WeaponId": 17, + "InUse": false, + "HoldInRightHand": false, + "HoldInLeftHand": false + }, + { + "WeaponId": 27, + "InUse": false, + "HoldInRightHand": false, + "HoldInLeftHand": false + } + ], + "characterSpells": [ + { + "SpellId": 3 + } + ], + "charisma": { + "Value": 11, + "Modification": 1, + "SavingThrows": 1, + "CanSavingThrows": true, + "Deception": 1, + "CanDeception": true, + "Intimidation": 0, + "CanIntimidation": false, + "Performance": 0, + "CanPerformance": false, + "Persuasion": 0, + "CanPersuasion": false + }, + "constitution": { + "Value": 13, + "Modification": 2, + "SavingThrows": 1, + "CanSaveThrows": true + }, + "dexterity": { + "Value": 17, + "Modification": 4, + "SavingThrows": 3, + "CanSaveThrows": true, + "Acrobatics": 3, + "CanAcrobatics": true, + "SleightOfHand": 4, + "CanSleightOfHand": true, + "Stealth": 1, + "canStealth": true + }, + "intelligence": { + "Value": 8, + "Modification": -2, + "SavingThrows": 0, + "CanSaveThrows": false, + "arcana": 0, + "canArcana": false, + "History": 0, + "CanHistory": false, + "Investigation": 0, + "CanInvestigation": false, + "Nature": 0, + "CanNature": false, + "Religion": 0, + "canReligion": false + }, + "strength": { + "Value": 18, + "Modification": 4, + "SavingThrows": 3, + "CanSaveThrows": true, + "Athletics": 5, + "canAthletics": true + }, + "wisdom": { + "Value": 8, + "Modification": -2, + "SavingThrows": 0, + "CanSaveThrows": false, + "AnimalHandling": 0, + "canAnimalHandling": false, + "Insight": 0, + "canInsight": false, + "medicine": 0, + "CanMedicine": false, + "Perception": 0, + "CanPerception": false, + "Survival": 0, + "CanSurvival": false + } + }, + { + "id": 9, + "userId": -1, + "statistics": { + "ExperiencePoints": 0, + "Level": 1, + "Speed": 4, + "Initiative": 3, + "HealthPoints": 12, + "CurrentHealthPoints": 12, + "ArmorClass": 3, + "Proficiency": 1 + }, + "biography": { + "Name": "Aarak", + "ClassId": 2, + "RaceId": 3, + "AlignmentId": "LawfulGood", + "BackgroundId": 2, + "Sex": "Female", + "Languages": "Common", + "background": { + "Origin": "No origin", + "History": "Nothing much" + } + }, + "characterWeapons": [ + { + "WeaponId": 4, + "InUse": true, + "HoldInRightHand": true, + "HoldInLeftHand": false + }, + { + "WeaponId": 7, + "InUse": false, + "HoldInRightHand": false, + "HoldInLeftHand": false + } + ], + "characterSpells": [ + { + "SpellId": 1 + }, + { + "SpellId": 55 + } + ], + "charisma": { + "Value": 12, + "Modification": 2, + "SavingThrows": 1, + "CanSavingThrows": true, + "Deception": 0, + "CanDeception": false, + "Intimidation": 0, + "CanIntimidation": false, + "Performance": 0, + "CanPerformance": false, + "Persuasion": 3, + "CanPersuasion": true + }, + "constitution": { + "Value": 11, + "Modification": 1, + "SavingThrows": 1, + "CanSaveThrows": true + }, + "dexterity": { + "Value": 15, + "Modification": 3, + "SavingThrows": 2, + "CanSaveThrows": true, + "Acrobatics": 2, + "CanAcrobatics": true, + "SleightOfHand": 1, + "CanSleightOfHand": true, + "Stealth": 4, + "canStealth": true + }, + "intelligence": { + "Value": 12, + "Modification": 1, + "SavingThrows": 1, + "CanSaveThrows": true, + "arcana": 0, + "canArcana": false, + "History": 0, + "CanHistory": false, + "Investigation": 0, + "CanInvestigation": false, + "Nature": 2, + "CanNature": true, + "Religion": 0, + "canReligion": false + }, + "strength": { + "Value": 15, + "Modification": 4, + "SavingThrows": 3, + "CanSaveThrows": true, + "Athletics": 2, + "canAthletics": true + }, + "wisdom": { + "Value": 6, + "Modification": -4, + "SavingThrows": 0, + "CanSaveThrows": false, + "AnimalHandling": 0, + "canAnimalHandling": false, + "Insight": 0, + "canInsight": false, + "medicine": 0, + "CanMedicine": false, + "Perception": 0, + "CanPerception": false, + "Survival": 0, + "CanSurvival": false + } + } +] diff --git a/SessionCompanion/SessionCompanion.Database/SessionCompanion.Database.csproj b/SessionCompanion/SessionCompanion.Database/SessionCompanion.Database.csproj index 120ad3e..a157829 100644 --- a/SessionCompanion/SessionCompanion.Database/SessionCompanion.Database.csproj +++ b/SessionCompanion/SessionCompanion.Database/SessionCompanion.Database.csproj @@ -21,8 +21,4 @@ - - - - diff --git a/SessionCompanion/SessionCompanion.Services/Intefraces/ICharacterService.cs b/SessionCompanion/SessionCompanion.Services/Intefraces/ICharacterService.cs index 026f0f7..715f6f3 100644 --- a/SessionCompanion/SessionCompanion.Services/Intefraces/ICharacterService.cs +++ b/SessionCompanion/SessionCompanion.Services/Intefraces/ICharacterService.cs @@ -1,6 +1,8 @@ using SessionCompanion.Database.Tables; using SessionCompanion.Services.Base; using SessionCompanion.ViewModels.CharacterViewModels; +using SessionCompanion.ViewModels.ClassViewModels; +using SessionCompanion.ViewModels.RaceViewModels; using SessionCompanion.ViewModels.UniversalModels; using System; using System.Collections.Generic; @@ -15,5 +17,6 @@ namespace SessionCompanion.Services.Interfaces Task> GetUserLoginCharacters(int userId); Task> GetCharacterStatistics(int characterId); Task GetBasicCharacterbasicInfo(int characterId); + Task> GetCharactersFromTemplate(List raceViewModels, List classViewModels); } } diff --git a/SessionCompanion/SessionCompanion.Services/Services/CharacterService.cs b/SessionCompanion/SessionCompanion.Services/Services/CharacterService.cs index ddbf698..808c168 100644 --- a/SessionCompanion/SessionCompanion.Services/Services/CharacterService.cs +++ b/SessionCompanion/SessionCompanion.Services/Services/CharacterService.cs @@ -16,12 +16,14 @@ using System.IO; using Newtonsoft.Json.Linq; using SessionCompanion.ViewModels.UniversalModels; using SessionCompanion.Services.Helpers; +using SessionCompanion.ViewModels.RaceViewModels; +using SessionCompanion.ViewModels.ClassViewModels; namespace SessionCompanion.Services.Services { public class CharacterService : ServiceBase, ICharacterService { - public CharacterService(IMapper mapper, IRepository repository) : base(mapper, repository) + public CharacterService(IMapper mapper, IRepository repository, IRepository classRepository) : base(mapper, repository) { } /// @@ -111,5 +113,31 @@ namespace SessionCompanion.Services.Services var result = Mapper.Map(character); return result; } + + /// + /// Function returns basic stats from Characters in templates + /// + /// + public async Task> GetCharactersFromTemplate(List raceViewModels, List classViewModels) + { + const string file = "../SessionCompanion.Database/JsonData/characters_templates.json"; + List basicStats = new List(); + using (StreamReader reader = new StreamReader(file)) + { + var json = await reader.ReadToEndAsync(); + foreach (var item in JArray.Parse(json)) + { + CharacterFromTemplatesSimpleViewModel characterFromTemplatesSimpleViewModel = new CharacterFromTemplatesSimpleViewModel() + { + Id = (int)item["id"], + Class = classViewModels.Where(c => c.Id.Equals((int)item["biography"]["ClassId"])).Select(c => c.Name).Single(), + Race = raceViewModels.Where(r => r.Id.Equals((int)item["biography"]["RaceId"])).Select(r => r.Name).Single(), + Name = (string)item["biography"]["Name"] + }; + basicStats.Add(characterFromTemplatesSimpleViewModel); + } + } + return basicStats; + } } } diff --git a/SessionCompanion/SessionCompanion.ViewModels/CharacterViewModels/CharacterFromTemplatesSimpleViewModel.cs b/SessionCompanion/SessionCompanion.ViewModels/CharacterViewModels/CharacterFromTemplatesSimpleViewModel.cs new file mode 100644 index 0000000..dbf4079 --- /dev/null +++ b/SessionCompanion/SessionCompanion.ViewModels/CharacterViewModels/CharacterFromTemplatesSimpleViewModel.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SessionCompanion.ViewModels.CharacterViewModels +{ + public class CharacterFromTemplatesSimpleViewModel + { + /// + /// Id postaci + /// + public int Id { get; set; } + /// + /// Imie postaci + /// + public string Name { get; set; } + /// + /// Nazwa rasy postaci + /// + public string Race { get; set; } + /// + /// Nazwa Klasy postaci + /// + public string Class { get; set; } + } +} diff --git a/SessionCompanion/SessionCompanion/Controllers/CharacterController.cs b/SessionCompanion/SessionCompanion/Controllers/CharacterController.cs index f59f3c7..4fd9901 100644 --- a/SessionCompanion/SessionCompanion/Controllers/CharacterController.cs +++ b/SessionCompanion/SessionCompanion/Controllers/CharacterController.cs @@ -9,6 +9,7 @@ namespace SessionCompanion.Controllers { using SessionCompanion.Hubs; using SessionCompanion.ViewModels.UniversalModels; + using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; @@ -19,11 +20,15 @@ namespace SessionCompanion.Controllers { private readonly ICharacterService _service; private readonly SessionHubData _sessionHubData; + private readonly IRaceService _raceService; + private readonly IClassService _classService; - public CharacterController(ICharacterService service) + public CharacterController(ICharacterService service, IRaceService raceService, IClassService classService) { this._service = service; this._sessionHubData = new SessionHubData(); + this._raceService = raceService; + this._classService = classService; } /// @@ -105,5 +110,29 @@ namespace SessionCompanion.Controllers }; return info; } + + /// + /// Metoda zwraca podstawowe informacje dla postaci z Templatek + /// + /// liste podstawowych informacji o postaciach z templatki + [HttpGet("getTemplateCharacters")] + public async Task>> GetTemplateCharacters() + { + var races = _raceService.Get().ToList(); + var classes = _classService.Get().ToList(); + try + { + var templateCharacters = await _service.GetCharactersFromTemplate(races, classes); + return templateCharacters.ToList(); + } + catch (Exception e) + { + return new ErrorResponse() + { + StatusCode = 500, + Message = e.Message + }; + } + } } } \ No newline at end of file