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()
         }));
     }
 }
Пример #2
0
        public async Task <GenericResponseView <EndGameResponseView> > End()
        {
            var response = new GenericResponseView <EndGameResponseView>();

            response.Model = await _gameService.EndGame(UserId);

            return(response);
        }
Пример #3
0
        public async Task <GenericResponseView <HasActiveGameGameResponseView> > HasActiveGame()
        {
            var response = new GenericResponseView <HasActiveGameGameResponseView>();

            response.Model = await _gameService.HasActiveGame(UserId);

            return(response);
        }
Пример #4
0
        public async Task <GenericResponseView <GetStateGameResponseView> > GetState()
        {
            var response = new GenericResponseView <GetStateGameResponseView>();

            response.Model = await _gameService.GetState(UserId);

            return(response);
        }
Пример #5
0
        public async Task <GenericResponseView <GetAllUserAccountResponseView> > GetAllUsers()
        {
            var response = new GenericResponseView <GetAllUserAccountResponseView>();

            response.Model = await _accountService.GetAllUsers();

            return(response);
        }
Пример #6
0
        public async Task <GenericResponseView <StartGameResponseView> > Start([FromBody] StartGameView model)
        {
            var response = new GenericResponseView <StartGameResponseView>();

            response.Model = await _gameService.StartGame(UserId, model);

            return(response);
        }
Пример #7
0
        public async Task <GenericResponseView <LoginAccountResponseView> > Register([FromBody] RegisterAccountView model)
        {
            var response = new GenericResponseView <LoginAccountResponseView>();

            response.Model = await _accountService.Register(model);

            return(response);
        }
Пример #8
0
        protected async Task <IActionResult> Execute(Func <Task> func)
        {
            var response = new GenericResponseView <string>();

            await func();

            return(Ok(response));
        }
Пример #9
0
        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));
        }
Пример #10
0
 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);
     }
 }
Пример #12
0
 public async Task<GenericResponseView<GetGameInfoHistoryResponseView>> GetGameInfo([FromBody]GetGameInfoHistoryView model)
 {
     var response = new GenericResponseView<GetGameInfoHistoryResponseView>();
     response.Model = await _historyService.GetGameInfo(UserId, model);
     return response;
 }
Пример #13
0
 public async Task<GenericResponseView<GetAllGamesHistoryResponseView>> GetAllGames()
 {
     var response = new GenericResponseView<GetAllGamesHistoryResponseView>();
     response.Model = await _historyService.GetAllGames(UserId);
     return response;
 }