public async Task Invoke(HttpContext context) { try { await _next(context); } catch (CustomServiceException ex) { context.Response.ContentType = "application/json"; context.Response.StatusCode = (int)HttpStatusCode.InternalServerError; var response = new GenericResponseView <string>(); response.Error = ex.Message; await context.Response.WriteAsync( JsonConvert.SerializeObject(response, new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() })); } catch (Exception ex) { context.Response.ContentType = "application/json"; context.Response.StatusCode = (int)HttpStatusCode.InternalServerError; var response = new GenericResponseView <string>(); response.Error = Constants.Messages.ServerError; await context.Response.WriteAsync( JsonConvert.SerializeObject(response, new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() })); } }
public async Task <GenericResponseView <EndGameResponseView> > End() { var response = new GenericResponseView <EndGameResponseView>(); response.Model = await _gameService.EndGame(UserId); return(response); }
public async Task <GenericResponseView <HasActiveGameGameResponseView> > HasActiveGame() { var response = new GenericResponseView <HasActiveGameGameResponseView>(); response.Model = await _gameService.HasActiveGame(UserId); return(response); }
public async Task <GenericResponseView <GetStateGameResponseView> > GetState() { var response = new GenericResponseView <GetStateGameResponseView>(); response.Model = await _gameService.GetState(UserId); return(response); }
public async Task <GenericResponseView <GetAllUserAccountResponseView> > GetAllUsers() { var response = new GenericResponseView <GetAllUserAccountResponseView>(); response.Model = await _accountService.GetAllUsers(); return(response); }
public async Task <GenericResponseView <StartGameResponseView> > Start([FromBody] StartGameView model) { var response = new GenericResponseView <StartGameResponseView>(); response.Model = await _gameService.StartGame(UserId, model); return(response); }
public async Task <GenericResponseView <LoginAccountResponseView> > Register([FromBody] RegisterAccountView model) { var response = new GenericResponseView <LoginAccountResponseView>(); response.Model = await _accountService.Register(model); return(response); }
protected async Task <IActionResult> Execute(Func <Task> func) { var response = new GenericResponseView <string>(); await func(); return(Ok(response)); }
public async Task <IActionResult> Execute <T>(Func <Task <T> > func) { var response = new GenericResponseView <T>(); var result = await func(); response.Model = result; return(Ok(response.Model)); }
public void OnActionExecuting(ActionExecutingContext context) { if (!context.ModelState.IsValid) { var errorResult = new GenericResponseView <string>(); errorResult.Error = context.ModelState.FirstErrorOrDefault(); context.Result = new BadRequestObjectResult(errorResult); } }
public override void OnActionExecuting(ActionExecutingContext context) { if (!context.ModelState.IsValid) { var errorResponse = new GenericResponseView <string>(); errorResponse.Error = context.ModelState.GetFirstErrorFromModelState(); context.Result = new BadRequestObjectResult(errorResponse); } }
public async Task<GenericResponseView<GetGameInfoHistoryResponseView>> GetGameInfo([FromBody]GetGameInfoHistoryView model) { var response = new GenericResponseView<GetGameInfoHistoryResponseView>(); response.Model = await _historyService.GetGameInfo(UserId, model); return response; }
public async Task<GenericResponseView<GetAllGamesHistoryResponseView>> GetAllGames() { var response = new GenericResponseView<GetAllGamesHistoryResponseView>(); response.Model = await _historyService.GetAllGames(UserId); return response; }