|
@@ -10,11 +10,14 @@ using System.Text;
|
|
|
using System.Text.RegularExpressions;
|
|
|
using System.Threading.Tasks;
|
|
|
using Users_Roles.Models;
|
|
|
+using MsBox.Avalonia.Enums;
|
|
|
+using MsBox.Avalonia;
|
|
|
|
|
|
namespace Users_Roles.ViewModels
|
|
|
{
|
|
|
internal class AddUserVM : ViewModelBase
|
|
|
{
|
|
|
+ string _messageButton;
|
|
|
User? _newUser;
|
|
|
public User? NewUser { get => _newUser; set => this.RaiseAndSetIfChanged(ref _newUser, value); }
|
|
|
|
|
@@ -22,12 +25,22 @@ namespace Users_Roles.ViewModels
|
|
|
{
|
|
|
_newUser = new User();
|
|
|
_newUser.RoleUser = idRole;
|
|
|
+ if (idRole == 1)
|
|
|
+ {
|
|
|
+ MessageButton = "Зарегистрировать администратора";
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ MessageButton = "Зарегистрировать пользователя";
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
string _massege;
|
|
|
string _newPassword;
|
|
|
public string NewPassword { get => _newPassword; set => _newPassword = value; }
|
|
|
public string Massege { get => _massege; set => this.RaiseAndSetIfChanged(ref _massege, value); }
|
|
|
+ public string MessageButton { get => _messageButton; set => _messageButton = value; }
|
|
|
+
|
|
|
bool TruePassword()
|
|
|
{
|
|
|
bool flag = false;
|
|
@@ -93,11 +106,16 @@ namespace Users_Roles.ViewModels
|
|
|
NewUser.Image = buffer;
|
|
|
}
|
|
|
}
|
|
|
+ public static _43pGaruaev2Context myConnection = new _43pGaruaev2Context();
|
|
|
public void AddUser()
|
|
|
{
|
|
|
- if (TruePassword())
|
|
|
+ if (myConnection.Users.Any(x => x.Login == NewUser.Login))
|
|
|
{
|
|
|
-
|
|
|
+ Massege = "Пользователь с таким логином уже существует";
|
|
|
+ }
|
|
|
+ else if (TruePassword())
|
|
|
+ {
|
|
|
+
|
|
|
}
|
|
|
else
|
|
|
{
|
|
@@ -114,6 +132,8 @@ namespace Users_Roles.ViewModels
|
|
|
|
|
|
MainWindowViewModel.myConnection.SaveChanges();
|
|
|
|
|
|
+ MessageBoxManager.GetMessageBoxStandard("Добавление", "Вы зарегистрировались", ButtonEnum.Ok).ShowAsync();
|
|
|
+
|
|
|
MainWindowViewModel.Instance.PageContent = new PageRegistrationV();
|
|
|
}
|
|
|
}
|