private async Task <IActionResult> Update(int id, Delta <Category> patch) #endif { var category = await FindAsync(id); if (category == null) { return(NotFound()); } #if NETCORE10 _db.Entry(patch as object).State = EntityState.Modified; #else if (!TryValidateModel(patch.GetInstance())) { return(BadRequest(ModelState)); } patch.Patch(category); #endif try { await _db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CategoryExists(id)) { return(NotFound()); } else { throw; } } #if NETCORE10 return(NoContent()); #else return(Updated(category)); #endif }
private ActionResult Update <T>(CollectionViewEditRequest <T> requestData, DbSet <T> data) where T : class { return(this.C1Json(CollectionViewHelper.Edit <T>(requestData, item => { string error = string.Empty; bool success = true; try { _db.Entry(item as object).State = EntityState.Modified; _db.SaveChanges(); } catch (Exception e) { error = GetExceptionMessage(e); success = false; } return new CollectionViewItemResult <T> { Error = error, Success = success, Data = item }; }, () => data.ToList <T>()))); }
public ActionResult ListUpdateProducts([C1JsonRequest] CollectionViewEditRequest <Product> requestData) { return(this.C1Json(CollectionViewHelper.Edit <Product>(requestData, item => { string error = string.Empty; bool success = true; try { _db.Entry(item as object).State = EntityState.Modified; _db.SaveChanges(); } catch (Exception e) { error = GetExceptionMessage(e); success = false; } return new CollectionViewItemResult <Product> { Error = error, Success = success, Data = item }; }, () => _db.Products.ToList <Product>()))); }