Ejemplo n.º 1
0
        public ActionResult Edit(EditProfileViewModel model, HttpPostedFileBase ImageUrl, string selectedInterests)
        {
            var user = UserManager.FindById(User.Identity.GetUserId());
            
            var errors = ModelState.Values.SelectMany(v => v.Errors);
            if (ImageUrl == null)
            {
                model.ImageUrl = user.ImageUrl;
            }
            else
            {
                if (!ImageSaver.IsImage(ImageUrl))
                {
                    ModelState.AddModelError("Image Upload", "You can upload only images");
                }
            }
            if (selectedInterests == "")
            {
                ModelState.AddModelError("Interests select", "You need to select interests");
            }

            if (ModelState.IsValid)
            {
                ApplicationUser updatedUser = db.Users.SingleOrDefault(x => x.UserName == user.UserName);
                updatedUser.FirstName = model.FirstName;
                updatedUser.LastName = model.LastName;
                updatedUser.Gender = model.Gender;
                updatedUser.BirthDate = model.BirthDate.Date;
                updatedUser.HomeAddress = model.Address;
                updatedUser.PlaceLatitude = model.PlaceLatitude;
                updatedUser.PlaceLongitude = model.PlaceLongitude;
                updatedUser.Interests.Clear();
                updatedUser.Interests = GetSelectedInterests(selectedInterests);
                uploadAndSetImage(ref updatedUser, ImageUrl);
                db.SaveChanges();
                ViewBag.AllInterests = InterestsFromObjects.LoadInterestViewModelsFromInterests(updatedUser.Interests, db);
                return Redirect("/Account/ShowProfile");
            }
            ViewBag.AllInterests = InterestsFromObjects.LoadInterestViewModelsFromInterests(user.Interests, db);
            buildDateViewBags();
            return View(model);
        }
Ejemplo n.º 2
0
        public ActionResult Edit()
        {
            var user = UserManager.FindById(User.Identity.GetUserId());
            EditProfileViewModel profile = new EditProfileViewModel();
            profile.FirstName = user.FirstName;
            profile.LastName = user.LastName;
            if (user.Gender == "F")
                profile.Gender = "Female";
            else
                profile.Gender = "Male";

            profile.ImageUrl = user.ImageUrl;
            profile.BirthDate = user.BirthDate.Value;
            profile.BirthDateDay = user.BirthDate.Value.Day;
            profile.BirthDateMonth = user.BirthDate.Value.Month;
            profile.BirthDateYear = user.BirthDate.Value.Year;
            profile.Address = user.HomeAddress;
            profile.PlaceLatitude = user.PlaceLatitude;
            profile.PlaceLongitude = user.PlaceLongitude;

            ViewBag.AllInterests = InterestsFromObjects.LoadInterestViewModelsFromInterests(user.Interests, db);

            buildDateViewBags();
            return View(profile);
        }