123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text.RegularExpressions;
- using pr13.Models;
- using Microsoft.EntityFrameworkCore;
- using MsBox.Avalonia;
- using ReactiveUI;
- namespace pr13.ViewModels
- {
- public class PersonalCabinetViewModel : ReactiveObject
- {
- PostgresContext DB = new PostgresContext();
- User? userData;
- public User? UserData { get => userData; set => userData = value; }
- public PersonalCabinetViewModel(int id)
- {
- UserData = DB.Users.Where(x => x.IdUser == id).Include(x => x.Teacher).ThenInclude(x => x.IdGenderNavigation).FirstOrDefault();
- }
- public string SelectedGender
- {
- get => UserData.Teacher.IdGenderNavigation.Gender1;
- set => UserData.Teacher.IdGender = DB.Genders.FirstOrDefault(x => x.Gender1 == value).Id;
- }
- public string DR
- {
- get => UserData.Teacher.Birthdate.ToString();
- set => UserData.Teacher.Birthdate = DateTime.Parse(value);
- }
- public List<string> Genders => DB.Genders.Select(x => x.Gender1).ToList();
- bool _enable = false;
- public bool Enable
- {
- get => _enable;
- set => this.RaiseAndSetIfChanged(ref _enable, value);
- }
- public void Checked()
- {
- if (!Enable)
- {
- Enable = true;
- }
- else
- {
- Enable = false;
- }
- }
- string _newPass;
- string _newPassRepeat;
- public string NewPass
- {
- get => _newPass;
- set => this.RaiseAndSetIfChanged(ref _newPass, value);
- }
- public string NewPassRepeat
- {
- get => _newPassRepeat;
- set => this.RaiseAndSetIfChanged(ref _newPassRepeat, value);
- }
- public void FixChanges()
- {
- if (!CheckOnEmpty() || !CheckPhone())
- {
- return;
- }
- if (NewPass == NewPassRepeat)
- {
- UserData.Password = NewPassRepeat;
- DB.SaveChanges();
- var box = MessageBoxManager.GetMessageBoxStandard("Èçìåíåíèÿ", "Èçìåíåíèÿ ñîõðàíåíû!");
- box.ShowAsync();
- }
- else
- {
- var box = MessageBoxManager.GetMessageBoxStandard("Èçìåíåíèÿ", "Ïàðîëü äîëæåí ñîâïàäàòü, èçìèíåíèÿ íå ñîõðàíåíû!");
- box.ShowAsync();
- }
- }
- public bool CheckOnEmpty()
- {
- if (!Enable)
- {
- if (UserData.Teacher.Surname.ToString() == null || UserData.Teacher.Surname.ToString() == "" ||
- UserData.Teacher.Name.ToString() == null || UserData.Teacher.Name.ToString() == "" ||
- UserData.Teacher.Patronymic.ToString() == null || UserData.Teacher.Patronymic.ToString() == "" ||
- UserData.Login.ToString() == null || UserData.Login.ToString() == "" ||
- UserData.Teacher.Email.ToString() == null || UserData.Teacher.Email.ToString() == "" ||
- UserData.Teacher.Phone.ToString() == null || UserData.Teacher.Phone.ToString() == "")
- {
- var box = MessageBoxManager.GetMessageBoxStandard("Ïîëÿ", "Ïîëÿ íå çàïîëíåíû");
- box.ShowAsync();
- return false;
- }
- else
- {
- return true;
- }
- }
- else
- {
- if (UserData.Teacher.Surname.ToString() == null || UserData.Teacher.Surname.ToString() == "" ||
- UserData.Teacher.Name.ToString() == null || UserData.Teacher.Name.ToString() == "" ||
- UserData.Teacher.Patronymic.ToString() == null || UserData.Teacher.Patronymic.ToString() == "" ||
- UserData.Login.ToString() == null || UserData.Login.ToString() == "" ||
- UserData.Teacher.Email.ToString() == null || UserData.Teacher.Email.ToString() == "" ||
- UserData.Teacher.Phone.ToString() == null || UserData.Teacher.Phone.ToString() == "" ||
- NewPass == null || NewPass == "" || NewPassRepeat == null || NewPassRepeat == "")
- {
- var box = MessageBoxManager.GetMessageBoxStandard("Ïîëÿ", "Ïîëÿ íå çàïîëíåíû");
- box.ShowAsync();
- return false;
- }
- else
- {
- return true;
- }
- }
- }
- public bool CheckPhone()
- {
- if (UserData.Teacher.Phone.Length == 11)
- {
- Regex PhoneRegex = new Regex("^89\\d{9}$");
- if (PhoneRegex.IsMatch(UserData.Teacher.Phone))
- {
- return true;
- }
- else
- {
- var box = MessageBoxManager.GetMessageBoxStandard("Òåëåôîí", "Íåâåðíî ââåäåí òåëåôîí!");
- box.ShowAsync();
- return false;
- }
- }
- else if (UserData.Teacher.Phone.Length < 11)
- {
- var box = MessageBoxManager.GetMessageBoxStandard("Òåëåôîí", "Íåâåðíî ââåäåí òåëåôîí!");
- box.ShowAsync();
- return false;
- }
- else
- {
- string CorrectPhone = "";
- CorrectPhone = UserData.Teacher.Phone.Replace("(", "");
- CorrectPhone = CorrectPhone.Replace(")", "");
- CorrectPhone = CorrectPhone.Replace("-", "");
- CorrectPhone = CorrectPhone.Replace(" ", "");
- if (CorrectPhone.Length == 11)
- {
- UserData.Teacher.Phone = CorrectPhone;
- return true;
- }
- else
- {
- var box = MessageBoxManager.GetMessageBoxStandard("Òåëåôîí", "Íåâåðíî ââåäåí òåëåôîí!");
- box.ShowAsync();
- return false;
- }
- }
- }
- }
- }
|