SES-148 finished character armor

This commit is contained in:
Karol Górzyński 2021-01-13 17:10:41 +01:00
parent 09863e9b8e
commit 108dc89fd7
2 changed files with 15 additions and 3 deletions

View File

@ -7,10 +7,13 @@ namespace SessionCompanion.Services.Interfaces
using System.Threading.Tasks;
using SessionCompanion.Database.Tables;
using SessionCompanion.Extensions.EitherType;
using SessionCompanion.Services.Base;
using SessionCompanion.ViewModels.ApiResponses;
using SessionCompanion.ViewModels.CharacterArmorViewModels;
public interface ICharacterArmorService : IServiceBase<CharacterArmorViewModel, CharacterArmor>
{
Task<Either<SuccessResponse, ErrorResponse>> ChangeCharacterArmor(int characterId, int newArmorId);
}
}

View File

@ -25,9 +25,18 @@ namespace SessionCompanion.Services.Services
{ }
public async Task<Either<SuccessResponse, ErrorResponse>> ChangeCharacterArmor(int characterId, int newArmorId)
{
var armorInUse = await Repository.Get(c => c.CharacterId.Equals(characterId))
.Include(a => a.Armor).Where(x => x.InUse == true).SingleAsync();
var armorToUse = await Repository.Get(c => c.ArmorId.Equals(newArmorId) && c.CharacterId.Equals(characterId)).SingleAsync();
CharacterArmor armorInUse = new CharacterArmor();
CharacterArmor armorToUse = new CharacterArmor();
try
{
armorInUse = await Repository.Get(c => c.CharacterId.Equals(characterId))
.Include(a => a.Armor).Where(x => x.InUse == true).SingleAsync();
armorToUse = await Repository.Get(c => c.ArmorId.Equals(newArmorId) && c.CharacterId.Equals(characterId)).SingleAsync();
}
catch (Exception e)
{
return new ErrorResponse() { StatusCode = 500, Message = e.Message };
}
if (armorToUse is null)
return new ErrorResponse() { StatusCode = 204, Message = "No weapon to change to" };