Guest User

Untitled

a guest
Mar 15th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.79 KB | None | 0 0
  1. public ActionResult EditarPerfil()
  2. {
  3. ViewBag.EditarPerfilResultado = "";
  4. if (!User.Identity.IsAuthenticated) return RedirectToAction("LogOn", "Account");
  5.  
  6. UserModel model = new UserModel();
  7. User user = userRepo.FindUserByUserName(User.Identity.Name);
  8. EFCityRepository cityRepo = new EFCityRepository();
  9. EFGenderRepository genderRepo = new EFGenderRepository();
  10.  
  11. model.Cities = new List<SelectListItem>();
  12.  
  13. foreach (var city in cityRepo.FindAllCities())
  14. {
  15. model.Cities.Add(new SelectListItem { Text = city.Name, Value = city.CityId.ToString(), Selected = true });
  16. }
  17.  
  18. model.Genders = new List<SelectListItem>();
  19.  
  20. foreach (var gender in genderRepo.FindAllGenders())
  21. {
  22. model.Genders.Add(new SelectListItem { Text = gender.Name, Value = gender.GenderId.ToString(), Selected = true });
  23. }
  24.  
  25. model.CityId = Convert.ToInt32(user.CityId );
  26. model.GenderId = Convert.ToInt32(user.GenderId);
  27.  
  28. model.Name = user.Name;
  29. model.Lastname = user.Lastname;
  30. model.Address = user.Address;
  31. model.Email = user.Email;
  32. model.Telephone = user.Telephone;
  33. model.MobilePhone = user.MobilePhone;
  34. model.Carnet = user.Carnet;
  35. model.DateOfBirth = user.DateOfBirth;
  36. //model.Login = user.Login;
  37. //model.Password = user.Password;
  38. //tUserModel.ConfirmPassword=tUSer.
  39.  
  40.  
  41. return View(model);
  42. }
  43.  
  44. [HttpPost]
  45. public ActionResult EditarPerfil(UserModel Model)
  46. {
  47.  
  48. if (!User.Identity.IsAuthenticated) return RedirectToAction("LogOn", "Account");
  49.  
  50. UserModel model = new UserModel();
  51. User user = userRepo.FindUserByUserName(User.Identity.Name);
  52. EFCityRepository cityRepo = new EFCityRepository();
  53. EFGenderRepository genderRepo = new EFGenderRepository();
  54.  
  55. model.Cities = new List<SelectListItem>();
  56.  
  57. foreach (var city in cityRepo.FindAllCities())
  58. {
  59. model.Cities.Add(new SelectListItem { Text = city.Name, Value = city.CityId.ToString(), Selected = true });
  60. }
  61.  
  62. model.Genders = new List<SelectListItem>();
  63.  
  64. foreach (var gender in genderRepo.FindAllGenders())
  65. {
  66. model.Genders.Add(new SelectListItem { Text = gender.Name, Value = gender.GenderId.ToString(), Selected = true });
  67. }
  68.  
  69.  
  70. if ((Model.CityId == user.CityId) && (Model.GenderId == user.GenderId) && (Model.Name == user.Name) && (Model.Lastname == user.Lastname) && (Model.Address == user.Address) && (Model.Email == user.Email) && (Model.Telephone == user.Telephone) && (Model.MobilePhone == user.MobilePhone) && (Model.Carnet == user.Carnet) && (Model.DateOfBirth == user.DateOfBirth))
  71. {
  72. ViewBag.EditarPerfilResultado = "Para editar su perfil debe modificar alguno de sus datos";
  73.  
  74. }
  75. else
  76. {
  77. ViewBag.EditarPerfilResultado = "Perfil Editado con exito";
  78. user.CityId = Convert.ToInt32(Model.CityId);
  79. user.GenderId = Convert.ToInt32(Model.GenderId);
  80.  
  81. user.Name = Model.Name;
  82. user.Lastname = Model.Lastname;
  83. user.Address = Model.Address;
  84. user.Email = Model.Email;
  85. user.Telephone = Model.Telephone;
  86. user.MobilePhone = Model.MobilePhone;
  87. user.Carnet = Model.Carnet;
  88. user.DateOfBirth = Model.DateOfBirth;
  89.  
  90. userRepo.SaveChanges();
  91. }
  92.  
  93. model.CityId = Convert.ToInt32(user.CityId);
  94. model.GenderId = Convert.ToInt32(user.GenderId);
  95.  
  96. model.Name = user.Name;
  97. model.Lastname = user.Lastname;
  98. model.Address = user.Address;
  99. model.Email = user.Email;
  100. model.Telephone = user.Telephone;
  101. model.MobilePhone = user.MobilePhone;
  102. model.Carnet = user.Carnet;
  103. model.DateOfBirth = user.DateOfBirth;
  104. return View(model);
  105. }
  106.  
  107.  
  108.  
  109.  
  110.  
  111. @model GoldRemate.WebUI.Models.UserModel
  112.  
  113. @{
  114. ViewBag.Title = "EditarPerfil";
  115. }
  116.  
  117. <script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
  118. <script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
  119.  
  120.  
  121. @using (Html.BeginForm()) {
  122. @Html.ValidationSummary(true)
  123.  
  124. <fieldset>
  125. <legend>Edite su perfil</legend>
  126. <div class="clearfix">
  127. <div class="input">
  128. @ViewBag.EditarPerfilResultado
  129. </div>
  130. </div>
  131.  
  132. <div class="clearfix">
  133. @Html.LabelFor(model => model.Name)
  134. <div class="input">
  135. @Html.EditorFor(model => model.Name)
  136. @Html.ValidationMessageFor(model => model.Name)
  137. </div>
  138. </div>
  139.  
  140. <div class="clearfix">
  141. @Html.LabelFor(model => model.Lastname)
  142. <div class="input">
  143. @Html.EditorFor(model => model.Lastname)
  144. @Html.ValidationMessageFor(model => model.Lastname)
  145. </div>
  146. </div>
  147.  
  148. <div class="clearfix">
  149. @Html.LabelFor(model => model.Cities)
  150. <div class="input">
  151. @Html.DropDownListFor(model => model.CityId, Model.Cities)
  152. </div>
  153. </div>
  154.  
  155. <div class="clearfix">
  156. @Html.LabelFor(model => model.Genders)
  157. <div class="input">
  158. @Html.DropDownListFor(model => model.GenderId, Model.Genders)
  159. </div>
  160. </div>
  161.  
  162. <div class="clearfix">
  163. @Html.LabelFor(model => model.Address)
  164. <div class="input">
  165. @Html.EditorFor(model => model.Address)
  166. @Html.ValidationMessageFor(model => model.Address)
  167. </div>
  168. </div>
  169.  
  170. <div class="clearfix">
  171. @Html.LabelFor(model => model.Email)
  172. <div class="input">
  173. @Html.EditorFor(model => model.Email)
  174. @Html.ValidationMessageFor(model => model.Email)
  175. </div>
  176. </div>
  177.  
  178. <div class="clearfix">
  179. @Html.LabelFor(model => model.Telephone)
  180. <div class="input">
  181. @Html.EditorFor(model => model.Telephone)
  182. @Html.ValidationMessageFor(model => model.Telephone)
  183. </div>
  184. </div>
  185.  
  186. <div class="clearfix">
  187. @Html.LabelFor(model => model.MobilePhone)
  188. <div class="input">
  189. @Html.EditorFor(model => model.MobilePhone)
  190. @Html.ValidationMessageFor(model => model.MobilePhone)
  191. </div>
  192. </div>
  193.  
  194. <div class="clearfix">
  195. @Html.LabelFor(model => model.Carnet)
  196. <div class="input">
  197. @Html.EditorFor(model => model.Carnet)
  198. @Html.ValidationMessageFor(model => model.Carnet)
  199. </div>
  200. </div>
  201.  
  202. <div class="clearfix">
  203. @Html.LabelFor(model => model.DateOfBirth)
  204. <div class="input">
  205. @Html.TextBoxFor(model => model.DateOfBirth)
  206. @Html.ValidationMessageFor(model => model.DateOfBirth)
  207. </div>
  208. </div>
  209.  
  210. <p>
  211. <input type="submit" value="Actualizar Datos" class="btn primary frmsubmit" />
  212. </p>
  213. </fieldset>
  214. }
Add Comment
Please, Sign In to add comment