public Context(bool hasSqlAccess) { SqlConnectorManager sqlCon = new SqlConnectorManager(); if (hasSqlAccess)//else if web we should give the URL to the data access { sqlCon.InitializeConnection(@"C:\PosLite\PosLite.s3db"); } BusinessEntities = new Dictionary <Type, IBusinessBase>(); DataEntities = new Dictionary <Type, IDataBase>(); var typeOfDataBase = typeof(IDataBase); var typeOfBusinessBase = typeof(IBusinessBase); //Loads all Data Entities foreach (var type in ExistingIDataBase) { var entity = hasSqlAccess?(IDataBase)Activator.CreateInstance(type) : (IDataBase)Activator.CreateInstance(type, sqlCon); //get interface that is not a base (isgeneric refers to iblentity<T>) var first = type.GetInterfaces().First(x => x.IsGenericType == false && !(x.Equals(typeOfDataBase))); DataEntities.Add(first, entity); } foreach (var type in ExistingIBusinessBase) { //get interface that is not a base var first = type.GetInterfaces().First(x => x.IsGenericType == false && !(x.Equals(typeOfBusinessBase))); var transaction = (IBusinessBase)Activator.CreateInstance(type); BusinessEntities.Add(first, transaction); } }
/// <summary> /// Executes all that happens in action inside a transaction /// </summary> /// <param name="action">the action that will be executed inside a transaction</param> /// <returns></returns> public void ExecuteInTransaction(Action action, SqlConnectorManager connector, params ModelBase[] models) { var ids = models.Select(x => x.Id).ToArray(); IDbTransaction trans = null; try { trans = connector.BeginTransaction(); action(); connector.CommitTransaction(trans); } catch (Exception e) { if (trans != null) { trans.Rollback(); } for (int i = 0; i < models.Length; i++) { models[i].Id = ids[i]; } LogHelper.Logger.Error(e); throw e; } }
public Context(string dbLocation) { SqlConnectorManager sqlCon = null; sqlCon = new SqlConnectorManager(); sqlCon.InitializeConnection(dbLocation); DbAccess = new Dictionary <Type, IDgvDbAccess> { { typeof(IPrinterBillsHistoryDE), new PrinterBillsHistoryDE(sqlCon) }, { typeof(IFamiliesDE), new FamiliesDE(sqlCon) }, { typeof(IMenuProductsDE), new MenuProductsDE(sqlCon) }, { typeof(IOrderItemsDE), new OrderItemsDE(sqlCon) }, { typeof(IOrderItemsHistoryDE), new OrderItemsHistoryDE(sqlCon) }, { typeof(IOrdersDE), new OrdersDE(sqlCon) }, { typeof(IOrdersHistoryDE), new OrdersHistoryDE(sqlCon) }, { typeof(IProductsDE), new ProductsDE(sqlCon) }, { typeof(ITablesDE), new TablesDE(sqlCon) }, { typeof(IUsersDE), new UsersDE(sqlCon) }, { typeof(ILanguagesDE), new LanguagesDE(sqlCon) }, { typeof(ITranslationsDE), new TranslationsDE(sqlCon) }, { typeof(IMenusDE), new MenusDE(sqlCon) } }; }
public PrinterBillsHistoryDE(SqlConnectorManager sqlConManager) : base(sqlConManager) { }
public OrdersHistoryDE(SqlConnectorManager sqlConManager) : base(sqlConManager) { }
public DataBase(SqlConnectorManager sqlConManager) { this.Connector = sqlConManager; }
public TranslationsDE(SqlConnectorManager sqlConManager) : base(sqlConManager) { }
public ProductsDE(SqlConnectorManager sqlConManager) : base(sqlConManager) { }
public MenusDE(SqlConnectorManager sqlConManager) : base(sqlConManager) { }
public TablesDE(SqlConnectorManager sqlConManager) : base(sqlConManager) { }
public UsersDE(SqlConnectorManager sqlConManager) : base(sqlConManager) { }
public LanguagesDE(SqlConnectorManager sqlConManager) : base(sqlConManager) { }
public FamiliesDE(SqlConnectorManager sqlConManager) : base(sqlConManager) { }
public OrderItemsDE(SqlConnectorManager sqlConManager) : base(sqlConManager) { }