public async Task <ActionResult> Delete(WorldDeleteRequest request, [FromHeader(Name = "Authorization")] string jwt) { var idclaim = _authenticationHelper.getUserIdFromToken(jwt); if (idclaim == request.UserId) { try { if (await _worldManagementService.DeleteWorld(request)) { return(Ok("world: " + request.Title + "succesfully deleted")); } else { return(BadRequest("World not succesfully deleted")); } } catch (Exception ex) { return(BadRequest(ex.Message)); } } else { return(Unauthorized("You are not authorised to do this")); } }
public async Task <bool> DeleteWorld(WorldDeleteRequest request) { var world = _worldRepository.Get(request.WorldId).Result; if (world.Title == request.Title && world.Owner.Id == request.UserId) { await _worldRepository.remove(request.WorldId); await _worldPublisher.DeleteWorldWorld(request.WorldId); return(true); } else { throw new VariablesDoNotMatchException("The title or/and ownerId are not correct, so this world will not be deleted"); } }