public IActionResult QueryUserChemicals() { var certification = HttpContext.Request.Headers["certification"]; var success = UserRoleCache.TryGetUserRole(certification, out var userRole); if (!success) { return(NotFound("try again")); } int userid = userRole.User.UserId; _logger.LogInformation("query chemicals of user id: {1}", userid); try { var response = HttpWrapper.CallServiceByGet("/api/entity/user/chemicals", $"userid={userid}"); if (!response.IsSuccessCode) { return(NotFound("try again")); } var res = JsonSerializer.Deserialize <List <Chemical> >(response.Body); return(Ok(res)); } catch (JsonException) { return(BadRequest("internal error")); } catch (Exception) { return(NotFound("try again")); } }
public IActionResult QueryWorkFlows() { var certification = HttpContext.Request.Headers["certification"]; var success = UserRoleCache.TryGetUserRole(certification, out var userRole); if (!success) { return(NotFound("try again")); } int userId = userRole.User.UserId; try { var response = HttpWrapper.CallServiceByGet("/api/entity/workflows", $"id={userId}", $"type=userid"); if (!response.IsSuccessCode) { return(NotFound("try again")); } var res = JsonSerializer.Deserialize <List <WorkFlow> >(response.Body); return(Ok(res)); } catch (JsonException) { return(BadRequest("internal error")); } catch (Exception) { return(NotFound("try again")); } }
public IActionResult Purchase([FromQuery] int workflowid) { try { var response = HttpWrapper.CallServiceByGet("/api/entity/purchase", $"workflowid={workflowid}"); if (!response.IsSuccessCode) { return(NotFound("internal error")); } return(Ok()); } catch (Exception) { return(NotFound("try again")); } }
public IActionResult GetClaimDetail([FromQuery] int formid) { try { var response = HttpWrapper.CallServiceByGet("/api/claim", $"formid={formid}"); if (!response.IsSuccessCode) { return(NotFound("try again")); } var res = JsonSerializer.Deserialize <PostClaimFormParam>(response.Body); return(Ok(res)); } catch (Exception e) { _logger.LogError(e.Message); return(NotFound(e.Message)); } }
public IActionResult QueryWorkFlowById([FromQuery] int workflowId) { try { var response = HttpWrapper.CallServiceByGet("/api/entity/workflow", $"workflowid={workflowId}"); if (!response.IsSuccessCode) { return(NotFound("try again")); } var res = JsonSerializer.Deserialize <WorkFlow>(response.Body); return(Ok(res)); } catch (JsonException) { return(BadRequest("internal error")); } catch (Exception) { return(NotFound("try again")); } }
public IActionResult QueryClaimChemicals([FromQuery] long formid) { try { var response = HttpWrapper.CallServiceByGet("/api/entity/chemicals", $"labId={formid}"); if (!response.IsSuccessCode) { return(NotFound("try again")); } var res = JsonSerializer.Deserialize <List <Chemical> >(response.Body); return(Ok(res)); } catch (JsonException) { return(BadRequest("internal error")); } catch (Exception) { return(NotFound("try again")); } }
public IActionResult Login([FromForm] string username, [FromForm] string password) { _logger.LogInformation("Username: {username} try login.", username); try { if (HttpContext.Request.Headers.ContainsKey("certification")) { var ifcertification = HttpContext.Request.Headers["certification"]; if (UserRoleCache.TryGetUserRole(ifcertification, out var userRole)) { if (username == userRole.User.UserName) { var ret = new LoginReturn { Success = true, User = userRole.User, Roles = userRole.Roles, Certification = ifcertification }; return(Ok(ret)); } else { UserRoleCache.RemoveUserRoleFromCache(ifcertification); } } } _logger.LogInformation("Call RpcWrapper, method: get."); _logger.LogInformation("port: {port}", HttpWrapper.Port); var response = HttpWrapper.CallServiceByGet( "/api/userrole", $"username={username}"); if (!response.IsSuccessCode) { return(Ok(new LoginReturn { Success = false })); } var result = JsonSerializer.Deserialize <UserRoleResult>(response.Body); if (password == result.User.UserPassword) { string certification = Guid.NewGuid().ToString(); var ret = new LoginReturn { Success = true, User = result.User, Roles = result.Roles, Certification = certification }; UserRoleCache.AddUserRoleToCache(certification, result); return(Ok(ret)); // For easy debug //ret.Certification = "123"; //UserRoleCache.AddUserRoleToCache("123", result); //return Ok(ret); } return(Ok(new LoginReturn { Success = false })); } catch (Exception e) { // not sure if this should be write here _logger.LogError(e.Message); _logger.LogError("Call database_connector failed."); return(Ok(new LoginReturn { Success = false })); } }