session-companion/SessionCompanion/SessionCompanion.Services/Services/StatisticsService.cs

35 lines
1.2 KiB
C#
Raw Normal View History

using AutoMapper;
using Microsoft.EntityFrameworkCore;
using SessionCompanion.Database.Repositories.Base;
using SessionCompanion.Database.Tables;
using SessionCompanion.Services.Base;
using SessionCompanion.Services.Interfaces;
using SessionCompanion.ViewModels.StatisticsViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SessionCompanion.Services.Services
{
public class StatisticsService : ServiceBase<StatisticsViewModel, Statistics>, IStatisticsService
{
public StatisticsService(IMapper mapper, IRepository<Statistics> repository) : base(mapper, repository)
{ }
2021-01-07 18:05:22 +01:00
/// <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();
}
}
}