Exemplo n.º 1
0
        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;

            try
            {
                var response = RpcWrapper.CallServiceByGet("/api/entity/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"));
            }
        }
Exemplo n.º 2
0
 public IActionResult GetClaimDetail([FromQuery] int formid)
 {
     try
     {
         var response = RpcWrapper.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));
     }
 }
Exemplo n.º 3
0
 public IActionResult QueryWorkFlowById([FromQuery] int workflowId)
 {
     try
     {
         var response = RpcWrapper.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"));
     }
 }
Exemplo n.º 4
0
 public IActionResult QueryFinancialByWorkFlow([FromQuery] int workflowId)
 {
     try
     {
         var response = RpcWrapper.CallServiceByGet("/api/financial/workflow", $"id={workflowId}", $"type=workflowid");
         if (!response.IsSuccessCode)
         {
             return(NotFound("try again"));
         }
         var res = JsonSerializer.Deserialize <List <FinancialForm> >(response.Body);
         return(Ok(res));
     }
     catch (JsonException)
     {
         return(BadRequest("internal error"));
     }
     catch (Exception)
     {
         return(NotFound("try again"));
     }
 }
Exemplo n.º 5
0
 public IActionResult QueryClaimChemicals([FromQuery] long formid)
 {
     try
     {
         var response = RpcWrapper.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"));
     }
 }
Exemplo n.º 6
0
 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(ifcertification));
                 }
                 else
                 {
                     UserRoleCache.RemoveUserRoleFromCache(ifcertification);
                 }
             }
         }
         _logger.LogInformation("Call RpcWrapper, method: get.");
         _logger.LogInformation("port: {port}", RpcWrapper.Port);
         var response = RpcWrapper.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(certification);
             // 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
         }));
     }
 }