Esempio n. 1
0
        public ActionResult EditUser(EditProfileModel model, int id, HttpPostedFileBase image)
        {
            var user = _userService.GetById(id);
            if (image != null)
            {
                var photo = _imageService.AddImage(image.FileName, GetFileContent(image), _userService.CurrentUser.Id);

                user.PhotoId = photo.Id;
                _userService.Update(user);
            }

            PopulateEditProfileViewModel(model);

            ValidateEditProfileViewModel(model);

            if (!ModelState.IsValid)
                return View(model);

            user.Comment = model.Comment;
            user.DateOfBirth = model.DateOfBirth;
            user.Email = model.Email;
            user.FirstName = model.FirstName;
            user.LastName = model.LastName;
            user.MiddleName = model.MiddleName;
            user.PhoneNumber = model.PhoneNumber;

            _userService.Update(user);

            return RedirectToAction("Index", "Home")
                .WithSuccessMessage(string.Format("You have successfully updated user's profile."));
        }
Esempio n. 2
0
        public ActionResult EditUser(int id)
        {
            var user = _userService.GetById(id);

            var model = new EditProfileModel
            {
                Comment = user.Comment,
                DateOfBirth = user.DateOfBirth,
                Email = user.Email,
                FirstName = user.FirstName,
                LastName = user.LastName,
                MiddleName = user.MiddleName,
                PhoneNumber = user.PhoneNumber,
                PhotoId = user.PhotoId
            };

            PopulateEditProfileViewModel(model);

            return View(model);
        }
Esempio n. 3
0
        void PopulateEditProfileViewModel(EditProfileModel model)
        {
            var user = _userService.CurrentUser;

            if (user.PhotoId != null)
                model.PhotoThumbnail = GetThumbnailUrl((byte[])_imageService.GetData(user.PhotoId.Value), "png", 120);
        }
Esempio n. 4
0
        void ValidateEditProfileViewModel(EditProfileModel model)
        {
            var user = _userService.GetByUsername(model.Email);

            if (user != null && user.Id != _userService.CurrentUser.Id)
                ModelState.AddModelError("Email", "User with such email address already exists in the system");
        }
        public ActionResult EditProfile(EditProfileModel model, HttpPostedFileBase image)
        {
            var user = _userService.CurrentUser;

            if (image != null)
            {
                var photo = _imageService.AddImage(image.FileName, GetFileContent(image), _userService.CurrentUser.Id);

                user.PhotoId = photo.Id;
                _userService.Update(user);
            }

            PopulateEditProfileViewModel(model);

            ValidateEditProfileViewModel(model);

            if (!ModelState.IsValid)
                return View(model);

            user.Comment = model.Comment;
            user.DateOfBirth = model.DateOfBirth;
            user.Email = model.Email;
            user.FirstName = model.FirstName;
            user.LastName = model.LastName;
            user.MiddleName = model.MiddleName;
            user.PhoneNumber = model.PhoneNumber;

            _userService.Update(user);

            FormsAuthentication.SetAuthCookie(user.Email, true);

            return RedirectToAction("List", "Session")
                .WithSuccessMessage(string.Format("You have successfully updated your profile.")); ;
        }