public override Task Invoke(AspectContext context, AspectDelegate next) { if (string.IsNullOrEmpty(Sql)) { throw new ArgumentNullException(nameof(Sql)); } var paramters = context.GetParameters(); var sqlParamters = ToParamterDict(paramters); using (var conn = ConnectionFactory.CreateConnection(ConnectionName)) { //get IAgileRepository<TEntity> 's TEntity for Query T var result = (int)QueryHelper.RunExecute(conn, Sql, sqlParamters); if (context.ServiceMethod.ReturnType == typeof(bool)) { context.ReturnValue = result >= 0; } else { context.ReturnValue = result; } } return(context.Break()); }
public override Task Invoke(AspectContext context, AspectDelegate next) { var dbContext = GetDbContext(context); var entityType = GetEntityType(context); var dbSet = GetDbSet(dbContext, entityType); context.ReturnValue = ExecuteSql(entityType, dbSet, context.Parameters); return(context.Break()); }
public override Task Invoke(AspectContext context, AspectDelegate next) { var localizer = GetLocalizerInstance(context); var resourceKey = string.IsNullOrEmpty(Key) ? context.ServiceMethod.Name : Key; var localizedString = localizer?.GetString(resourceKey); var template = localizedString.ResourceNotFound ? this.Value : localizedString.Value; context.ReturnValue = FormatTemplate(template, context); return(context.Break()); }
public override Task Invoke(AspectContext context, AspectDelegate next) { this.AssertReturnType(context); var errorCode = GetErrorCode(context); var message = GetErrorMessage(context); var data = GetExceptionData(context); var innerException = GetInnerException(context); context.ReturnValue = BuildException(errorCode, message, data, innerException); return(context.Break()); }
public override Task Invoke(AspectContext context, AspectDelegate next) { var sql = GenericSqlByMethodName(context, next); var paramters = context.GetParameters(); var queryParams = ToParamterDict(paramters); using (var conn = ConnectionFactory.CreateConnection(ConnectionName)) { var result = QueryHelper.RunGenericCount(context.ServiceMethod.ReturnType, conn, sql, queryParams); context.ReturnValue = result; } return(context.Break()); }
public override Task Invoke(AspectContext context, AspectDelegate next) { var sql = GenericSqlByMethodName(context, next); var paramters = context.GetParameters(); var queryParams = ToParamterDict(paramters); using (var conn = ConnectionFactory.CreateConnection(ConnectionName)) { var gt = AgileRepositoryGenericTypeArguments(context); var result = QueryHelper.RunGenericQuery(gt.First(), conn, sql, queryParams); context.ReturnValue = result; } return(context.Break()); }
public override Task Invoke(AspectContext context, AspectDelegate next) { if (string.IsNullOrEmpty(Sql)) { throw new ArgumentNullException(nameof(Sql)); } var paramters = context.GetParameters(); var queryParams = ToParamterDict(paramters); using (var conn = ConnectionFactory.CreateConnection(ConnectionName)) { var result = QueryHelper.RunGenericCount(context.ServiceMethod.ReturnType, conn, Sql, queryParams); context.ReturnValue = result; } return(context.Break()); }
public override Task Invoke(AspectContext context, AspectDelegate next) { if (string.IsNullOrEmpty(Sql)) { throw new ArgumentNullException(nameof(Sql)); } var paramters = context.GetParameters(); var queryParams = ToParamterDict(paramters); using (var conn = ConnectionFactory.CreateConnection(ConnectionName)) { var gt = AgileRepositoryGenericTypeArguments(context); //get IAgileRepository<TEntity> 's TEntity for Query T var result = QueryHelper.RunGenericQuery(gt[0], conn, Sql, queryParams); context.ReturnValue = result; } return(context.Break()); }
public override Task Invoke(AspectContext context, AspectDelegate next) { var paramters = context.GetParameters(); var queryParams = ToParamterDict(paramters); using (var conn = ConnectionFactory.CreateConnection(ConnectionName)) { var sql = GenericDeleteSql(context); var result = (int)QueryHelper.RunExecute(conn, sql, queryParams); if (context.ServiceMethod.ReturnType == typeof(bool)) { context.ReturnValue = result > 0; } else { context.ReturnValue = result; } } return(context.Break()); }
public override Task Invoke(AspectContext context, AspectDelegate next) { var paramters = context.GetParameters(); using (var conn = ConnectionFactory.CreateConnection(ConnectionName)) { var sql = GenericInsertSql(context); var insertParam = paramters.First(); var isIEnumerable = (insertParam as IEnumerable) != null; var result = 0; if (!isIEnumerable) { result = (int)QueryHelper.RunExecute(conn, sql, paramters.First().Value); } else { //for insert entities using (var tran = conn.BeginTransaction()) { foreach (var p in (IEnumerable)insertParam) { result += (int)QueryHelper.RunExecute(conn, tran, sql, p); } tran.Commit(); } } if (context.ServiceMethod.ReturnType == typeof(bool)) { context.ReturnValue = result > 0; } else { context.ReturnValue = result; } } return(context.Break()); }