示例#1
0
        public ActionResult Profile(ProfileViewModel model)
        {
            if (model == null)
            {
                //TODO: return error message.
                return(View());
            }
            if (!ModelState.IsValid)
            {
                //TODO: return error message.
                return(View("EditProfile", model));
            }

            var userInfo = _userQueryService.GetUser(new UserId(UserContext.Current.UserId));

            if (userInfo == null)
            {
                //TODO: return error message.
                return(RedirectToAction("Profile", new { id = UserContext.Current.UserId }));
            }

            if (userInfo.FirstName != model.FirstName || userInfo.LastName != model.LastName || userInfo.Phone != model.Phone || userInfo.DateOfBirth != model.DateOfBirth)
            {
                var command = new ChangeUserInformation(new UserId(userInfo.UserId), model.Phone, userInfo.Image, model.FirstName,
                                                        model.LastName, model.DateOfBirth);
                _cmdSender.Send(command);

                UserContext.IsUpdated = false;
            }

            return(RedirectToAction("Profile", new { id = userInfo.UserId }));
        }
示例#2
0
        public MembershipCreateStatus CreateUser(string userName, string password, string email, string lastName, Guid roleId, DateTime dateOfBirth)
        {
            if (String.IsNullOrEmpty(userName))
            {
                throw new ArgumentException("Value cannot be null or empty.", "userName");
            }
            if (String.IsNullOrEmpty(password))
            {
                throw new ArgumentException("Value cannot be null or empty.", "password");
            }
            if (String.IsNullOrEmpty(email))
            {
                throw new ArgumentException("Value cannot be null or empty.", "email");
            }

            MembershipCreateStatus status;
            var user = _provider.CreateUser(userName, password, email, null, null, true, null, out status);

            ICommand command;

            if (user != null && user.ProviderUserKey != null)
            {
                var userId = new Guid();
                Guid.TryParse(user.ProviderUserKey.ToString(), out userId);

                command = new ChangeUserInformation(new UserId(userId), null, null, userName, lastName, dateOfBirth);
                _commandSender.Send(command);

                command = new AddRoleToUser(new UserId(userId), roleId);
                _commandSender.Send(command);
            }

            return(status);
        }
示例#3
0
        /// <summary>
        /// Handles the specified <see cref="ChangeUserInformation">command</see>.
        /// </summary>
        /// <param name="command">The command.</param>
        /// <exception cref="System.ArgumentNullException">When UserId is null.</exception>
        /// <exception cref="System.ArgumentException">When user does not exist.</exception>
        public void Handle(ChangeUserInformation command)
        {
            if (command.Id == null)
            {
                throw new ArgumentNullException("command", "UserId must be specified.");
            }

            User user = _userRepository.Get(command.Id);

            if (user == null)
            {
                throw new ArgumentException(string.Format("User with such id: {0} does not exist.", command.Id));
            }

            user.ChangeInformation(command.FirstName, command.LastName, command.Image, command.Phone, command.DateOfBirth);

            _userRepository.Save(user);
        }
示例#4
0
        private void ChangeIngBt_Click(object sender, RoutedEventArgs e)
        {
            ChangeUserInformation CUI = new ChangeUserInformation(em, Login.Text);

            CUI.Show();
        }