Beispiel #1
0
        public async void CreateUser()
        {
            var regx = @"^([a-z0-9_-]+\.)*[a-z0-9_-]+@[a-z0-9_-]+(\.[a-z0-9_-]+)*\.[a-z]{2,6}$";

            if (String.IsNullOrEmpty(userModel.UserName) || String.IsNullOrEmpty(userModel.PasswordHash) ||
                String.IsNullOrEmpty(userModel.FirstName) || String.IsNullOrEmpty(userModel.Surname) ||
                String.IsNullOrEmpty(userModel.Email) || SelectedTimeZone == null || SelectedRole == null)
            {
                windowManager.ShowDialog(new ErrorViewModel(MyResources.FillAllFields));
            }
            else
            {
                if (userModel.Email != null && !Regex.IsMatch(userModel.Email, regx))
                {
                    windowManager.ShowDialog(new ErrorViewModel(MyResources.InvalidEmail));
                }
                else
                {
                    var token = UserInfo.Token;
                    userModel.Role         = SelectedRole;
                    userModel.TimeZone     = SelectedTimeZone.ToString();
                    userModel.UserLanguage = SelectedLanguage;

                    if (userModel.PasswordHash != null && userModel.PasswordHash.Count() < 4)
                    {
                        windowManager.ShowDialog(new ErrorViewModel(MyResources.TSP));
                    }
                    else
                    {
                        var result = await userService.RegisterUser(userModel);

                        if (!result.Equals("USERNAME_ALREADY_EXISTS"))
                        {
                            TryClose();
                        }
                        else
                        {
                            windowManager.ShowDialog(new ErrorViewModel(MyResources.UAE));
                        }
                    }
                }
            }
        }
Beispiel #2
0
        public async void UpdateUser()
        {
            var user = new UserModel
            {
                Id           = selectedUser.Id,
                UserName     = selectedUser.UserName,
                PasswordHash = selectedUser.PasswordHash,
                FirstName    = selectedUser.FirstName,
                Surname      = selectedUser.Surname,
                Email        = selectedUser.Email,
                Account      = selectedUser.Account,
                Role         = SelectedRole == null ? selectedUser.Role : SelectedRole,
                TimeZone     = SelectedTimeZone == null ? selectedUser.TimeZone : SelectedTimeZone.ToString(),
                UserLanguage = SelectedLanguage == 0 ? selectedUser.UserLanguage : SelectedLanguage
            };

            if (String.IsNullOrEmpty(selectedUser.FirstName) || String.IsNullOrEmpty(selectedUser.Surname) ||
                String.IsNullOrEmpty(selectedUser.Email))
            {
                windowManager.ShowDialog(new ErrorViewModel(MyResources.FillAllFields));
            }
            else
            {
                var regx = @"^([a-z0-9_-]+\.)*[a-z0-9_-]+@[a-z0-9_-]+(\.[a-z0-9_-]+)*\.[a-z]{2,6}$";
                if (selectedUser.Email != null && !Regex.IsMatch(selectedUser.Email, regx))
                {
                    windowManager.ShowDialog(new ErrorViewModel(MyResources.InvalidEmail));
                }
                else
                {
                    SelectedUser = await userService.UpdateAsync(user);

                    await userService.LoadUsersAsync();
                }
            }
        }