/
CheckinViewModel.cs
88 lines (73 loc) · 2.45 KB
/
CheckinViewModel.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
76
77
78
79
80
81
82
83
84
85
86
87
88
using System;
using System.Diagnostics;
using System.Windows;
using Caliburn.Micro;
using Telerik.Windows.Controls;
using TrainShareApp.Data;
using TrainShareApp.Event;
using TrainShareApp.Model;
namespace TrainShareApp.ViewModels
{
public class CheckinViewModel : Screen
{
private readonly ILog _logger;
private readonly INavigationService _navigationService;
private readonly ITrainshareClient _trainshareClient;
public CheckinViewModel()
{
Debug.Assert(Execute.InDesignMode, "Default constructor can only be called to generate design data.");
}
public CheckinViewModel(
ILog logger,
INavigationService navigationService,
ITrainshareClient trainshareClient)
{
_logger = logger;
_navigationService = navigationService;
_trainshareClient = trainshareClient;
}
public Checkin CurrentCheckin { get; set; }
public float Position { get; set; }
public string Message { get; set; }
public bool Loading { get; set; }
public async void Confirm()
{
try
{
Loading = true;
// subtrack because the front is on the right
var position = 10 - (int) Position*10;
position = Math.Min(position, 10);
position = Math.Max(position, 0);
CurrentCheckin.Position = position;
CurrentCheckin.CheckinTime = DateTime.Now;
// need await to handle exception
await _trainshareClient.Checkin(CurrentCheckin);
}
catch(Exception e)
{
_logger.Error(e);
RadMessageBox.Show("Sorry, there was an unexpected error while checking in. Please try again later.");
}
finally
{
Loading = false;
_navigationService
.UriFor<MainViewModel>()
.Navigate();
}
}
public void Cancel()
{
_navigationService.RemoveBackEntry();
_navigationService.RemoveBackEntry();
_navigationService.GoBack();
}
protected override void OnActivate()
{
Position = 0.5f;
CurrentCheckin = Checkin.FromConnection(App.Instance.SearchSelection);
base.OnActivate();
}
}
}