public async Task <IActionResult> UpdateGridParameters([FromBody] GridTemplate grid) { try { if (grid.OwnerId != HttpContext.Items[Text.UserId]?.ToString()) { return(StatusCode(StatusCodes.Status403Forbidden, new ErrorResponse(Text.UnownedResource).ToString())); } var oldGridModel = (GridModel)HttpContext.Items[Text.Grid]; if (oldGridModel == null) { return(StatusCode(StatusCodes.Status403Forbidden, new ErrorResponse(Text.ResourceDoesNotExist).ToString())); } var response = await _gridHandler.UpdateGridParameters(grid); return(StatusCode(StatusCodes.Status200OK, 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())); } }
public async Task <IActionResult> UpdateGridParameters([FromBody] GridModel gridParameters) { //TODO: here we should check that gridParameters.id is owned by userId from jwt, otherwise refuse if (!ModelState.IsValid) { //TODO: use FluentValidation return(BadRequest(new ErrorResponse(error: ModelState.Values.ToString()))); } try { var response = await _gridHandler.UpdateGridParameters(gridParameters); return(StatusCode(StatusCodes.Status200OK, 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())); } }