Advertisement
Guest User

Untitled

a guest
Dec 8th, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. ==================================JS===========================================
  2. var user = Ext.Ajax.request({
  3. method: 'GET',
  4. url: '/UserAccount/GetUserData',
  5. success: function (response) {
  6. user = Ext.util.JSON.decode(response.responseText).results;
  7. Ext.getCmp('user-name').setHtml(user.Username);
  8. var image = new Image();
  9. image.src = 'data:image/png;base64,' + user.ProfilePictureString;
  10. var e = Ext.getCmp('dashboard-profile-picture');
  11. e.setSrc(image.src);
  12. }
  13. });
  14.  
  15.  
  16.  
  17. ==============================================================================
  18.  
  19.  
  20.  
  21. =========================== C# ===========================================
  22. public ActionResult GetUserData()
  23. {
  24. if (Session["user"] != null)
  25. {
  26. Response.StatusCode = (int)HttpStatusCode.OK;
  27. var results = new UserRepository().GetUserInfo(Session["user"].ToString());
  28.  
  29. return Json(new { results }, JsonRequestBehavior.AllowGet); //TODO: add code for sending back the navigation data
  30. }
  31. Response.StatusCode = (int)HttpStatusCode.Unauthorized;
  32. return Json("Unauthorised access at this point, you must be logged into an account!");
  33. }
  34.  
  35.  
  36.  
  37.  
  38. in other c# file
  39.  
  40.  
  41.  
  42.  
  43. public User GetUserInfo(string name)
  44. {
  45. var _db = base.GetDatabaseConnection();
  46. if (!String.IsNullOrWhiteSpace(name))
  47. {
  48. return _db.SingleOrDefault<User>("WHERE username = @0", name);
  49. }
  50. else
  51. {
  52. return null;
  53. }
  54. }
  55.  
  56. ==============================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement