Example #1
0
        public UserDto AddNewUser(UserDto userDto)
        {
            var user = Mapper.Map <UserDto, User>(userDto);

            if (userDto.Groups == null || userDto.Groups.Count == 0)
            {
                throw new InvalidOperationException("User must belong to at least one Group. Cannot add User.");
            }

            var groups  = userDto.Groups.Select(Mapper.Map <GroupDto, Group>).ToList();
            var newUser = _userDataProvider.AddNewUser(user, groups);

            var newGroups  = newUser.UserGroups.Select(ug => ug.Group).ToList();
            var newUserDto = Mapper.Map <User, UserDto>(newUser);

            newUserDto.Groups = newGroups.Select(Mapper.Map <Group, GroupDto>).ToList();

            return(newUserDto);
        }
Example #2
0
        /// <summary>
        /// Attempts to register a new user
        /// </summary>
        /// <param name="parameter">The <see cref="SecureString"/> passed in from the view for the users password</param>
        /// <returns></returns>
        public async Task RegisterAsync(object parameter)
        {
            await RunCommandAsync(() => RegisterIsRunning, async() =>
            {
                var pass = (parameter as IHavePassword).SecurePassword.Unsecure();

                var user = new User()
                {
                    Address     = Address,
                    UserType    = UserType.User,
                    LastName    = LastName,
                    FirstName   = FirstName,
                    Designation = Designation,
                    UserName    = UserName,
                    Password    = pass,
                    Email       = Email,
                    Title       = Title
                };
                var t = Task.Run(() => _userDataProvider.AddNewUser(user));
                await t;
            });
        }