diff --git a/Sledgemapper.Api/Controllers/SessionController.cs b/Sledgemapper.Api/Controllers/SessionController.cs index b644773..fbf2f7c 100644 --- a/Sledgemapper.Api/Controllers/SessionController.cs +++ b/Sledgemapper.Api/Controllers/SessionController.cs @@ -12,21 +12,20 @@ namespace Sledgemapper.Api.Controllers public class SessionController : ControllerBase { private readonly IMediator _mediator; - - public SessionController(IMediator mediator) { _mediator = mediator; } + private int UserId => int.Parse(HttpContext.User.Identity.Name); + + public SessionController(IMediator mediator) => _mediator = mediator; [HttpPost] public async Task Post(string sessionName) { - var userId = int.Parse(HttpContext.User.Identity.Name); - var result = await _mediator.Send(new NewSessionCommand(sessionName, userId)); + var result = await _mediator.Send(new NewSessionCommand(sessionName, UserId)); return result; } [HttpGet] public async Task Get(string sessionName) { - var userId = int.Parse(HttpContext.User.Identity.Name); var result = await _mediator.Send(new GetMapSnapshotCommand(sessionName)); return result; } @@ -34,50 +33,43 @@ namespace Sledgemapper.Api.Controllers [HttpPost("snapshot")] public async Task Post(string sessionName, [FromBody] Session session) { - var userId = int.Parse(HttpContext.User.Identity.Name); - await _mediator.Send(new NewSnapshotCommand(sessionName, session, userId)); + await _mediator.Send(new NewSnapshotCommand(sessionName, session, UserId)); } [HttpPost("tile")] public async Task Post(string sessionName, [FromBody] Tile tile) { - var userId = int.Parse(HttpContext.User.Identity.Name); - await _mediator.Send(new NewTileCommand(sessionName, tile, userId)); + await _mediator.Send(new NewTileCommand(sessionName, tile, UserId)); } [HttpPost("overlay")] public async Task Post(string sessionName, [FromBody] Overlay overlay) { - var userId = int.Parse(HttpContext.User.Identity.Name); - await _mediator.Send(new NewOverlayCommand(sessionName, overlay, userId)); + await _mediator.Send(new NewOverlayCommand(sessionName, overlay, UserId)); } [HttpPost("wall")] public async Task Post(string sessionName, [FromBody] Wall wall) { - var userId = int.Parse(HttpContext.User.Identity.Name); - await _mediator.Send(new NewWallCommand(sessionName, wall, userId)); + await _mediator.Send(new NewWallCommand(sessionName, wall, UserId)); } [HttpDelete("tile")] public async Task Delete(string sessionName, [FromBody] Tile tile) { - var userId = int.Parse(HttpContext.User.Identity.Name); - await _mediator.Send(new DeleteTileCommand(sessionName, tile, userId)); + await _mediator.Send(new DeleteTileCommand(sessionName, tile, UserId)); } [HttpDelete("overlay")] public async Task Delete(string sessionName, [FromBody] Overlay overlay) { - var userId = int.Parse(HttpContext.User.Identity.Name); - await _mediator.Send(new DeleteOverlayCommand(sessionName, overlay, userId)); + await _mediator.Send(new DeleteOverlayCommand(sessionName, overlay, UserId)); } [HttpDelete("wall")] public async Task Delete(string sessionName, [FromBody] Wall wall) { - var userId = int.Parse(HttpContext.User.Identity.Name); - await _mediator.Send(new DeleteWallCommand(sessionName, wall, userId)); + await _mediator.Send(new DeleteWallCommand(sessionName, wall, UserId)); } } } \ No newline at end of file