While working through a process of batch editing a database tables that
had a timestamp field in each row for concurrency checking. It was not
immediately apparent the the return value for the update could be the
same as that for the create procedure.
Could you update your
documentation to explain that during an update you can return the
results of the update process to the grid.
so using generics the insert process can be:-
public
static DataSourceResult AddChanges<TEntity>([DataSourceRequest]
DataSourceRequest request, System.Data.Entity.DbContext context,
System.Web.Mvc.ModelStateDictionary modelState,
System.Collections.Generic.IEnumerable<TEntity> dbes)
where TEntity : class
{
var results = new System.Collections.Generic.List<TEntity>();
if (dbes != null && modelState.IsValid)
{
foreach (var dbe in dbes)
{
if (AddChanges<TEntity>(context, modelState, dbe))
results.Add(dbe);
}
}
return results.ToDataSourceResult(request, modelState);
}
and the update process can also be:-
public
static DataSourceResult SaveChanges<TEntity>([DataSourceRequest]
DataSourceRequest request, System.Data.Entity.DbContext context,
System.Web.Mvc.ModelStateDictionary modelState,
System.Collections.Generic.IEnumerable<TEntity> detached)
where TEntity : class
{
var results = new System.Collections.Generic.List<TEntity>();
if (modelState.IsValid)
{
foreach (var dbe in detached)
{
if (SaveChanges<TEntity>(context, modelState, dbe))
results.Add(dbe);
}
}
return results.ToDataSourceResult(request, modelState);
}
NOTE the return of the results from the Save process
so in a controller the create and edit ActionResults would like :-
[AcceptVerbs(HttpVerbs.Post)]
public virtual ActionResult ProductPricingClientCreate([DataSourceRequest] DataSourceRequest request, [Bind(Prefix = "models")]IEnumerable<ProductPricing> prices)
{
return Json(PS.Common.DataAccess.AddChanges<ProductPricing>(request, db, ModelState, prices));
}
[AcceptVerbs(HttpVerbs.Post)]
public virtual ActionResult ProductPricingGridUpdate([DataSourceRequest] DataSourceRequest request, [Bind(Prefix = "models")]IEnumerable<ProductPricing> prices)
{
return Json(PS.Common.DataAccess.SaveChanges<ProductPricing>(request, db, ModelState, prices));
}
had a timestamp field in each row for concurrency checking. It was not
immediately apparent the the return value for the update could be the
same as that for the create procedure.
Could you update your
documentation to explain that during an update you can return the
results of the update process to the grid.
so using generics the insert process can be:-
public
static DataSourceResult AddChanges<TEntity>([DataSourceRequest]
DataSourceRequest request, System.Data.Entity.DbContext context,
System.Web.Mvc.ModelStateDictionary modelState,
System.Collections.Generic.IEnumerable<TEntity> dbes)
where TEntity : class
{
var results = new System.Collections.Generic.List<TEntity>();
if (dbes != null && modelState.IsValid)
{
foreach (var dbe in dbes)
{
if (AddChanges<TEntity>(context, modelState, dbe))
results.Add(dbe);
}
}
return results.ToDataSourceResult(request, modelState);
}
and the update process can also be:-
public
static DataSourceResult SaveChanges<TEntity>([DataSourceRequest]
DataSourceRequest request, System.Data.Entity.DbContext context,
System.Web.Mvc.ModelStateDictionary modelState,
System.Collections.Generic.IEnumerable<TEntity> detached)
where TEntity : class
{
var results = new System.Collections.Generic.List<TEntity>();
if (modelState.IsValid)
{
foreach (var dbe in detached)
{
if (SaveChanges<TEntity>(context, modelState, dbe))
results.Add(dbe);
}
}
return results.ToDataSourceResult(request, modelState);
}
NOTE the return of the results from the Save process
so in a controller the create and edit ActionResults would like :-
[AcceptVerbs(HttpVerbs.Post)]
public virtual ActionResult ProductPricingClientCreate([DataSourceRequest] DataSourceRequest request, [Bind(Prefix = "models")]IEnumerable<ProductPricing> prices)
{
return Json(PS.Common.DataAccess.AddChanges<ProductPricing>(request, db, ModelState, prices));
}
[AcceptVerbs(HttpVerbs.Post)]
public virtual ActionResult ProductPricingGridUpdate([DataSourceRequest] DataSourceRequest request, [Bind(Prefix = "models")]IEnumerable<ProductPricing> prices)
{
return Json(PS.Common.DataAccess.SaveChanges<ProductPricing>(request, db, ModelState, prices));
}