Browse Source

Add InternalReference field to batches and send it through when placing orders.

Andrew Klopper 8 years ago
parent
commit
67b038f550

+ 4 - 1
BulkPrintingAPI/Controllers/BatchesController.cs

29
             [Required]
29
             [Required]
30
             public string CustomerReference { get; set; }
30
             public string CustomerReference { get; set; }
31
 
31
 
32
+            [Required]
33
+            public string InternalReference { get; set; }
34
+
32
             public Guid? OrderGuid { get; set; }
35
             public Guid? OrderGuid { get; set; }
33
         };
36
         };
34
 
37
 
129
             }
132
             }
130
 
133
 
131
             var orderResponse = await MAX.Utils.PlaceOrderAsync(_clientFactory, _logger,
134
             var orderResponse = await MAX.Utils.PlaceOrderAsync(_clientFactory, _logger,
132
-                credentials, product, order.Quantity, order.CustomerReference, order.OrderGuid,
135
+                credentials, product, order.Quantity, order.CustomerReference, order.InternalReference, order.OrderGuid,
133
                 Utils.AesDecryptBytes(credentials.Vendor.EncryptedVoucherKey,
136
                 Utils.AesDecryptBytes(credentials.Vendor.EncryptedVoucherKey,
134
                     _dataEncryptionOptions.DefaultKey));
137
                     _dataEncryptionOptions.DefaultKey));
135
 
138
 

+ 300 - 0
BulkPrintingAPI/Migrations/20180111104438_AddInternalReference.Designer.cs

1
+using System;
2
+using Microsoft.EntityFrameworkCore;
3
+using Microsoft.EntityFrameworkCore.Infrastructure;
4
+using Microsoft.EntityFrameworkCore.Metadata;
5
+using Microsoft.EntityFrameworkCore.Migrations;
6
+using MAX.Models;
7
+
8
+namespace BulkPrintingAPI.Migrations
9
+{
10
+    [DbContext(typeof(MAXContext))]
11
+    [Migration("20180111104438_AddInternalReference")]
12
+    partial class AddInternalReference
13
+    {
14
+        protected override void BuildTargetModel(ModelBuilder modelBuilder)
15
+        {
16
+            modelBuilder
17
+                .HasAnnotation("ProductVersion", "1.1.2")
18
+                .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
19
+
20
+            modelBuilder.Entity("MAX.Models.Account", b =>
21
+                {
22
+                    b.Property<int>("Id");
23
+
24
+                    b.Property<decimal>("Balance");
25
+
26
+                    b.Property<string>("Name")
27
+                        .IsRequired()
28
+                        .HasMaxLength(50);
29
+
30
+                    b.Property<string>("Reference")
31
+                        .IsRequired()
32
+                        .HasMaxLength(50);
33
+
34
+                    b.Property<int>("Status");
35
+
36
+                    b.Property<int>("WarehouseId");
37
+
38
+                    b.HasKey("Id");
39
+
40
+                    b.HasIndex("WarehouseId");
41
+
42
+                    b.ToTable("Accounts");
43
+                });
44
+
45
+            modelBuilder.Entity("MAX.Models.Batch", b =>
46
+                {
47
+                    b.Property<int>("Id");
48
+
49
+                    b.Property<int>("AccountId");
50
+
51
+                    b.Property<decimal>("Cost");
52
+
53
+                    b.Property<int>("DeliveredQuantity");
54
+
55
+                    b.Property<decimal>("DiscountPercentage");
56
+
57
+                    b.Property<decimal>("FaceValue");
58
+
59
+                    b.Property<string>("InternalReference")
60
+                        .HasMaxLength(32);
61
+
62
+                    b.Property<int>("NetworkId");
63
+
64
+                    b.Property<string>("NetworkName")
65
+                        .IsRequired()
66
+                        .HasMaxLength(20);
67
+
68
+                    b.Property<DateTimeOffset>("OrderDate");
69
+
70
+                    b.Property<Guid?>("OrderGuid");
71
+
72
+                    b.Property<string>("OrderReference")
73
+                        .IsRequired()
74
+                        .HasMaxLength(20);
75
+
76
+                    b.Property<int>("OrderedById");
77
+
78
+                    b.Property<string>("ProductDescription")
79
+                        .IsRequired()
80
+                        .HasMaxLength(50);
81
+
82
+                    b.Property<int>("ProductId");
83
+
84
+                    b.Property<bool>("ReadyForDownload");
85
+
86
+                    b.Property<int>("RequestedQuantity");
87
+
88
+                    b.Property<int>("VendorId");
89
+
90
+                    b.Property<int>("VoucherType");
91
+
92
+                    b.HasKey("Id");
93
+
94
+                    b.HasIndex("AccountId");
95
+
96
+                    b.HasIndex("OrderGuid")
97
+                        .IsUnique();
98
+
99
+                    b.HasIndex("ReadyForDownload", "OrderDate");
100
+
101
+                    b.ToTable("Batches");
102
+                });
103
+
104
+            modelBuilder.Entity("MAX.Models.User", b =>
105
+                {
106
+                    b.Property<int>("Id");
107
+
108
+                    b.Property<int>("AccountId");
109
+
110
+                    b.Property<bool>("BulkExport");
111
+
112
+                    b.Property<decimal>("BulkExportMaxValue");
113
+
114
+                    b.Property<bool>("BulkOrder");
115
+
116
+                    b.Property<decimal>("BulkOrderMaxValue");
117
+
118
+                    b.Property<bool>("BulkReExport");
119
+
120
+                    b.Property<bool>("BulkViewPins");
121
+
122
+                    b.Property<bool>("CanPrintOffline");
123
+
124
+                    b.Property<bool>("CanPrintOnline");
125
+
126
+                    b.Property<bool>("CanReprintOffline");
127
+
128
+                    b.Property<bool>("CanReprintOnline");
129
+
130
+                    b.Property<bool>("Enabled");
131
+
132
+                    b.Property<string>("FirstName")
133
+                        .IsRequired()
134
+                        .HasMaxLength(50);
135
+
136
+                    b.Property<DateTimeOffset>("LastLogin");
137
+
138
+                    b.Property<int>("Level");
139
+
140
+                    b.Property<decimal>("OfflinePrintValue");
141
+
142
+                    b.Property<decimal>("OfflineReprintValue");
143
+
144
+                    b.Property<decimal>("OnlinePrintValue");
145
+
146
+                    b.Property<decimal>("OnlineReprintValue");
147
+
148
+                    b.Property<string>("Surname")
149
+                        .IsRequired()
150
+                        .HasMaxLength(50);
151
+
152
+                    b.Property<int>("System");
153
+
154
+                    b.Property<string>("Username")
155
+                        .IsRequired()
156
+                        .HasMaxLength(50);
157
+
158
+                    b.HasKey("Id");
159
+
160
+                    b.HasIndex("AccountId");
161
+
162
+                    b.ToTable("Users");
163
+                });
164
+
165
+            modelBuilder.Entity("MAX.Models.Vendor", b =>
166
+                {
167
+                    b.Property<int>("Id");
168
+
169
+                    b.Property<int>("AccountId");
170
+
171
+                    b.Property<byte[]>("EncryptedDatabasePassword")
172
+                        .IsRequired()
173
+                        .HasMaxLength(32);
174
+
175
+                    b.Property<byte[]>("EncryptedVoucherKey")
176
+                        .IsRequired()
177
+                        .HasMaxLength(32);
178
+
179
+                    b.Property<int?>("LastVendorEventRemoteId");
180
+
181
+                    b.Property<string>("SerialNumber")
182
+                        .IsRequired()
183
+                        .HasMaxLength(50);
184
+
185
+                    b.HasKey("Id");
186
+
187
+                    b.HasIndex("AccountId");
188
+
189
+                    b.ToTable("Vendors");
190
+                });
191
+
192
+            modelBuilder.Entity("MAX.Models.VendorEvent", b =>
193
+                {
194
+                    b.Property<int>("Id")
195
+                        .ValueGeneratedOnAdd();
196
+
197
+                    b.Property<DateTimeOffset>("EventDate");
198
+
199
+                    b.Property<int>("EventType");
200
+
201
+                    b.Property<int?>("RemoteId");
202
+
203
+                    b.Property<bool>("Retry");
204
+
205
+                    b.Property<int>("UserId");
206
+
207
+                    b.Property<int>("VendorId");
208
+
209
+                    b.Property<int?>("VoucherId");
210
+
211
+                    b.HasKey("Id");
212
+
213
+                    b.HasIndex("VendorId", "RemoteId")
214
+                        .IsUnique();
215
+
216
+                    b.ToTable("VendorEvents");
217
+                });
218
+
219
+            modelBuilder.Entity("MAX.Models.Voucher", b =>
220
+                {
221
+                    b.Property<int>("Id");
222
+
223
+                    b.Property<int>("BatchId");
224
+
225
+                    b.Property<string>("EncryptedPIN")
226
+                        .IsRequired()
227
+                        .HasMaxLength(50);
228
+
229
+                    b.Property<DateTime>("ExpiryDate")
230
+                        .HasColumnType("Date");
231
+
232
+                    b.Property<int>("SequenceNumber");
233
+
234
+                    b.Property<string>("Serial")
235
+                        .IsRequired()
236
+                        .HasMaxLength(50);
237
+
238
+                    b.HasKey("Id");
239
+
240
+                    b.HasIndex("BatchId", "SequenceNumber")
241
+                        .IsUnique();
242
+
243
+                    b.ToTable("Vouchers");
244
+                });
245
+
246
+            modelBuilder.Entity("MAX.Models.Warehouse", b =>
247
+                {
248
+                    b.Property<int>("Id");
249
+
250
+                    b.Property<string>("Name")
251
+                        .IsRequired()
252
+                        .HasMaxLength(50);
253
+
254
+                    b.HasKey("Id");
255
+
256
+                    b.ToTable("Warehouses");
257
+                });
258
+
259
+            modelBuilder.Entity("MAX.Models.Account", b =>
260
+                {
261
+                    b.HasOne("MAX.Models.Warehouse", "Warehouse")
262
+                        .WithMany("Accounts")
263
+                        .HasForeignKey("WarehouseId")
264
+                        .OnDelete(DeleteBehavior.Cascade);
265
+                });
266
+
267
+            modelBuilder.Entity("MAX.Models.Batch", b =>
268
+                {
269
+                    b.HasOne("MAX.Models.Account", "Account")
270
+                        .WithMany()
271
+                        .HasForeignKey("AccountId")
272
+                        .OnDelete(DeleteBehavior.Cascade);
273
+                });
274
+
275
+            modelBuilder.Entity("MAX.Models.User", b =>
276
+                {
277
+                    b.HasOne("MAX.Models.Account", "Account")
278
+                        .WithMany("Users")
279
+                        .HasForeignKey("AccountId")
280
+                        .OnDelete(DeleteBehavior.Cascade);
281
+                });
282
+
283
+            modelBuilder.Entity("MAX.Models.Vendor", b =>
284
+                {
285
+                    b.HasOne("MAX.Models.Account", "Account")
286
+                        .WithMany("Vendors")
287
+                        .HasForeignKey("AccountId")
288
+                        .OnDelete(DeleteBehavior.Cascade);
289
+                });
290
+
291
+            modelBuilder.Entity("MAX.Models.Voucher", b =>
292
+                {
293
+                    b.HasOne("MAX.Models.Batch", "Batch")
294
+                        .WithMany("Vouchers")
295
+                        .HasForeignKey("BatchId")
296
+                        .OnDelete(DeleteBehavior.Cascade);
297
+                });
298
+        }
299
+    }
300
+}

+ 25 - 0
BulkPrintingAPI/Migrations/20180111104438_AddInternalReference.cs

1
+using System;
2
+using System.Collections.Generic;
3
+using Microsoft.EntityFrameworkCore.Migrations;
4
+
5
+namespace BulkPrintingAPI.Migrations
6
+{
7
+    public partial class AddInternalReference : Migration
8
+    {
9
+        protected override void Up(MigrationBuilder migrationBuilder)
10
+        {
11
+            migrationBuilder.AddColumn<string>(
12
+                name: "InternalReference",
13
+                table: "Batches",
14
+                maxLength: 32,
15
+                nullable: true);
16
+        }
17
+
18
+        protected override void Down(MigrationBuilder migrationBuilder)
19
+        {
20
+            migrationBuilder.DropColumn(
21
+                name: "InternalReference",
22
+                table: "Batches");
23
+        }
24
+    }
25
+}

+ 3 - 0
BulkPrintingAPI/Migrations/MAXContextModelSnapshot.cs

55
 
55
 
56
                     b.Property<decimal>("FaceValue");
56
                     b.Property<decimal>("FaceValue");
57
 
57
 
58
+                    b.Property<string>("InternalReference")
59
+                        .HasMaxLength(32);
60
+
58
                     b.Property<int>("NetworkId");
61
                     b.Property<int>("NetworkId");
59
 
62
 
60
                     b.Property<string>("NetworkName")
63
                     b.Property<string>("NetworkName")

+ 4 - 1
MAXClient/Client.cs

340
         }
340
         }
341
 
341
 
342
         public async Task<OrderResponse> PlaceOrderAsync(int accountId, Product product, int quantity,
342
         public async Task<OrderResponse> PlaceOrderAsync(int accountId, Product product, int quantity,
343
-            string customerReference, Guid? orderGuid, byte[] key)
343
+            string customerReference, string internalReference, Guid? orderGuid, byte[] key)
344
         {
344
         {
345
             if (key.Length != 24)
345
             if (key.Length != 24)
346
             {
346
             {
361
                     .Append(BitConverter.ToString(key, 8, 8).Replace("-", ""))
361
                     .Append(BitConverter.ToString(key, 8, 8).Replace("-", ""))
362
                     .Append("|")
362
                     .Append("|")
363
                     .Append(BitConverter.ToString(key, 16, 8).Replace("-", ""))
363
                     .Append(BitConverter.ToString(key, 16, 8).Replace("-", ""))
364
+                    .Append("|")
365
+                    .Append(internalReference)
364
                     .ToString()))).ConfigureAwait(false);
366
                     .ToString()))).ConfigureAwait(false);
365
 
367
 
366
             var response = Decrypt(await ReadMessageAsync().ConfigureAwait(false));
368
             var response = Decrypt(await ReadMessageAsync().ConfigureAwait(false));
377
                         RequestedQuantity = int.Parse(parts[3]),
379
                         RequestedQuantity = int.Parse(parts[3]),
378
                         DeliveredQuantity = int.Parse(parts[4]),
380
                         DeliveredQuantity = int.Parse(parts[4]),
379
                         Cost = decimal.Parse(parts[5]),
381
                         Cost = decimal.Parse(parts[5]),
382
+                        InternalReference = internalReference,
380
                         OrderGuid = orderGuid,
383
                         OrderGuid = orderGuid,
381
                         AccountId = accountId,
384
                         AccountId = accountId,
382
                         VendorId = _vendorId,
385
                         VendorId = _vendorId,

+ 3 - 2
MAXClient/Utils.cs

90
 
90
 
91
         public static async Task<OrderResponse> PlaceOrderAsync(
91
         public static async Task<OrderResponse> PlaceOrderAsync(
92
             ClientFactory clientFactory, ILogger logger, LoginCredentials credentials,
92
             ClientFactory clientFactory, ILogger logger, LoginCredentials credentials,
93
-            Product product, int quantity, string customerReference, Guid? orderGuid, byte[] key)
93
+            Product product, int quantity, string customerReference, string internalReference,
94
+            Guid? orderGuid, byte[] key)
94
         {
95
         {
95
             using (var client = clientFactory.GetClient(logger, credentials))
96
             using (var client = clientFactory.GetClient(logger, credentials))
96
             {
97
             {
101
                         credentials.ToString()));
102
                         credentials.ToString()));
102
                 }
103
                 }
103
                 return await client.PlaceOrderAsync(credentials.User.AccountId,
104
                 return await client.PlaceOrderAsync(credentials.User.AccountId,
104
-                    product, quantity, customerReference, orderGuid, key).ConfigureAwait(false);
105
+                    product, quantity, customerReference, internalReference, orderGuid, key).ConfigureAwait(false);
105
             }
106
             }
106
         }
107
         }
107
     }
108
     }

+ 3 - 0
MAXData/Models/Batch.cs

45
         [Required, MaxLength(20)]
45
         [Required, MaxLength(20)]
46
         public string OrderReference { get; set; }
46
         public string OrderReference { get; set; }
47
 
47
 
48
+        [MaxLength(32)]
49
+        public string InternalReference { get; set; }
50
+
48
         public int NetworkId { get; set; }
51
         public int NetworkId { get; set; }
49
 
52
 
50
         [Required, MaxLength(20)]
53
         [Required, MaxLength(20)]