/// <summary> /// Delete object from db /// </summary> /// <typeparam name="T"></typeparam> /// <param name="repository"></param> /// <param name="o"></param> internal static void DeleteAbstract <T>(this ICustomRepository repository, T o) where T : class, IDbEntity { if (o != null) { DbSchema.DeleteAbstract(repository, o, true); } }
public ProfileManagementService(ICustomRepository <ProfileMaster> profileRepository, ICustomRepository <Typemaster> typemasterRepository , ICustomRepository <SubscriptionMaster> subscriptionRepository) { _profileRepository = profileRepository; _typemasterRepository = typemasterRepository; _subscriptionRepository = subscriptionRepository; }
/// <summary> /// select object by its id /// </summary> /// <typeparam name="T"></typeparam> /// <param name="repository"></param> /// <param name="objectId"></param> /// <returns></returns> public static ISqlQueriable <T> GetAbstractById <T>(this ICustomRepository repository, long?objectId) where T : class, IDbEntity { return(!objectId.HasValue ? null : new SqlQueriable <T>(new List <T>() { (T)DbSchema.GetSqlById(objectId.Value, repository, typeof(T)) }, repository)); }
/// <summary> /// Delete object from db /// </summary> /// <typeparam name="T"></typeparam> /// <param name="repository"></param> /// <param name="o"></param> internal static async Task DeleteAbstractAsync <T>(this ICustomRepository repository, T o) where T : class, IDbEntity { if (o != null) { await Task.Run(() => DbSchema.DeleteAbstract(repository, o, true)); } }
public Order_masterController(ICustomRepository customRepository, IDeliverRepository deliverRepository, IEmployeeRepository employeeRepository, IOrder_masterRepository order_MasterRepository) { _customRepository = customRepository; _deliverRepository = deliverRepository; _employeeRepository = employeeRepository; _order_MasterRepository = order_MasterRepository; }
public override void ExecuteMigration(ICustomRepository repository) { repository.CreateTable <User>(true); // create the table User, Role, Address var user = new User() { Role = new Role() { Name = "Admin" }, Address = new List <Address>() { new Address() { AddressName = "test" } }, UserName = "******", Password = "******" }; repository.Save(user); base.ExecuteMigration(repository); }
public TempUserRegisterService(CleanArchitectureContext dbContext, ILogger <TempUserRegisterService> log, IUserService userService, ITempOtpService tempOtpService, ICustomRepository <TempUserRegister> tempRepository) { _dbContext = dbContext; _log = log; _userService = userService; _tempOtpService = tempOtpService; _tempRepository = tempRepository; }
public void BeforeSave(ICustomRepository repository, User itemDbEntity) { if (string.IsNullOrEmpty(itemDbEntity.Password) || string.IsNullOrEmpty(itemDbEntity.UserName)) { // this will do a transaction rollback and delete all changes that have happened to the database throw new Exception("Password or UserName can not be empty"); } }
/// <summary> /// object must containe PrimaryKey /// </summary> /// <typeparam name="T"></typeparam> /// <param name="repository"></param> /// <param name="o"></param> /// <returns></returns> internal static async Task <long> SaveAsync <T>(this ICustomRepository repository, T o) where T : IDbEntity { if (o == null) { return(await Task.FromResult <long>(-1)); } o.State = ItemState.Added; return(await Task.Run(() => DbSchema.SaveObject(repository, o, false, true))); }
public void AfterSave(ICustomRepository repository, User itemDbEntity, long objectId) { itemDbEntity.ClearPropertChanges();// clear all changes. // lets do some changes here, when the item have updated.. itemDbEntity.Password = MethodHelper.EncodeStringToBase64(itemDbEntity.Password); // and now we want to save this change to the database itemDbEntity.State = ItemState.Changed; // the lightdatatable will now that it need to update the database agen. }
/// <summary> /// All available Migrations to be executed /// </summary> public IList <Migration> GetMigrations(ICustomRepository repository) { // return all migration that is to be executetd // all already executed migration that do exist in the database will be ignored return(new List <Migration>() { new Migration_1() }); }
/// <summary> /// object must containe PrimaryKey /// </summary> /// <typeparam name="T"></typeparam> /// <param name="repository"></param> /// <param name="o"></param> /// <returns></returns> public static long Save <T>(this ICustomRepository repository, T o) where T : IDbEntity { if (o == null) { return(-1); } o.State = ItemState.Added; return(DbSchema.SaveObject(repository, o, false, true)); }
public TwoFaMasterServices(IUserService userService, ICustomRepository <TwoFAmaster> customRepository, IRegisterTypeService registerTypeService, IMediator mediator) { _userService = userService; _customRepository = customRepository; _registerTypeService = registerTypeService; _mediator = mediator; }
/// <summary> /// Get all by object /// PrimaryKey attr must be set /// </summary> /// <typeparam name="T"></typeparam> /// <param name="repository"></param> /// <param name="quary"></param> /// <param name="type"></param> /// <returns></returns> internal static IList GetSqlAll(ICustomRepository repository, Type type) { var sqlKey = type.FullName + "GetSqlAll"; if (!CachedSql.ContainsKey(sqlKey)) { CachedSql.Add(sqlKey, Querys.Select(type, repository.GetDataBaseType() == DataBaseTypes.Sqllight).Execute()); } return(repository.GetLightDataTable(repository.GetSqlCommand(CachedSql[sqlKey])).Rows.ToObject(type)); }
public OrderService(IRepository <Order, long> orderRepository, IRepository <Product, long> productRepository, ICustomRepository <Order, long> CustomRepository, OrderManager orderManager) { _orderRepository = orderRepository; _productRepository = productRepository; this.CustomRepository = CustomRepository; _orderManager = orderManager; }
public UserChangeLogServices(CleanArchitectureContext dbContext, ICustomRepository <UserLogChange> customRepository, //IMessageRepository<Customtoken> customRepository, ILogger <UserLogChange> logger) { _dbContext = dbContext; _customRepository = customRepository; _logger = logger; }
/// <summary> /// load children /// </summary> /// <typeparam name="T"></typeparam> /// <typeparam name="TP"></typeparam> /// <param name="repository"></param> /// <param name="item"></param> /// <param name="onlyFirstLevel"></param> /// <param name="ignoreList"></param> /// <param name="actions"></param> internal static void LoadChildren <T, TP>(this ICustomRepository repository, T item, bool onlyFirstLevel = false, List <string> ignoreList = null, params Expression <Func <T, TP> >[] actions) where T : class, IDbEntity { var parames = new List <string>(); if (actions != null) { parames = actions.ConvertExpressionToIncludeList(); } DbSchema.LoadChildren <T>(item, repository, onlyFirstLevel, actions != null ? parames : null, ignoreList != null && ignoreList.Any() ? ignoreList : null); }
public CustomPasswordService( CleanArchitectureContext dbContext, IUserService userService, ICustomRepository <CustomPassword> customRepository, //IMessageRepository<Customtoken> customRepository, ILogger <CustomPassword> logger) { _dbContext = dbContext; _userService = userService; _customRepository = customRepository; _logger = logger; }
internal SqlQueriable(List <T> items, ICustomRepository repository) { _repository = repository; if (items == null) { return; } _partExecuted = true; items.RemoveAll(x => x == null); base.AddRange(items); }
/// <summary> /// load children /// </summary> /// <typeparam name="T"></typeparam> /// <typeparam name="TP"></typeparam> /// <param name="repository"></param> /// <param name="item"></param> /// <param name="onlyFirstLevel"></param> /// <param name="ignoreList"></param> /// <param name="actions"></param> internal static async Task <bool> LoadChildrenAsync <T, TP>(this ICustomRepository repository, T item, bool onlyFirstLevel = false, List <string> ignoreList = null, params Expression <Func <T, TP> >[] actions) where T : class, IDbEntity { var parames = new List <string>(); if (actions != null) { parames = actions.ConvertExpressionToIncludeList(); } await Task.Run(() => DbSchema.LoadChildren <T>(item, repository, onlyFirstLevel, actions != null ? parames : null, ignoreList != null && ignoreList.Any() ? ignoreList : null)); return(await Task.FromResult <bool>(true)); }
internal static ILightDataTable Select(ICustomRepository repository, Type type, QueryItem quary = null) { var sql = new StringBuilder(); sql.Append(Querys.Select(type, repository.GetDataBaseType() == DataBaseTypes.Sqllight).Execute()); if (quary != null && quary.HasValue()) { sql.Append(quary.Execute()); } return(repository.GetLightDataTable(repository.GetSqlCommand(sql.ToString()))); }
private static ILightDataTable ObjectColumns(this ICustomRepository repository, Type type) { if (CachedObjectColumn.ContainsKey(type)) { return(CachedObjectColumn[type]); } var table = type.GetCustomAttribute <Table>()?.Name ?? type.Name; var cmd = repository.GetSqlCommand("SELECT COLUMN_NAME, DATA_TYPE FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = N'" + table + "'"); var data = repository.GetLightDataTable(cmd, "COLUMN_NAME"); CachedObjectColumn.Add(type, data); return(CachedObjectColumn[type]); }
/// <summary> /// Get all by object /// PrimaryKey attr must be set ins Where /// </summary> /// <typeparam name="T"></typeparam> /// <param name="repository"></param> /// <param name="quary"></param> /// <returns></returns> internal static List <T> Select <T>(ICustomRepository repository, QueryItem quary = null) where T : class { var type = typeof(T); var sql = new StringBuilder(); sql.Append(Querys.Select(type, repository.GetDataBaseType() == DataBaseTypes.Sqllight).Execute()); if (quary != null && quary.HasValue()) { sql.Append(quary.Execute()); } return(repository.GetLightDataTable(repository.GetSqlCommand(sql.ToString())).Rows.ToObject <T>()); }
/// <summary> /// Get all by object /// PrimaryKey attr must be set ins Where /// </summary> /// <typeparam name="T"></typeparam> /// <param name="repository"></param> /// <param name="quary"></param> /// <returns></returns> internal static List <T> Where <T>(ICustomRepository repository, string quary = null) where T : class { var type = typeof(T); var sql = new StringBuilder(); sql.Append(Querys.Select(type, repository.GetDataBaseType() == DataBaseTypes.Sqllight).Execute()); if (!string.IsNullOrEmpty(quary)) { sql = new StringBuilder(quary); } return(repository.GetLightDataTable(repository.GetSqlCommand(sql.ToString())).Rows.ToObject <T>()); }
/// <summary> /// Get object by ID /// Primary Key attribute must be set /// </summary> /// <param name="id"></param> /// <param name="repository"></param> /// <param name="type"></param> /// <returns></returns> internal static object GetSqlById(long id, ICustomRepository repository, Type type) { var sqlKey = type.GetActualType().FullName + "GetById"; if (!CachedSql.ContainsKey(sqlKey)) { var key = type.GetActualType().GetPrimaryKey().GetPropertyName(); CachedSql.Add(sqlKey, Querys.Select(type.GetActualType(), repository.GetDataBaseType() == DataBaseTypes.Sqllight).Where.Column <long>(key).Equal("@ID", true).Execute()); } var cmd = repository.GetSqlCommand(CachedSql[sqlKey]); repository.AddInnerParameter(cmd, "@ID", id, System.Data.SqlDbType.BigInt); if (type.IsGenericType && type.GetGenericTypeDefinition()?.Name == "List`1" && type.GenericTypeArguments.Length > 0) { return(repository.GetLightDataTable(cmd).Rows.ToObject(type)); } return(repository.GetLightDataTable(cmd).Rows.FirstOrDefault()?.ToObject(type)); }
/// <summary> /// Retrieve <see cref="ICustomRepository"/> based on AppSettings. /// </summary> /// <returns>The <see cref="ICustomRepository"/> implementation.</returns> public static ICustomRepository CustomRepository() { ICustomRepository customRepository = null; string repositoryType = ConfigurationManager.AppSettings["Repository"].ToString(); switch (repositoryType) { case "SQLite": customRepository = new CustomRepository(); break; default: throw new ArgumentException("Invalid repository type"); } return(customRepository); }
/// <summary> /// Get all by object /// Get object by column, as fogenKey /// </summary> /// <typeparam name="T"></typeparam> /// <param name="column"></param> /// <param name="repository"></param> /// <param name="quary"></param> /// <param name="id"></param> /// <param name="type"></param> /// <returns></returns> private static object GetByColumn(long id, string column, ICustomRepository repository, Type type) { var sqlKey = type.FullName + "GetByColumn" + column; if (!CachedSql.ContainsKey(sqlKey)) { CachedSql.Add(sqlKey, Querys.Select(type).Where.Column <long>(column).Equal("@ID", true).Execute()); } var cmd = repository.GetSqlCommand(CachedSql[sqlKey]); repository.AddInnerParameter(cmd, "@ID", id, System.Data.SqlDbType.BigInt); if (type.IsGenericType && type.GetGenericTypeDefinition()?.Name == "List`1" && type.GenericTypeArguments.Length > 0) { return(repository.GetLightDataTable(cmd).Rows.ToObject(type)); } return(repository.GetLightDataTable(cmd).Rows.FirstOrDefault()?.ToObject(type)); }
private static ILightDataTable ObjectColumns(this ICustomRepository repository, Type type) { if (CachedObjectColumn.ContainsKey(type)) { return(CachedObjectColumn[type]); } var table = type.GetCustomAttribute <Table>()?.Name ?? type.Name; var cmd = repository.GetSqlCommand(repository.GetDataBaseType() == DataBaseTypes.Mssql ? "SELECT COLUMN_NAME, DATA_TYPE FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = N'" + table + "'" : "SELECT name as COLUMN_NAME, type as DATA_TYPE FROM pragma_table_info('" + table + "');"); var data = repository.GetLightDataTable(cmd, "COLUMN_NAME"); if (data.Rows.Any()) { CachedObjectColumn.Add(type, data); } else { return(data); } return(CachedObjectColumn[type]); }
public ComplainmasterServices(ICustomRepository <Complainmaster> customRepository, CleanArchitectureContext context) { _ComplainmasterRepository = customRepository; _dbContext = context; }
public CustomServiceImpl() { _customRepository = new CustomRepositoryImpl(); }