public (Result, string) Insert(IEnumerable <IndexNOResult> data, object state) { using (var adapter = new IndexNODataTableAdapter { Connection = new SqlConnection(SettingsContext.GlobalSettings.NifudaConnectionString) }) { if (!SafeCheck.IsValidConnection(adapter.Connection)) { return(Result.Unsuccess, $"Database connection error"); } var methodInfo = typeof(IndexNODataTableAdapter).GetMethod("Insert"); foreach (var obj in data) { var tupleParameters = obj.PropertiesToTuple(); var values = methodInfo.GetParameters().Select(info => tupleParameters.FirstOrDefault(p => p.Name.ToLower() == info.Name.ToLower()).Value ?? ""); if (values == null) { continue; } methodInfo.Invoke(adapter, values.ToArray()); } return(Result.Success, $"Ok"); } }
public IEnumerable <IndexNOResult> SelectDataByIndex(string index, object state) { using (var adapter = new IndexNODataTableAdapter { Connection = new SqlConnection(SettingsContext.GlobalSettings.NifudaConnectionString) }) { if (!SafeCheck.IsValidConnection(adapter.Connection)) { throw new ConnectionException(SettingsContext.GlobalSettings.NifudaConnectionString); } var dataTable = adapter.GetDataBySapIndexNO(index); foreach (var obj in dataTable.AdaptWithSameProperties <IndexNOResult, IndexNODataTableRow>()) { yield return(obj); } } }