public StorageOperationResult Delete(int id) { T entity = _set.Find(id); if (entity == null) { StorageOperationError error = new StorageOperationError(id, typeof(T).Name, "The entity requested for deletion was not found in the data storage"); return(new StorageOperationResult() { Errors = new StorageOperationError[] { error } }); } _set.Remove(entity); try { _context.SaveChanges(); return(new StorageOperationResult(StorageOperationResult.EmptyOperation, StorageOperationResult.EmptyOperation, new int[] { id })); } catch (DbUpdateException ex) { return(new StorageOperationResult() { Errors = ex.Entries.Select(entry => new StorageOperationError(((T)entry.Entity).Id, typeof(T).Name, ex.Message)) }); } }
public ActionResult Delete(int?id) { StorageOperationResult result; if (id.HasValue) { result = _repository.Delete(id.Value); } else { StorageOperationError error = new StorageOperationError(0, null, "No Id argument received in server for delete operation"); result = new StorageOperationResult() { Errors = new StorageOperationError[] { error } }; } return(PrepareUpdateResult(result)); }
public ActionResult SaveMany(IEnumerable <T> entities) { StorageOperationResult result; if (entities != null) { result = _repository.SaveMany(entities); } else { StorageOperationError error = new StorageOperationError(0, null, "No data recieved in server for SaveMany operation."); result = new StorageOperationResult() { Errors = new StorageOperationError[] { error } }; } return(PrepareUpdateResult(result)); }