SES-148 Add Armor changing, but not ready yet
This commit is contained in:
parent
f8b7fe6243
commit
95b995fd2d
@ -15,11 +15,50 @@ namespace SessionCompanion.Services.Services
|
||||
using SessionCompanion.Database.Tables;
|
||||
using SessionCompanion.Services.Base;
|
||||
using SessionCompanion.Services.Interfaces;
|
||||
using SessionCompanion.ViewModels.ApiResponses;
|
||||
using SessionCompanion.ViewModels.CharacterArmorViewModels;
|
||||
|
||||
public class CharacterArmorService : ServiceBase<CharacterArmorViewModel, CharacterArmor>, ICharacterArmorService
|
||||
{
|
||||
public CharacterArmorService(IMapper mapper, IRepository<CharacterArmor> repository) : base(mapper, repository)
|
||||
{ }
|
||||
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();
|
||||
|
||||
if (armorToUse is null)
|
||||
return new ErrorResponse() { StatusCode = 204, Message = "No weapon to change to" };
|
||||
|
||||
if (armorInUse is null)
|
||||
{
|
||||
armorToUse.InUse = true;
|
||||
try
|
||||
{
|
||||
await Repository.Update(armorToUse);
|
||||
await Repository.Save();
|
||||
return new SuccessResponse("Character weapon updated") { SuccessCode = 200 };
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return new ErrorResponse() { StatusCode = 500, Message = e.Message };
|
||||
}
|
||||
}
|
||||
|
||||
armorInUse.InUse = false;
|
||||
armorToUse.InUse = true;
|
||||
try
|
||||
{
|
||||
await Repository.Update(armorInUse);
|
||||
await Repository.Update(armorToUse);
|
||||
await Repository.Save();
|
||||
return new SuccessResponse("Character weapon updated") { SuccessCode = 204 }
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return new ErrorResponse() { StatusCode = 500, Message = e.Message };
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -10,10 +10,13 @@ EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SessionCompanion.ViewModels", "SessionCompanion.ViewModels\SessionCompanion.ViewModels.csproj", "{7762AA75-7B60-4F28-B80A-B03E39140F89}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SessionCompanion.Services", "SessionCompanion.Services\SessionCompanion.Services.csproj", "{C0A172ED-0F4C-4E78-8B64-28E2A756F62F}"
|
||||
ProjectSection(ProjectDependencies) = postProject
|
||||
{1EE35EB3-C703-407C-B390-5605A0A46884} = {1EE35EB3-C703-407C-B390-5605A0A46884}
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SessionCompanion.Extensions", "SessionCompanion.Extensions\SessionCompanion.Extensions.csproj", "{1EE35EB3-C703-407C-B390-5605A0A46884}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SessionCompanion.XUnitTests", "SessionCompanion.XUnitTests\SessionCompanion.XUnitTests.csproj", "{B8A4DAF6-DD33-4B35-99B8-A1D060EE1869}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SessionCompanion.XUnitTests", "SessionCompanion.XUnitTests\SessionCompanion.XUnitTests.csproj", "{B8A4DAF6-DD33-4B35-99B8-A1D060EE1869}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
|
@ -0,0 +1,33 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using SessionCompanion.Services.Interfaces;
|
||||
using SessionCompanion.Extensions.EitherType;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using SessionCompanion.ViewModels.ApiResponses;
|
||||
|
||||
namespace SessionCompanion.Controllers
|
||||
{
|
||||
[Route("api/characterArmor")]
|
||||
[ApiController]
|
||||
public class CharacterArmorController : Controller
|
||||
{
|
||||
private ICharacterArmorService _service;
|
||||
public CharacterArmorController(ICharacterArmorService characterArmorService)
|
||||
{
|
||||
this._service = characterArmorService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Metoda zmienia uzywany armor danej postaci
|
||||
/// </summary>
|
||||
/// <param name="characterId"></param>
|
||||
/// <param name="newArmorId"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<Either<ErrorResponse, SuccessResponse>> ChangeCharacterArmor(int characterId, int newArmorId)
|
||||
{
|
||||
return new ErrorResponse() { StatusCode = 1, Message = "asd" };
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user