示例#1
0
        public async Task <IActionResult> CreateGridParameters([FromBody] GridModel gridParameters)
        {
            if (!ModelState.IsValid)
            {
                //TODO: use FluentValidation
                return(BadRequest(new ErrorResponse(error: ModelState.Values.ToString())));
            }
            try
            {
                var response = await _gridHandler.CreateGridParameters(gridParameters);

                return(StatusCode(StatusCodes.Status201Created, response.ToString()));
            }
            catch (Exception e)
            {
                //TODO: question: can we create more grids for one user? if so then we should allow more posts and make put requests with gridId and not userId
                if (e is ServerException)
                {
                    return(StatusCode(StatusCodes.Status500InternalServerError, new ErrorResponse(error: "Server exception", errorMessage: e.ToString()).ToString()));
                }
                return(StatusCode(StatusCodes.Status500InternalServerError, new ErrorResponse(error: "Internal server error", errorMessage: e.ToString()).ToString()));
            }
        }
示例#2
0
        public async Task <IActionResult> CreateGridParameters([FromBody] GridTemplate gridTemplate)
        {
            try
            {
                var oldGridModel = (GridModel)HttpContext.Items[Text.Grid];
                if (oldGridModel != null)
                {
                    return(StatusCode(StatusCodes.Status403Forbidden, new ErrorResponse(Text.GridConfigurationError).ToString()));
                }
                gridTemplate.OwnerId = HttpContext.Items[Text.UserId]?.ToString();
                var response = await _gridHandler.CreateGridParameters(gridTemplate);

                return(StatusCode(StatusCodes.Status201Created, response.ToString()));
            }
            catch (Exception e)
            {
                if (e is ServerException)
                {
                    return(StatusCode(StatusCodes.Status500InternalServerError, new ErrorResponse(error: Text.ServerException, errorMessage: e.ToString()).ToString()));
                }
                return(StatusCode(StatusCodes.Status500InternalServerError, new ErrorResponse(error: Text.InternalServerError, errorMessage: e.ToString()).ToString()));
            }
        }