Advertisement
Guest User

Untitled

a guest
Jul 19th, 2016
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.32 KB | None | 0 0
  1. public class MyAccountViewModel
  2. {
  3. public string Username { get; set; }
  4. public string LastName { get; set; }
  5. public string MiddleInitial { get; set; }
  6. public string State { get; set; }
  7. public string ZIP { get; set; }
  8. public string Telephone1 { get; set; }
  9. public string Telephone2 { get; set; }
  10. public string Email { get; set; }
  11. public string PreferredLanguage { get; set; }
  12. public int DateOfBirthDay { get; set; }
  13. public int DateOfBirthMonth { get; set; }
  14. public string NewPassword { get; set; }
  15. public string ConfirmNewPassword { get; set; }
  16. public List<QuestionAnswerPairModel> SecurityQuestionAnswers { get; set; }
  17. public List<SelectListItem> AllowedQuestions { get; set; }
  18. public List<SelectListItem> PreferredLanguageList
  19. {
  20. get
  21. {
  22. return new List<SelectListItem>
  23. {
  24. new SelectListItem { Text = "English", Value = "en", Selected = PreferredLanguage == "en"},
  25. new SelectListItem { Text = "Español", Value = "es", Selected = PreferredLanguage == "es"},
  26. };
  27. }
  28. }
  29.  
  30. public UserRegistration ToUserRegistration()
  31. {
  32. return new UserRegistration
  33. {
  34. Username = Username,
  35. FirstName = FirstName,
  36. MiddleInitial = MiddleInitial,
  37. LastName = LastName,
  38. AddressLine1 = Address1,
  39. AddressLine2 = Address2,
  40. City = City,
  41. State = State,
  42. Zip = ZIP,
  43. Telephone1 = Telephone1,
  44. Telephone2 = Telephone2,
  45. Email = Email,
  46. PreferredLanguage = PreferredLanguage,
  47. DateOfBirthDate = DateOfBirthDay,
  48. DateOfBirthMonth = DateOfBirthMonth
  49. };
  50. }
  51. }
  52.  
  53. public class QuestionAnswerPairModel
  54. {
  55. public int QuestionId { get; set; }
  56. public string Answer { get; set; }
  57.  
  58. public QuestionAnswerPair ToQuestionAnswerPair()
  59. {
  60. return new QuestionAnswerPair
  61. {
  62. QuestionId = QuestionId,
  63. Answer = Answer,
  64. HasChanged = Answer != "Type your answer"
  65. };
  66. }
  67. }
  68.  
  69. [HttpPost]
  70. public PartialViewResult UpdateMyAccount(MyAccountViewModel myAccountViewModel)
  71. {
  72. //the myAccountViewModel property has null set for all properties
  73. }
  74.  
  75. $.ajax({
  76. url: '@Url.Action("UpdateMyAccount", "MyAccount", new {area = ""})',
  77. type: 'post', // type: 'POST'
  78. //datatype: "json",
  79. contentType: "application/json; charset=utf-8", // contentType: "application/json"
  80. data: getMyAccount(), // data: JSON.stringify(getMyAccount()) and data: JSON.stringify({'myAccountViewModel': getMyAccount()}) and data: JSON.stringify({myAccountViewModel: getMyAccount()})
  81. success: function() {
  82. makeAjaxCall(accountInfo);
  83. }
  84. });
  85.  
  86. function getMyAccount() {
  87. return {
  88. Username: $('#Username').val(),
  89. FirstName: $('#FirstName').val(),
  90. LastName: $('#LastName').val(),
  91. MiddleInitial: $('#MiddleInitial').val(),
  92. Address1: $('#Address1').val(),
  93. Address2: $('#Address2').val(),
  94. City: $('#City').val(),
  95. State: $('#State').val(),
  96. ZIP: $('#ZIP').val(),
  97. Telephone1: $('#Telephone1').val(),
  98. Telephone2: $('#Telephone2').val(),
  99. Email: $('#Email').val(),
  100. PreferredLanguage: $('#PreferredLanguage').val(),
  101. DateOfBirthDay: $('#DateOfBirthDay').val(),
  102. DateOfBirthMonth: $('#DateOfBirthMonth').val(),
  103. NewPassword: $('#NewPassword').val(),
  104. ConfirmNewPassword: $('#ConfirmNewPassword').val(),
  105. SecurityQuestionAnswers: [
  106. {
  107. QuestionId: $('#originalQuestionId0').val(),
  108. Answer: $('#answerId0').val(),
  109. },
  110. {
  111. QuestionId: $('#originalQuestionId1').val(),
  112. Answer: $('#answerId1').val(),
  113. },
  114. {
  115. QuestionId: $('#originalQuestionId2').val(),
  116. Answer: $('#answerId2').val(),
  117. }
  118. ]
  119. };
  120. }
  121.  
  122. {"myAccountViewModel":{"SecurityQuestionAnswers":[{},{},{}]}}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement