SES-148 finished character armor
This commit is contained in:
parent
09863e9b8e
commit
108dc89fd7
@ -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))
|
||||
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();
|
||||
var armorToUse = await Repository.Get(c => c.ArmorId.Equals(newArmorId) && c.CharacterId.Equals(characterId)).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