SES-148 Endpointy dla Armor i Weapon #71

Merged
s426134 merged 11 commits from SES-148 into dev 2021-01-14 16:45:05 +01:00
2 changed files with 15 additions and 3 deletions
Showing only changes of commit 108dc89fd7 - Show all commits

View File

@ -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);
} }
} }

View File

@ -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();
CharacterArmor armorToUse = new CharacterArmor();
try
{
armorInUse = await Repository.Get(c => c.CharacterId.Equals(characterId))
.Include(a => a.Armor).Where(x => x.InUse == true).SingleAsync(); .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) 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" };