@@ -255,8 +255,119 @@ public void RegisterModule(IDependencyRegistrator dependencyRegistrator)
255
255
return container;
256
256
}}
257
257
}}
258
- }}" ) ) ;
258
+ }}" ) ) . WithFolder ( $ "{ solutionName } .Data.Real.Providers",
259
+ r => r . WithFile ( $ "{ entityName } DataProvider.cs",
260
+ $@ "using System;
261
+ using System.Collections.Generic;
262
+ using { solutionName } .Data.Contracts.Dto;
263
+ using { solutionName } .Data.Contracts.Providers;
264
+
265
+ namespace { solutionName } .Data.Real.Providers
266
+ {{
267
+ internal sealed class { entityName } DataProvider : I{ entityName } DataProvider
268
+ {{
269
+ public IEnumerable<{ entityName } Dto> GetItems()
270
+ {{
271
+ throw new NotImplementedException();
272
+ }}
273
+
274
+ public bool DeleteItem(Guid id)
275
+ {{
276
+ throw new NotImplementedException();
277
+ }}
278
+
279
+ public bool UpdateItem({ entityName } Dto dto)
280
+ {{
281
+ throw new NotImplementedException();
282
+ }}
283
+
284
+ public void CreateItem({ entityName } Dto dto)
285
+ {{
286
+ throw new NotImplementedException();
287
+ }}
288
+ }}
289
+ }}" ) ) . WithFolder ( $ "{ solutionName } .Model",
290
+ r => r . WithFile ( $ "{ entityName } Service.cs",
291
+ $@ "using System.Collections.Generic;
292
+ using System.Linq;
293
+ using System.Threading.Tasks;
294
+ using JetBrains.Annotations;
295
+ using LogoFX.Client.Core;
296
+ using LogoFX.Core;
297
+ using { solutionName } .Data.Contracts.Providers;
298
+ using { solutionName } .Model.Contracts;
299
+ using { solutionName } .Model.Mappers;
300
+
301
+ namespace { solutionName } .Model
302
+ {{
303
+ [UsedImplicitly]
304
+ internal sealed class { entityName } Service : NotifyPropertyChangedBase<{ entityName } Service>, I{ entityName } Service
305
+ {{
306
+ private readonly I{ entityName } DataProvider _provider;
307
+ private readonly { entityName } Mapper _mapper;
308
+
309
+ private readonly RangeObservableCollection<I{ entityName } > _items =
310
+ new RangeObservableCollection<I{ entityName } >();
311
+
312
+ public { entityName } Service(I{ entityName } DataProvider provider, { entityName } Mapper mapper)
313
+ {{
314
+ _provider = provider;
315
+ _mapper = mapper;
316
+ }}
317
+
318
+ private void GetItems()
319
+ {{
320
+ var items = _provider.GetItems().Select(_mapper.MapTo{ entityName } );
321
+ _items.Clear();
322
+ _items.AddRange(items);
323
+ }}
324
+
325
+ IEnumerable<I{ entityName } > I{ entityName } Service.Items => _items;
326
+
327
+ Task I{ entityName } Service.GetItems() => MethodRunner.RunAsync(GetItems);
328
+
329
+ Task<I{ entityName } > I{ entityName } Service.NewItem() => MethodRunner.RunWithResultAsync<I{ entityName } >(() => new { entityName } ());
330
+
331
+ Task I{ entityName } Service.SaveItem(I{ entityName } item) => MethodRunner.RunAsync(() =>
332
+ {{
333
+ var dto = _mapper.MapFrom{ entityName } (item);
334
+
335
+ if (item.IsNew)
336
+ {{
337
+ _provider.CreateItem(dto);
338
+ }}
339
+ else
340
+ {{
341
+ _provider.UpdateItem(dto);
342
+ }}
343
+ }});
259
344
345
+ Task I{ entityName } Service.DeleteItem(I{ entityName } item) => MethodRunner.RunAsync(() =>
346
+ {{
347
+ _provider.DeleteItem(item.Id);
348
+ _items.Remove(item);
349
+ }});
350
+ }}
351
+ }}" ) ) . WithFolder ( $ "{ solutionName } .Model.Contracts",
352
+ r => r . WithFile ( $ "I{ entityName } Service.cs",
353
+ $@ "using System.Collections.Generic;
354
+ using System.Threading.Tasks;
355
+
356
+ namespace { solutionName } .Model.Contracts
357
+ {{
358
+ public interface I{ entityName } Service
359
+ {{
360
+ IEnumerable<I{ entityName } > Items {{ get; }}
361
+
362
+ Task GetItems();
363
+
364
+ Task<I{ entityName } > NewItem();
365
+
366
+ Task SaveItem(I{ entityName } item);
367
+
368
+ Task DeleteItem(I{ entityName } item);
369
+ }}
370
+ }}" ) ) ;
260
371
261
372
structure . AssertGeneratedCode ( ) ;
262
373
}
0 commit comments