Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public ActionResult EditarPerfil()
- {
- ViewBag.EditarPerfilResultado = "";
- if (!User.Identity.IsAuthenticated) return RedirectToAction("LogOn", "Account");
- UserModel model = new UserModel();
- User user = userRepo.FindUserByUserName(User.Identity.Name);
- EFCityRepository cityRepo = new EFCityRepository();
- EFGenderRepository genderRepo = new EFGenderRepository();
- model.Cities = new List<SelectListItem>();
- foreach (var city in cityRepo.FindAllCities())
- {
- model.Cities.Add(new SelectListItem { Text = city.Name, Value = city.CityId.ToString(), Selected = true });
- }
- model.Genders = new List<SelectListItem>();
- foreach (var gender in genderRepo.FindAllGenders())
- {
- model.Genders.Add(new SelectListItem { Text = gender.Name, Value = gender.GenderId.ToString(), Selected = true });
- }
- model.CityId = Convert.ToInt32(user.CityId );
- model.GenderId = Convert.ToInt32(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;
- //model.Login = user.Login;
- //model.Password = user.Password;
- //tUserModel.ConfirmPassword=tUSer.
- return View(model);
- }
- [HttpPost]
- public ActionResult EditarPerfil(UserModel Model)
- {
- if (!User.Identity.IsAuthenticated) return RedirectToAction("LogOn", "Account");
- UserModel model = new UserModel();
- User user = userRepo.FindUserByUserName(User.Identity.Name);
- EFCityRepository cityRepo = new EFCityRepository();
- EFGenderRepository genderRepo = new EFGenderRepository();
- model.Cities = new List<SelectListItem>();
- foreach (var city in cityRepo.FindAllCities())
- {
- model.Cities.Add(new SelectListItem { Text = city.Name, Value = city.CityId.ToString(), Selected = true });
- }
- model.Genders = new List<SelectListItem>();
- foreach (var gender in genderRepo.FindAllGenders())
- {
- model.Genders.Add(new SelectListItem { Text = gender.Name, Value = gender.GenderId.ToString(), Selected = true });
- }
- 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))
- {
- ViewBag.EditarPerfilResultado = "Para editar su perfil debe modificar alguno de sus datos";
- }
- else
- {
- ViewBag.EditarPerfilResultado = "Perfil Editado con exito";
- user.CityId = Convert.ToInt32(Model.CityId);
- user.GenderId = Convert.ToInt32(Model.GenderId);
- user.Name = Model.Name;
- user.Lastname = Model.Lastname;
- user.Address = Model.Address;
- user.Email = Model.Email;
- user.Telephone = Model.Telephone;
- user.MobilePhone = Model.MobilePhone;
- user.Carnet = Model.Carnet;
- user.DateOfBirth = Model.DateOfBirth;
- userRepo.SaveChanges();
- }
- model.CityId = Convert.ToInt32(user.CityId);
- model.GenderId = Convert.ToInt32(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;
- return View(model);
- }
- @model GoldRemate.WebUI.Models.UserModel
- @{
- ViewBag.Title = "EditarPerfil";
- }
- <script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
- <script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
- @using (Html.BeginForm()) {
- @Html.ValidationSummary(true)
- <fieldset>
- <legend>Edite su perfil</legend>
- <div class="clearfix">
- <div class="input">
- @ViewBag.EditarPerfilResultado
- </div>
- </div>
- <div class="clearfix">
- @Html.LabelFor(model => model.Name)
- <div class="input">
- @Html.EditorFor(model => model.Name)
- @Html.ValidationMessageFor(model => model.Name)
- </div>
- </div>
- <div class="clearfix">
- @Html.LabelFor(model => model.Lastname)
- <div class="input">
- @Html.EditorFor(model => model.Lastname)
- @Html.ValidationMessageFor(model => model.Lastname)
- </div>
- </div>
- <div class="clearfix">
- @Html.LabelFor(model => model.Cities)
- <div class="input">
- @Html.DropDownListFor(model => model.CityId, Model.Cities)
- </div>
- </div>
- <div class="clearfix">
- @Html.LabelFor(model => model.Genders)
- <div class="input">
- @Html.DropDownListFor(model => model.GenderId, Model.Genders)
- </div>
- </div>
- <div class="clearfix">
- @Html.LabelFor(model => model.Address)
- <div class="input">
- @Html.EditorFor(model => model.Address)
- @Html.ValidationMessageFor(model => model.Address)
- </div>
- </div>
- <div class="clearfix">
- @Html.LabelFor(model => model.Email)
- <div class="input">
- @Html.EditorFor(model => model.Email)
- @Html.ValidationMessageFor(model => model.Email)
- </div>
- </div>
- <div class="clearfix">
- @Html.LabelFor(model => model.Telephone)
- <div class="input">
- @Html.EditorFor(model => model.Telephone)
- @Html.ValidationMessageFor(model => model.Telephone)
- </div>
- </div>
- <div class="clearfix">
- @Html.LabelFor(model => model.MobilePhone)
- <div class="input">
- @Html.EditorFor(model => model.MobilePhone)
- @Html.ValidationMessageFor(model => model.MobilePhone)
- </div>
- </div>
- <div class="clearfix">
- @Html.LabelFor(model => model.Carnet)
- <div class="input">
- @Html.EditorFor(model => model.Carnet)
- @Html.ValidationMessageFor(model => model.Carnet)
- </div>
- </div>
- <div class="clearfix">
- @Html.LabelFor(model => model.DateOfBirth)
- <div class="input">
- @Html.TextBoxFor(model => model.DateOfBirth)
- @Html.ValidationMessageFor(model => model.DateOfBirth)
- </div>
- </div>
- <p>
- <input type="submit" value="Actualizar Datos" class="btn primary frmsubmit" />
- </p>
- </fieldset>
- }
Add Comment
Please, Sign In to add comment