public ActionResult Vehicles_Create([DataSourceRequest]DataSourceRequest request, VehicleGridInputModel vehicle) { var newId = 0; if (this.ModelState.IsValid) { var entity = new Vehicle() { Brand = vehicle.Brand, Model = vehicle.Model, RegistrationNumber = vehicle.RegistrationNumber, Year = vehicle.Year, Color = vehicle.Color }; this.vehicles.Create(entity); newId = entity.Id; } var vehicleToDisplay = this.vehicles .GetAll() .To<VehicleGridViewModel>() .FirstOrDefault(x => x.Id == newId); return this.Json(new[] { vehicleToDisplay }.ToDataSourceResult(request, this.ModelState)); }
public ActionResult Vehicles_Update([DataSourceRequest]DataSourceRequest request, VehicleGridInputModel vehicle) { if (this.ModelState.IsValid) { var entity = this.vehicles.GetAll().FirstOrDefault(x => x.Id == vehicle.Id); entity.Brand = vehicle.Brand; entity.Model = vehicle.Model; entity.RegistrationNumber = vehicle.RegistrationNumber; entity.Year = vehicle.Year; entity.Color = vehicle.Color; this.vehicles.Update(entity); } return this.Json(new[] { vehicle }.ToDataSourceResult(request, this.ModelState)); }