-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainWindowViewModel.cs
More file actions
55 lines (46 loc) · 1.43 KB
/
MainWindowViewModel.cs
File metadata and controls
55 lines (46 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
using System;
using System.Windows.Input;
namespace InvoiceApp
{
public class MainWindowViewModel : ViewModel
{
private DocumentService _documentService;
public InvoiceModel Invoice { get; set; }
private bool _hasError;
public bool HasError
{
get
{
return _hasError;
}
set
{
_hasError = value;
OnPropertyChanged(nameof(HasError));
}
}
public ICommand GenerateDocumentCommand { get; }
public MainWindowViewModel()
{
_documentService = new DocumentService();
Invoice = new InvoiceModel();
GenerateDocumentCommand = new RelayCommand(GenerateDocument);
}
public void GenerateDocument()
{
HasError = !_documentService.TryGenerateInvoice(Invoice);
}
}
public class InvoiceModel
{
public string Name { get; set; } = string.Empty;
public string Description { get; set; } = string.Empty;
public DateTime Date { get; set; } = DateTime.Today;
public decimal Cost { get; set; }
private decimal _price => Cost - _gst;
public string Price => _price.ToString("C");
private decimal _gst => Cost * 0.11m;
public string Gst => _gst.ToString("C");
public string Total => Cost.ToString("C");
}
}