public async Task <APIGatewayProxyResponse> GetCompaniesByEmployee(APIGatewayProxyRequest request, ILambdaContext context) { var bodyMessage = String.Empty; HttpStatusCode statusCode = HttpStatusCode.OK; var jwtHandler = new JwtSecurityTokenHandler(); //grab employeeid var token = jwtHandler.ReadToken(request.Headers["Authorization"].Replace("Bearer ", "")) as JwtSecurityToken; var identity = token.Payload.Sub; var getCompanies = DBUtilityFactory.GetCompanies(DBUtilityFactory.CreateDyanmoDBContext()); try { bodyMessage = JsonConvert.SerializeObject(getCompanies.Execute(identity).Select(x => x.ToJson()).ToArray()); } catch (Exception ex) { bodyMessage = "{ Status: Failed , Message: Server Issues}"; statusCode = HttpStatusCode.InternalServerError; } var response = new APIGatewayProxyResponse { StatusCode = (int)statusCode, Body = bodyMessage, Headers = new Dictionary <string, string> { { "Access-Control-Allow-Origin", "*" }, { "Access-Control-Allow-Credentials", "true" } } }; return(response); }
//Check //TODO: May not need this method anymore public async Task <APIGatewayProxyResponse> GetCompanies(APIGatewayProxyRequest request, ILambdaContext context) { var bodyMessage = String.Empty; HttpStatusCode statusCode = HttpStatusCode.OK; var input = request.Body; var getCompanies = DBUtilityFactory.GetCompanies(DBUtilityFactory.CreateDyanmoDBContext()); try { bodyMessage = JsonConvert.SerializeObject(getCompanies.Execute(input).Select(x => x.ToJson())).ToString(); } catch { bodyMessage = "{ Status: Failed , Message: Server Issues}"; statusCode = HttpStatusCode.InternalServerError; } var response = new APIGatewayProxyResponse { StatusCode = (int)statusCode, Body = bodyMessage, Headers = new Dictionary <string, string> { { "Access-Control-Allow-Origin", "*" }, { "Access-Control-Allow-Credentials", "true" } } }; return(response); }