SES-148 Endpointy dla Armor i Weapon #71
@ -7,10 +7,13 @@ namespace SessionCompanion.Services.Interfaces
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
using SessionCompanion.Database.Tables;
|
using SessionCompanion.Database.Tables;
|
||||||
|
using SessionCompanion.Extensions.EitherType;
|
||||||
using SessionCompanion.Services.Base;
|
using SessionCompanion.Services.Base;
|
||||||
|
using SessionCompanion.ViewModels.ApiResponses;
|
||||||
using SessionCompanion.ViewModels.CharacterArmorViewModels;
|
using SessionCompanion.ViewModels.CharacterArmorViewModels;
|
||||||
|
|
||||||
public interface ICharacterArmorService : IServiceBase<CharacterArmorViewModel, CharacterArmor>
|
public interface ICharacterArmorService : IServiceBase<CharacterArmorViewModel, CharacterArmor>
|
||||||
{
|
{
|
||||||
|
Task<Either<SuccessResponse, ErrorResponse>> ChangeCharacterArmor(int characterId, int newArmorId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,9 +25,18 @@ namespace SessionCompanion.Services.Services
|
|||||||
{ }
|
{ }
|
||||||
public async Task<Either<SuccessResponse, ErrorResponse>> ChangeCharacterArmor(int characterId, int newArmorId)
|
public async Task<Either<SuccessResponse, ErrorResponse>> ChangeCharacterArmor(int characterId, int newArmorId)
|
||||||
{
|
{
|
||||||
var armorInUse = await Repository.Get(c => c.CharacterId.Equals(characterId))
|
CharacterArmor armorInUse = new CharacterArmor();
|
||||||
.Include(a => a.Armor).Where(x => x.InUse == true).SingleAsync();
|
CharacterArmor armorToUse = new CharacterArmor();
|
||||||
var armorToUse = await Repository.Get(c => c.ArmorId.Equals(newArmorId) && c.CharacterId.Equals(characterId)).SingleAsync();
|
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)
|
if (armorToUse is null)
|
||||||
return new ErrorResponse() { StatusCode = 204, Message = "No weapon to change to" };
|
return new ErrorResponse() { StatusCode = 204, Message = "No weapon to change to" };
|
||||||
|
Loading…
Reference in New Issue
Block a user