|
@@ -16,25 +16,39 @@ namespace AvaloniaApplication2.ViewModels
|
|
|
{
|
|
|
public partial class Page2ViewModel : ViewModelBase
|
|
|
{
|
|
|
- [ObservableProperty] User editedUser;
|
|
|
+ [ObservableProperty] Logined editedLogined;
|
|
|
[ObservableProperty] List<Gender> gendersList;
|
|
|
[ObservableProperty] Bitmap imageUser;
|
|
|
-
|
|
|
- public Page2ViewModel(int id)
|
|
|
+
|
|
|
+ public Page2ViewModel()
|
|
|
+ {
|
|
|
+ GendersList = db.Genders.ToList();
|
|
|
+ editedLogined = new Logined(){ User = new User { IdGenderNavigation = new Gender() }, IdRole=2 };
|
|
|
+ }
|
|
|
+
|
|
|
+ public Page2ViewModel(int id)
|
|
|
{
|
|
|
GendersList = db.Genders.ToList();
|
|
|
- editedUser = db.Users.Include(x=>x.IdGenderNavigation).Include(x=>x.IdTraits).FirstOrDefault(x=>x.IdUser == id);
|
|
|
- imageUser = EditedUser.Image != null ? new Bitmap(new MemoryStream(editedUser.Image)) : new Bitmap("Assets/заглушка.jpg");
|
|
|
+ editedLogined = db.Logineds.Include(x=>x.User.IdTraits).Include(x=>x.User.IdGenderNavigation).FirstOrDefault(x=>x.Id == id);
|
|
|
+ imageUser = EditedLogined.User.Image != null ? new Bitmap(new MemoryStream(editedLogined.User.Image)) : new Bitmap("Assets/заглушка.jpg");
|
|
|
}
|
|
|
public DateTimeOffset DateTimeOffset
|
|
|
{
|
|
|
- get => new DateTimeOffset((DateTime)EditedUser.BirthDate, TimeSpan.Zero);
|
|
|
- set => EditedUser.BirthDate = new DateTime(value.Year, value.Month, value.Day);
|
|
|
+ get => new DateTimeOffset((DateTime)EditedLogined.User.BirthDate, TimeSpan.Zero);
|
|
|
+ set => EditedLogined.User.BirthDate = new DateTime(value.Year, value.Month, value.Day);
|
|
|
}
|
|
|
|
|
|
public void GoBack() => MainWindowViewModel.Self.Page = new Page1();
|
|
|
|
|
|
- public void Save() => db.SaveChanges();
|
|
|
+ public void Save()
|
|
|
+ {
|
|
|
+ if (EditedLogined.Id==0) db.Logineds.Add(EditedLogined);
|
|
|
+ db.SaveChanges();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
public async Task Image()
|
|
|
{
|
|
|
if (Application.Current?.ApplicationLifetime is not IClassicDesktopStyleApplicationLifetime desktop ||
|
|
@@ -53,8 +67,8 @@ namespace AvaloniaApplication2.ViewModels
|
|
|
byte[] buffer = new byte[10000000];
|
|
|
var bytes = readStream.ReadAtLeast(buffer, 1);
|
|
|
Array.Resize(ref buffer,bytes);
|
|
|
- editedUser.Image = buffer;
|
|
|
- ImageUser = new Bitmap(new MemoryStream(editedUser.Image));
|
|
|
+ EditedLogined.User.Image = buffer;
|
|
|
+ ImageUser = new Bitmap(new MemoryStream(EditedLogined.User.Image));
|
|
|
db.SaveChanges();
|
|
|
}
|
|
|
|