Ejemplo n.º 1
0
        public ActionResult EditProfile(EditProfileBindingModel model)
        {
            var loggedUserId = this.User.Identity.GetUserId();
            var user = this.Data.Users.Find(loggedUserId);

            //if (!ModelState.IsValid)
            //{
            //    ModelState.AddModelError("", "Invalid update profile attempt.");

            //    return View(model);
            //}

            if (model.FullName != null)
            {
                user.ScreenName = model.FullName;
            }

            if (model.AvatarUrl != null)
            {
                user.AvatarUrl = model.AvatarUrl;
            }

            if (model.Bio != null)
            {
                user.Bio = model.Bio;
            }

            if (model.BirthDay != null)
            {
                user.BirthDay = model.BirthDay;
            }

            if (model.Website != null)
            {
                user.Website = model.Website;
            }

            if (model.Location != null)
            {
                user.Location = model.Location;
            }

            this.Data.SaveChanges();

            return RedirectToAction("ShowProfile", "Users");
        }
Ejemplo n.º 2
0
        public ActionResult EditProfile(EditProfileBindingModel model)
        {
            if (!this.ModelState.IsValid)
            {
                return this.RedirectToAction("EditProfile", new { Message = ManageMessageId.Error });
            }

            var userId = this.User.Identity.GetUserId();
            var user = this.Data.Users.Find(userId);

            if (user == null)
            {
                return this.RedirectToAction("EditProfile", new { Message = ManageMessageId.Error });
            }

            string profileImage = user.ProfileImage;
            if (model.ProfileImage != null)
            {
                profileImage = Helpers.ConvertImage(model.ProfileImage);
            }

            string coverImage = user.CoverImage;
            if (model.CoverImage != null)
            {
                coverImage = Helpers.ConvertImage(model.CoverImage);
            }

            user.UserName = model.Username;
            user.Email = model.Email;
            user.ProfileImage = profileImage;
            user.CoverImage = coverImage;

            this.Data.SaveChanges();

            this.HttpContext.GetOwinContext().Authentication.SignOut();

            return this.RedirectToAction("Login", "Account");
        }