69 lines
1.6 KiB
C#
69 lines
1.6 KiB
C#
using Avalonia.Controls;
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
|
using CommunityToolkit.Mvvm.Input;
|
|
using GazpromApp.Enums;
|
|
using GazpromApp.Models;
|
|
|
|
namespace GazpromApp.ViewModels;
|
|
|
|
public partial class ErrorViewModel : ViewModelBase
|
|
{
|
|
[ObservableProperty]
|
|
private string? _title;
|
|
|
|
[ObservableProperty]
|
|
private string? _message;
|
|
|
|
[RelayCommand]
|
|
private static void Ok(Window w)
|
|
{
|
|
w.Close();
|
|
}
|
|
|
|
private ErrorSeverity severity;
|
|
|
|
// Visual and other properties
|
|
[ObservableProperty] private bool _isErrorVisible;
|
|
[ObservableProperty] private bool _isWarnVisible;
|
|
[ObservableProperty] private bool _isInfoVisible;
|
|
|
|
public ErrorViewModel()
|
|
{
|
|
IsInfoVisible = true;
|
|
Title = "Тест ошибки";
|
|
Message = "Сообщение ошибки";
|
|
}
|
|
|
|
public ErrorViewModel(Error error)
|
|
{
|
|
Title = error.Title;
|
|
Message = error.Message;
|
|
severity = error.Severity;
|
|
switch (error.Severity)
|
|
{
|
|
case ErrorSeverity.Error:
|
|
IsErrorVisible = true;
|
|
break;
|
|
case ErrorSeverity.Warning:
|
|
IsWarnVisible = true;
|
|
break;
|
|
case ErrorSeverity.Message:
|
|
IsInfoVisible = true;
|
|
break;
|
|
default:
|
|
IsInfoVisible = true;
|
|
break;
|
|
}
|
|
}
|
|
|
|
public Error GetError()
|
|
{
|
|
Error error = new Error()
|
|
{
|
|
Title = Title,
|
|
Message = Message,
|
|
Severity = severity,
|
|
};
|
|
return error;
|
|
}
|
|
} |