-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUnclosedShiftDataServiceAsync.cs
140 lines (126 loc) · 7.06 KB
/
UnclosedShiftDataServiceAsync.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
namespace Contoso
{
namespace Commerce.Runtime.GetOpenShifts
{
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Dynamics.Commerce.Runtime;
using Microsoft.Dynamics.Commerce.Runtime.Data;
using Microsoft.Dynamics.Commerce.Runtime.DataModel;
using Microsoft.Dynamics.Commerce.Runtime.Messages;
using Microsoft.Dynamics.Commerce.Runtime.Services.Messages;
using Microsoft.Dynamics.Commerce.Runtime.Helpers;
using Microsoft.Dynamics.Commerce.Runtime.RealtimeServices.Messages;
using System.Collections.ObjectModel;
using System.Threading.Tasks;
using Microsoft.Dynamics.Retail.Diagnostics;
public class UnclosedShiftDataServiceAsync
{
public static void CreateShiftAsync(CreateShiftRequest request, CreateShiftResponse response)
{
ThrowIf.Null(request, "CreateShiftRequest");
ThrowIf.Null(response, "CreateShiftResponse");
string inventLocationDataAreaId = request.RequestContext.GetChannelConfiguration().InventLocationDataAreaId;
Task.Run<bool>(()=> {
InvokeExtensionMethodRealtimeRequest extensionRequest = new InvokeExtensionMethodRealtimeRequest(
"CreateNewShift",
response.Shift.StoreRecordId,
response.Shift.TerminalId,
response.Shift.StoreId,
response.Shift.ShiftId,
response.Shift.StaffId,
response.Shift.CurrentStaffId,
Convert.ToInt32(response.Shift.Status),
response.Shift.CurrentTerminalId,
response.Shift.IsShared,
response.Shift.CashDrawer,
inventLocationDataAreaId);
InvokeExtensionMethodRealtimeResponse RTSResponse = request.RequestContext.Execute<InvokeExtensionMethodRealtimeResponse>(extensionRequest);
ReadOnlyCollection<object> results = RTSResponse.Result;
bool success = Convert.ToBoolean(results[0]);
return success;
});
Task.Run(() =>
{
using (var databaseContext = new DatabaseContext(request))
{
ParameterSet parameters = new ParameterSet();
parameters["@CHANNEL"] = response.Shift.StoreRecordId;
parameters["@TERMINALID"] = response.Shift.TerminalId;
parameters["@STOREID"] = response.Shift.StoreId;
parameters["@SHIFTID"] = response.Shift.ShiftId;
parameters["@STAFFID"] = response.Shift.StaffId;
parameters["@CURRENTSTAFFID"] = response.Shift.CurrentStaffId;
parameters["@STATUS"] = response.Shift.Status;
parameters["@CURRENTTERMINALID"] = response.Shift.CurrentTerminalId;
parameters["@ISSHARED"] = response.Shift.IsShared;
parameters["@STARTDATETIMEUTC"] = DateTimeOffsetDataHelper.GetDbNullableDateTime(response.Shift.StartDateTime);
parameters["@STATUSDATETIMEUTC"] = DateTimeOffsetDataHelper.GetDbNullableDateTime(response.Shift.StatusDateTime);
parameters["@DATAAREAID"] = inventLocationDataAreaId;
parameters["@CASHDRAWER"] = response.Shift.CashDrawer;
databaseContext.ExecuteStoredProcedureNonQuery("[ext].[CreateNewShift]", parameters);
}
}).Wait();
}
public static void CloseShiftAsync(Shift shift, Request request)
{
Task.Run<bool>(() =>
{
InvokeExtensionMethodRealtimeRequest extensionRequest = new InvokeExtensionMethodRealtimeRequest(
"RemoveOpenedShift",
shift.StoreRecordId,
shift.TerminalId,
shift.ShiftId);
InvokeExtensionMethodRealtimeResponse RTSResponse = request.RequestContext.Execute<InvokeExtensionMethodRealtimeResponse>(extensionRequest);
ReadOnlyCollection<object> results = RTSResponse.Result;
bool success = Convert.ToBoolean(results[0]);
return success;
});
Task.Run(() =>
{
using (var databaseContext = new DatabaseContext(request))
{
ParameterSet parameters = new ParameterSet();
parameters["@CHANNEL"] = shift.StoreRecordId;
parameters["@TERMINALID"] = shift.TerminalId;
parameters["@SHIFTID"] = shift.ShiftId;
databaseContext.ExecuteStoredProcedureNonQuery("[ext].[DeleteClosedShift]", parameters);
}
}).Wait();
}
public static void ChangeShiftStatusAsync(Shift shift, Request request)
{
Task.Run<bool>(() => {
InvokeExtensionMethodRealtimeRequest extensionRequest = new InvokeExtensionMethodRealtimeRequest(
"ChangeShiftStatus",
shift.StoreRecordId,
shift.TerminalId,
shift.ShiftId,
Convert.ToInt32(shift.Status),
shift.CurrentTerminalId,
shift.CurrentStaffId);
InvokeExtensionMethodRealtimeResponse RTSResponse = request.RequestContext.Execute<InvokeExtensionMethodRealtimeResponse>(extensionRequest);
ReadOnlyCollection<object> results = RTSResponse.Result;
bool success = Convert.ToBoolean(results[0]);
return success;
});
Task.Run(() =>
{
using (var databaseContext = new DatabaseContext(request))
{
ParameterSet parameters = new ParameterSet();
parameters["@CHANNEL"] = shift.StoreRecordId;
parameters["@TERMINALID"] = shift.TerminalId;
parameters["@SHIFTID"] = shift.ShiftId;
parameters["@STATUS"] = shift.Status;
parameters["@STATUSDATETIMEUTC"] = shift.StatusDateTime;
parameters["@CURRENTSTAFFID"] = shift.CurrentStaffId;
parameters["@CURRENTTERMINALID"] = shift.CurrentTerminalId;
databaseContext.ExecuteStoredProcedureNonQuery("[ext].[ChangeShiftStaus]", parameters);
}
}).Wait();
}
}
}
}