11@page " /"
2-
2+ @ using AutoMapper
33@using InstantFeedback .Models ;
44@using Microsoft .EntityFrameworkCore
55@using DevExpress .Data .Linq
4848@code {
4949 EntityInstantFeedbackSource InstantFeedbackSource { get ; set ; }
5050 NorthwindContext Northwind { get ; set ; }
51+ IMapper ProductMapper { get ; set ; }
5152
5253 protected override void OnInitialized () {
5354 Northwind = NorthwindContextFactory .CreateDbContext ();
5455 InstantFeedbackSource = new EntityInstantFeedbackSource (e => {
5556 e .KeyExpression = " OrderId" ;
5657 e .QueryableSource = Northwind .Orders ;
5758 });
59+ var config = new MapperConfiguration (c => c .CreateMap <Order , Order >());
60+ ProductMapper = config .CreateMapper ();
5861 }
5962 async Task OnEditModelSaving (GridEditModelSavingEventArgs e ) {
6063 var editModel = (Order )e .EditModel ;
6164 // Re-query a data item from the database.
6265 var dataItem = e .IsNew ? new Order () : Northwind .Orders .Find (editModel .OrderId );
6366 // Assign changes from the edit model to the data item.
6467 if (dataItem != null ) {
65- dataItem .ShipName = editModel .ShipName ;
66- dataItem .ShipCity = editModel .ShipCity ;
67- dataItem .ShipCountry = editModel .ShipCountry ;
68- dataItem .Freight = editModel .Freight ;
69- dataItem .OrderDate = editModel .OrderDate ;
70- dataItem .ShippedDate = editModel .ShippedDate ;
68+ ProductMapper .Map <Order , Order >(editModel , dataItem );
7169 // Post changes to the database.
7270 if (e .IsNew )
7371 await Northwind .AddAsync (dataItem );
9088 InstantFeedbackSource ? .Dispose ();
9189 Northwind ? .Dispose ();
9290 }
93- }
91+ }
0 commit comments