Merge pull request 'SES-134 Serwis do odejmowania HP' (#57) from SES-134 into dev

Reviewed-on: #57
This commit is contained in:
Łukasz Góreczny 2021-01-08 14:25:52 +01:00
commit 7075e8ef88
2 changed files with 14 additions and 0 deletions

View File

@ -10,5 +10,6 @@ namespace SessionCompanion.Services.Interfaces
{
public interface IStatisticsService : IServiceBase<StatisticsViewModel, Statistics>
{
Task SubtractHp(int characterId, int hpToSubtract);
}
}

View File

@ -17,5 +17,18 @@ namespace SessionCompanion.Services.Services
{
public StatisticsService(IMapper mapper, IRepository<Statistics> repository) : base(mapper, repository)
{ }
/// <summary>
/// Method subtract hp from given character
/// </summary>
/// <param name="characterId"></param>
/// <param name="hpToSubtract"></param>
/// <returns></returns>
public async Task SubtractHp(int characterId, int hpToSubtract)
{
var result = await Repository.Get(c => c.Id.Equals(characterId)).SingleAsync();
result.CurrentHealthPoints -= hpToSubtract;
await Repository.Update(result);
await Repository.Save();
}
}
}