This is a migrated thread and some comments may be shown as answers.

Batch Editing in a grid with rows containing timestamp or row version

0 Answers 64 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Timothy
Top achievements
Rank 1
Timothy asked on 24 Apr 2013, 11:18 PM
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));
}


No answers yet. Maybe you can help?

Tags
Grid
Asked by
Timothy
Top achievements
Rank 1
Share this question
or