private async Task PostTracking <T>(TrackingPostParameter <T> parameter) where T : new() { var procAttr = SqlMapperEx.GetStoredProcedureAttribute <T>(); var mapping = SqlMapperEx.GetMapping <T>(); var sqlParameters = new DynamicParameters(); foreach (var pair in mapping) { var propName = pair.Key; var sqlName = pair.Value; var value = typeof(T).GetProperty(propName).GetValue(parameter.Data, null); // parameters.Add("@newId", DbType.Int32, direction: ParameterDirection.Output); if (sqlName == procAttr.KeyColumnName) { sqlParameters.Add(sqlName, value, direction: ParameterDirection.InputOutput); } else { sqlParameters.Add(sqlName, value); } } sqlParameters.Add("Action", 16); sqlParameters.Add("LanguageID", parameter.Language); using (var connection = new SqlConnection(ConnectionString)) { await connection.ExecuteScalarAsync(procAttr.PostProcedureName, sqlParameters, commandType : CommandType.StoredProcedure); } }
private async Task <IEnumerable <T> > GetGridItems <T>(GridParameter parameter, Dictionary <string, object> extraParameters = null) { var procAttr = SqlMapperEx.GetStoredProcedureAttribute <T>(); var sqlParameters = new DynamicParameters(); sqlParameters.Add(procAttr.KeyColumnName, parameter.Id); sqlParameters.Add("LanguageID", parameter.Language); if (extraParameters != null) { foreach (var pair in extraParameters) { sqlParameters.Add(pair.Key, pair.Value); } } using (var connection = new SqlConnection(ConnectionString)) { var result = await connection.QueryAsync <T>(procAttr.GetProcedureName, sqlParameters, commandType : CommandType.StoredProcedure); return(result); } }
private async Task <T> GetTracking <T>(TrackingParameter parameter) { var procAttr = SqlMapperEx.GetStoredProcedureAttribute <T>(); var sqlParameters = new DynamicParameters(); sqlParameters.Add(procAttr.KeyColumnName, parameter.Id); sqlParameters.Add("LanguageID", parameter.Language); using (var connection = new SqlConnection(ConnectionString)) { var result = await connection.QueryMultipleAsync(procAttr.GetProcedureName, sqlParameters, commandType : CommandType.StoredProcedure); var tracking = result.ReadSingleOrDefault <T>(); //todo: implement reading of custom fields //var customFields = result.Read(); return(tracking); } }