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 :
- {
- "request_status" : {
- "status" : "succeeded",
- "code": 0,
- "message" : "login succeeded!"
- },
- "user_data": {
- "UserFullName" : "Admin",
- "LoginTime" : "12:00"
-
- },
- "branches": [
- {
- "BranchCode" : "1",
- "BranchName":"Baha"
-
- }
- ]
- }
- What I try is :
-
- [HttpPost(Contracts.ApiRoutes.Login.PostUserLogin)]
- public IActionResult PostUserLogins(Users user)
- {
- int LoginStatus = _AuthunticateService.PostUserLogin(user.UserName,user.Password ,out DataTable Branches,out string errorMessage, out int statusCode);
- if(LoginStatus == 0)
- {
- user.StatusCode = statusCode;
- user.StatusText = "succeeded";
- user.MessageStatus = "login succeeded!";
- if (Branches.Rows.Count > 0)
- {
- user.dtgetBranches = Branches;
- }
- user.LoginTime = DateTime.Now.ToString();
-
- }
- }
- public class Users
- {
- public string UserName { get; set; }
- public string Password { get; set; }
- public string MessageStatus { get; set; }
- public int StatusCode { get; set; }
- public string StatusText { get; set; }
- public string IpAddress { get; set; }
- public string BrowserInfo { get; set; }
- public DataTable dtgetBranches { get; set; }
- public string LoginTime { get; set; }
- }
- How to convert user class object to json format as above ?