Advertisement
Guest User

Untitled

a guest
Jul 25th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.58 KB | None | 0 0
  1. // Фамилия пользователя
  2. public string SecondName { get; set; }
  3. // Имя пользователя
  4. public string FirstName { get; set; }
  5. // Отчество пользователя
  6. public string PatronymicName { get; set; }
  7. // Дата рождения, необходима для фильтрации игр по возрастной категории
  8. public DateTime? BirthDate { get; set; }
  9. // Номер телефона
  10. public string TelephoneNumber { get; set; }
  11.  
  12. <ul class="nav nav-tabs" id="myTab">
  13. <li class="active">
  14. <a href="#mygames" data-toggle="tab">Моя коллекция игр</a>
  15. </li>
  16. <li>
  17. <a href="#mydata" data-toggle="tab">Мои данные</a>
  18. </li>
  19. </ul>
  20.  
  21. <div class="tab-pane" id="mydata">
  22. @Html.Partial("_EditInfo");
  23. </div>
  24.  
  25. @model MyGameStore.Models.EditInfoViewModel
  26.  
  27. @using (Html.BeginForm("EditInfo", "Manage", FormMethod.Post, new { @class = "form-signin form-horizontal", role = "form" }))
  28. {
  29. @Html.AntiForgeryToken()
  30. @Html.ValidationSummary("", new { @class = "text-danger" })
  31. <div class="form-group">
  32.  
  33. <div class="col-xs-4">
  34. @Html.LabelFor(m => m.SecondName, new { @class = "col-md-2 control-label" })
  35. @Html.TextBoxFor(m => m.SecondName, new { @class = "form-control", value = Model.SecondName })
  36. </div>
  37. </div>
  38. <div class="form-group">
  39.  
  40. <div class="col-xs-4">
  41. <div class="col-xs-4">
  42. @Html.LabelFor(m => m.FirstName, new { @class = "col-md-2 control-label" })
  43. @Html.TextBoxFor(m => m.FirstName, new { @class = "form-control", value = Model.FirstName })
  44. </div>
  45. </div>
  46.  
  47. <div class="form-group">
  48.  
  49. <div class="col-xs-4">
  50. @Html.LabelFor(m => m.PatronymicName, new { @class = "col-md-2 control-label" })
  51. @Html.TextBoxFor(m => m.PatronymicName, new { @class = "form-control", value = Model.PatronymicName })
  52. </div>
  53. </div>
  54.  
  55. <div class="form-group">
  56. <div class="col-xs-4">
  57. @Html.LabelFor(m => m.BirthDate, new { @class = "col-md-2 control-label" })
  58. @Html.TextBoxFor(m => m.BirthDate, new { @class = "form-control", value = Model.BirthDate })
  59. </div>
  60. </div>
  61. <div class="form-group">
  62.  
  63. <div class="col-xs-4">
  64. @Html.LabelFor(m => m.TelephoneNumber, new { @class = "col-md-2 control-label" })
  65. @Html.TextBoxFor(m => m.TelephoneNumber, new { @class = "form-control", value = Model.TelephoneNumber })
  66. </div>
  67. </div>
  68.  
  69. <div class="form-group">
  70.  
  71. <div class="col-xs-4">
  72. <br />
  73. <button class="btn btn-primary btn-block" type="submit"><i class="fa fa-save"></i> Применить</button>
  74. <button class="btn btn-default btn-block" type="reset"><i class="fa fa-repeat"></i> Сбросить</button>
  75. </div>
  76. </div>
  77. </div>
  78. }
  79.  
  80. public async Task<ActionResult> EditInfo()
  81. {
  82. var user = await UserManager.FindByIdAsync(User.Identity.GetUserId());
  83.  
  84. if (user == null)
  85. return HttpNotFound();
  86.  
  87. var model = new EditInfoViewModel
  88. {
  89. SecondName = user.SecondName,
  90. FirstName = user.FirstName,
  91. PatronymicName = user.PatronymicName,
  92. BirthDate = user.BirthDate,
  93. TelephoneNumber = user.TelephoneNumber
  94. };
  95.  
  96. return PartialView("_EditInfo", model);
  97. }
  98.  
  99. [HttpPost]
  100. [ValidateAntiForgeryToken]
  101. public async Task<ActionResult> EditInfo([Bind(Include = "SecondName,FirstName,PatronymicName,BirthDate,TelephoneNumber")] EditInfoViewModel model)
  102. {
  103. var user = await UserManager.FindByEmailAsync(User.Identity.Name);
  104.  
  105. if (!ModelState.IsValid)
  106. return PartialView("_EditInfo", model);
  107.  
  108. if (user != null)
  109. {
  110. user.SecondName = model.SecondName;
  111. user.FirstName = model.FirstName;
  112. user.PatronymicName = model.PatronymicName;
  113. user.BirthDate = model.BirthDate;
  114. user.TelephoneNumber = model.TelephoneNumber;
  115.  
  116. var result = await UserManager.UpdateAsync(user);
  117. if (result.Succeeded)
  118. return RedirectToAction("Index");
  119.  
  120. ModelState.AddModelError("", "Что-то пошло не так");
  121. }
  122. else
  123. ModelState.AddModelError("", "Пользователь не найден");
  124.  
  125. return PartialView("_EditInfo", model);
  126. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement