ahmed elbarbary

ahmed elbarbary

  • NA
  • 1.6k
  • 254.8k

How to convert User class object to json file when success l

Aug 30 2019 11:17 PM
problem
How to convert User class object to json file when success login ?
I need to convert user class object to json file represent status of login and data related as following ;
this is actually desired result :
 
  1. {  
  2. "request_status" : {  
  3. "status" : "succeeded",  
  4. "code": 0,  
  5. "message" : "login succeeded!"  
  6. },  
  7. "user_data": {   
  8.   "UserFullName" : "Admin",   
  9.   "LoginTime" : "12:00"  
  10.     
  11. },  
  12. "branches": [  
  13. {   
  14.   "BranchCode" : "1",  
  15.   "BranchName":"Baha"   
  16.     
  17. }  
  18. ]  
  19. }  
  1. What I try is :  
  2.   
  3.  [HttpPost(Contracts.ApiRoutes.Login.PostUserLogin)]  
  4.         public  IActionResult PostUserLogins(Users user)  
  5.         {  
  6.             int LoginStatus = _AuthunticateService.PostUserLogin(user.UserName,user.Password ,out DataTable Branches,out string errorMessage, out int statusCode);  
  7.             if(LoginStatus == 0)  
  8.             {  
  9.                 user.StatusCode = statusCode;  
  10.                 user.StatusText = "succeeded";  
  11.                 user.MessageStatus = "login succeeded!";  
  12.                 if (Branches.Rows.Count > 0)  
  13.                 {  
  14.                     user.dtgetBranches = Branches;  
  15.                 }  
  16.                 user.LoginTime = DateTime.Now.ToString();  
  17. // How to convert user class after assign values to json result as script above diplay  
  18.             }  
  19.          }  
  20. public class Users  
  21.     {  
  22.         public string UserName { getset; }  
  23.         public string Password { getset; }  
  24.         public string MessageStatus { getset; }  
  25.         public int StatusCode { getset; }  
  26.         public string StatusText { getset; }  
  27.         public string IpAddress { getset; }  
  28.         public string BrowserInfo { getset; }  
  29.         public DataTable dtgetBranches { getset; }  
  30.         public string LoginTime { getset; }  
  31.     }  
  32. How to convert user class object to json format as above ?  
 

Answers (1)