/
CreateIssueViewModel.cs
75 lines (68 loc) · 2.24 KB
/
CreateIssueViewModel.cs
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
using Microsoft.Toolkit.Mvvm.ComponentModel;
using Microsoft.Toolkit.Mvvm.Input;
using ResourcePlanner.Models;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Windows.Input;
using UnoBookRail.Common.Auth;
using UnoBookRail.Common.Issues;
namespace ResourcePlanner.ViewModels
{
public class CreateIssueViewModel : ObservableObject
{
public readonly ICommand CreateIssueCommand;
// General fields
public string Title { get; set; } = "";
public string Description { get; set; } = "";
private IssueType issueType = IssueType.Train;
public IssueType IssueType
{
get
{
return issueType;
}
set
{
SetProperty(ref issueType, value);
}
}
public Urgency Urgency { get; set; }
// Train fields
public string TrainNumber { get; set; } = "";
// Station fields
public string StationName { get; set; } = "";
// "Other" fields
public string Location { get; set; } = "";
public CreateIssueViewModel(NavigationViewModel navigationVM)
{
CreateIssueCommand = new RelayCommand(() =>
{
var issue = new Issue()
{
IssueType = IssueType,
Title = Title,
Description = Description,
Urgency = Urgency,
OpenDate = DateTime.Now,
IsOpen = true,
OpenedBy = Authentication.GetCurrentUser()
};
switch (IssueType)
{
case IssueType.Train:
issue.TrainNumber = TrainNumber;
break;
case IssueType.Station:
issue.StationName = StationName;
break;
case IssueType.Other:
issue.Location = Location;
break;
}
IssuesRepository.AddIssue(issue);
navigationVM.Issues_OpenAllIssuesCommand.Execute(null);
});
}
}
}