UpdateUsersViewModel.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using AvaloniaApplication1.Models;
  5. using Microsoft.EntityFrameworkCore;
  6. using ReactiveUI;
  7. namespace AvaloniaApplication1.ViewModels
  8. {
  9. public class UpdateUsersViewModel : ViewModelBase
  10. {
  11. User user;
  12. List<Gender> genderList;
  13. Gender selectedGender;
  14. public User User { get => user; set => this.RaiseAndSetIfChanged(ref user, value); }
  15. public List<Gender> GenderList { get => genderList; set => this.RaiseAndSetIfChanged(ref genderList, value); }
  16. public Gender SelectedGender { get => selectedGender; set => this.RaiseAndSetIfChanged(ref selectedGender, value); }
  17. public UpdateUsersViewModel(int id)
  18. {
  19. user = myConnection.Users.FirstOrDefault(x => x.Id == id);
  20. genderList = myConnection.Genders.ToList();
  21. selectedGender = genderList.FirstOrDefault(x => x.Id == user.Gender);
  22. }
  23. public DateTimeOffset DateTimeOffset
  24. {
  25. get => new DateTimeOffset(user.DateOfBirth, TimeSpan.Zero);
  26. set => user.DateOfBirth = new DateTime(value.Year, value.Month, value.Day);
  27. }
  28. public void Back() => MainWindowViewModel.Self.Uc = new AdminPage();
  29. }
  30. }