Merge pull request 'SES-157 Create characters from templates' (#73) from SES-157 into dev
Reviewed-on: #73
This commit is contained in:
commit
f99437e3ab
@ -16,7 +16,7 @@
|
|||||||
"Name": "Ulora",
|
"Name": "Ulora",
|
||||||
"ClassId": 2,
|
"ClassId": 2,
|
||||||
"RaceId": 3,
|
"RaceId": 3,
|
||||||
"AlignmentId": "LawfulGood",
|
"AlignmentId": 1,
|
||||||
"BackgroundId": 2,
|
"BackgroundId": 2,
|
||||||
"Sex": "Female",
|
"Sex": "Female",
|
||||||
"Languages": "Common",
|
"Languages": "Common",
|
||||||
@ -137,7 +137,7 @@
|
|||||||
"Name": "Nucate",
|
"Name": "Nucate",
|
||||||
"ClassId": 1,
|
"ClassId": 1,
|
||||||
"RaceId": 1,
|
"RaceId": 1,
|
||||||
"AlignmentId": "LawfulGood",
|
"AlignmentId": 2,
|
||||||
"BackgroundId": 1,
|
"BackgroundId": 1,
|
||||||
"Sex": "Male",
|
"Sex": "Male",
|
||||||
"Languages": "Common",
|
"Languages": "Common",
|
||||||
@ -258,7 +258,7 @@
|
|||||||
"Name": "Muraraj",
|
"Name": "Muraraj",
|
||||||
"ClassId": 2,
|
"ClassId": 2,
|
||||||
"RaceId": 2,
|
"RaceId": 2,
|
||||||
"AlignmentId": "LawfulGood",
|
"AlignmentId": 1,
|
||||||
"BackgroundId": 1,
|
"BackgroundId": 1,
|
||||||
"Sex": "Male",
|
"Sex": "Male",
|
||||||
"Languages": "Common",
|
"Languages": "Common",
|
||||||
@ -366,7 +366,7 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": 5,
|
"id": 4,
|
||||||
"userId": -1,
|
"userId": -1,
|
||||||
"statistics": {
|
"statistics": {
|
||||||
"ExperiencePoints": 0,
|
"ExperiencePoints": 0,
|
||||||
@ -382,7 +382,7 @@
|
|||||||
"Name": "Amarena",
|
"Name": "Amarena",
|
||||||
"ClassId": 2,
|
"ClassId": 2,
|
||||||
"RaceId": 1,
|
"RaceId": 1,
|
||||||
"AlignmentId": "LawfulGood",
|
"AlignmentId": 1,
|
||||||
"BackgroundId": 2,
|
"BackgroundId": 2,
|
||||||
"Sex": "Female",
|
"Sex": "Female",
|
||||||
"Languages": "Common",
|
"Languages": "Common",
|
||||||
@ -490,7 +490,7 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": 6,
|
"id": 5,
|
||||||
"userId": -1,
|
"userId": -1,
|
||||||
"statistics": {
|
"statistics": {
|
||||||
"ExperiencePoints": 0,
|
"ExperiencePoints": 0,
|
||||||
@ -506,7 +506,7 @@
|
|||||||
"Name": "Yaz' uw Emul",
|
"Name": "Yaz' uw Emul",
|
||||||
"ClassId": 1,
|
"ClassId": 1,
|
||||||
"RaceId": 3,
|
"RaceId": 3,
|
||||||
"AlignmentId": "LawfulGood",
|
"AlignmentId": 1,
|
||||||
"BackgroundId": 3,
|
"BackgroundId": 3,
|
||||||
"Sex": "Male",
|
"Sex": "Male",
|
||||||
"Languages": "Common",
|
"Languages": "Common",
|
||||||
@ -614,7 +614,7 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": 7,
|
"id": 6,
|
||||||
"userId": -1,
|
"userId": -1,
|
||||||
"statistics": {
|
"statistics": {
|
||||||
"ExperiencePoints": 0,
|
"ExperiencePoints": 0,
|
||||||
@ -630,7 +630,7 @@
|
|||||||
"Name": "Kamul",
|
"Name": "Kamul",
|
||||||
"ClassId": 2,
|
"ClassId": 2,
|
||||||
"RaceId": 1,
|
"RaceId": 1,
|
||||||
"AlignmentId": "LawfulGood",
|
"AlignmentId": 2,
|
||||||
"BackgroundId": 1,
|
"BackgroundId": 1,
|
||||||
"Sex": "Female",
|
"Sex": "Female",
|
||||||
"Languages": "Common",
|
"Languages": "Common",
|
||||||
@ -738,7 +738,7 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": 8,
|
"id": 7,
|
||||||
"userId": -1,
|
"userId": -1,
|
||||||
"statistics": {
|
"statistics": {
|
||||||
"ExperiencePoints": 0,
|
"ExperiencePoints": 0,
|
||||||
@ -754,7 +754,7 @@
|
|||||||
"Name": "Mu",
|
"Name": "Mu",
|
||||||
"ClassId": 1,
|
"ClassId": 1,
|
||||||
"RaceId": 3,
|
"RaceId": 3,
|
||||||
"AlignmentId": "LawfulGood",
|
"AlignmentId": 1,
|
||||||
"BackgroundId": 2,
|
"BackgroundId": 2,
|
||||||
"Sex": "Male",
|
"Sex": "Male",
|
||||||
"Languages": "Common",
|
"Languages": "Common",
|
||||||
@ -862,7 +862,7 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": 9,
|
"id": 8,
|
||||||
"userId": -1,
|
"userId": -1,
|
||||||
"statistics": {
|
"statistics": {
|
||||||
"ExperiencePoints": 0,
|
"ExperiencePoints": 0,
|
||||||
@ -878,7 +878,7 @@
|
|||||||
"Name": "Aarak",
|
"Name": "Aarak",
|
||||||
"ClassId": 2,
|
"ClassId": 2,
|
||||||
"RaceId": 3,
|
"RaceId": 3,
|
||||||
"AlignmentId": "LawfulGood",
|
"AlignmentId": 1,
|
||||||
"BackgroundId": 2,
|
"BackgroundId": 2,
|
||||||
"Sex": "Female",
|
"Sex": "Female",
|
||||||
"Languages": "Common",
|
"Languages": "Common",
|
||||||
|
@ -18,5 +18,6 @@ namespace SessionCompanion.Services.Interfaces
|
|||||||
Task<List<UniversalStatisticViewModel>> GetCharacterStatistics(int characterId);
|
Task<List<UniversalStatisticViewModel>> GetCharacterStatistics(int characterId);
|
||||||
Task<CharacterBasicInfoViewModel> GetBasicCharacterbasicInfo(int characterId);
|
Task<CharacterBasicInfoViewModel> GetBasicCharacterbasicInfo(int characterId);
|
||||||
Task<IEnumerable<CharacterFromTemplatesSimpleViewModel>> GetCharactersFromTemplate(List<RaceViewModel> raceViewModels, List<ClassViewModel> classViewModels);
|
Task<IEnumerable<CharacterFromTemplatesSimpleViewModel>> GetCharactersFromTemplate(List<RaceViewModel> raceViewModels, List<ClassViewModel> classViewModels);
|
||||||
|
Task CreateCharactersFromTemplate(int characterId, int userId, string newName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -139,5 +139,31 @@ namespace SessionCompanion.Services.Services
|
|||||||
}
|
}
|
||||||
return basicStats;
|
return basicStats;
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Function creates chosen template Character for given User, it can also change its name
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="characterId"></param>
|
||||||
|
/// <param name="userId"></param>
|
||||||
|
/// <param name="newName"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task CreateCharactersFromTemplate(int characterId, int userId, string newName)
|
||||||
|
{
|
||||||
|
const string file = "../SessionCompanion.Database/JsonData/characters_templates.json";
|
||||||
|
List<Character> characters = new List<Character>();
|
||||||
|
using (StreamReader reader = new StreamReader(file))
|
||||||
|
{
|
||||||
|
var json = await reader.ReadToEndAsync();
|
||||||
|
characters = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Character>>(json);
|
||||||
|
}
|
||||||
|
var character = characters.Where(x => x.Id.Equals(characterId)).Single();
|
||||||
|
|
||||||
|
character.Id = 0;
|
||||||
|
character.UserId = userId;
|
||||||
|
if (newName != null)
|
||||||
|
character.Biography.Name = newName;
|
||||||
|
|
||||||
|
await Repository.Create(character);
|
||||||
|
await Repository.Save();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -134,5 +134,29 @@ namespace SessionCompanion.Controllers
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Metoda do tworzenia postaci z templatek
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="characterId">Id postaci z templatki</param>
|
||||||
|
/// <param name="userId"></param>
|
||||||
|
/// <param name="newName"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpPost("createCharacterFromTemplate")]
|
||||||
|
public async Task<Either<SuccessResponse,ErrorResponse>> CreateTemplateCharacters(int characterId, int userId, string newName)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await _service.CreateCharactersFromTemplate(characterId, userId, newName);
|
||||||
|
return new SuccessResponse("Character created") { SuccessCode = 200 };
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
return new ErrorResponse()
|
||||||
|
{
|
||||||
|
StatusCode = 500,
|
||||||
|
Message = e.Message
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user