Пример #1
0
        public MainPage()
        {
            InitializeComponent();

            // Bind users to list
            var users = DressingRoom.ListAvailable();

            UserPanel.ItemsSource = users.Select(u => new
            {
                Username         = u,
                ProfileColor     = DressingRoom.ColorFor(u),
                ProfileIcon      = DressingRoom.IconFor(u),
                UserClickCommand = UserClickCommand.Instance
            });
        }
Пример #2
0
        private async void BtnSaveUser_Click(object _1, RoutedEventArgs _2)
        {
            var username = UserNameTextBox.Text;

            // Validation: User name must have between 1 and 24 characters
            if (username.Length < 1 || username.Length > 24)
            {
                await new UserNameFormatError().ShowAsync();
                return;
            }
            // Validation: User name can only contain letters and dashes
            var regex = new Regex("^[A-Z\\-]+$");

            if (!regex.IsMatch(username.ToUpperInvariant()))
            {
                await new UserNameFormatError().ShowAsync();
                return;
            }
            // Validation: User name must not exist already
            if (DressingRoom.ListAvailable().Contains(username))
            {
                await new UserNameExistingError().ShowAsync();
                return;
            }
            // Validation: A profile color must be selected
            if (UserColorGrid.SelectedItem is null)
            {
                await new MissingProfileDataError().ShowAsync();
                return;
            }
            // Validation: A profile icon must be selected
            if (UserIconGrid.SelectedItem is null)
            {
                await new MissingProfileDataError().ShowAsync();
                return;
            }

            // Register new user
            var color = (UserColorGrid.SelectedItem as ColorWrapper).Color;
            var icon  = (UserIconGrid.SelectedItem as IconWrapper).Icon;

            DressingRoom.CreateNew(username, color, icon);

            Frame.Navigate(typeof(MainPage));
        }