SES-148 Endpointy dla Armor i Weapon #71
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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" };
|
||||
|
Loading…
Reference in New Issue
Block a user