public static int ExecuteNonQuery(ConnectionConstant connectionConstant, string sql, params SqlParam[] sqlParameters) { try { var connectionString = ConnectionStringManager.GetConnectionString(connectionConstant); int result; using (var sqlConnection = new SqlConnection(connectionString)) { using (var sqlCommand = new SqlCommand()) { sqlCommand.Connection = sqlConnection; sqlCommand.CommandText = sql; foreach (var parameter in sqlParameters) { sqlCommand.Parameters.Add(parameter.ParameterName, parameter.SqlDbType).Value = (parameter.Value).ToString() == "" ? DBNull.Value : parameter.Value; } sqlConnection.Open(); result = sqlCommand.ExecuteNonQuery(); } } return(result); } catch (SqlException sqlException) { throw; } catch (Exception ex) { throw; } }
public static DataTable ExecuteReader(ConnectionConstant connectionConstant, string sql, params SqlParam[] sqlParameters) { try { var connectionString = ConnectionStringManager.GetConnectionString(connectionConstant); var result = new DataTable(); using (var sqlConnection = new SqlConnection(connectionString)) { using (var sqlCommand = new SqlCommand()) { sqlCommand.Connection = sqlConnection; sqlCommand.CommandText = sql; foreach (var parameter in sqlParameters) { sqlCommand.Parameters.Add(parameter.ParameterName, parameter.SqlDbType).Value = (parameter.Value).ToString() == "" ? DBNull.Value : parameter.Value; } sqlConnection.Open(); using (var dataReader = sqlCommand.ExecuteReader(CommandBehavior.CloseConnection)) { result.Load(dataReader); } } } return(result); } catch (SqlException sqlException) { throw; } catch (Exception ex) { throw; } }
public CreateUpdateDeleteAnEventSteps() { var context = new EfContext(ConnectionStringManager.GetConnectionString()); _eventRepository = new EfRepository <Event>(context); _layoutRepository = new EfRepository <Layout>(context); }
public BuyTicketsSteps() { var context = new EfContext(ConnectionStringManager.GetConnectionString()); _eventRepository = new EfRepository <Event>(context); _layoutRepository = new EfRepository <Layout>(context); _eventAreaRepository = new EfRepository <EventArea>(context); }
public MyContext CreateDbContext(string[] args) { var con = new ConnectionStringManager(); var connectionString = con.GetConnectionString(); var optionsBuilder = new DbContextOptionsBuilder <MyContext> (); optionsBuilder.UseSqlServer(connectionString); return(new MyContext(optionsBuilder.Options)); }
protected void Application_Start(object sender, EventArgs e) { // WCF integration docs are at: // https://autofac.readthedocs.io/en/latest/integration/wcf.html var builder = new ContainerBuilder(); // Register your service implementations. builder.RegisterType <WcfPurchaseFlowService>(); builder.RegisterType <WcfCartManageService>(); builder.RegisterType <WcfEventManageService>(); builder.RegisterType <WcfVenueManageService>(); builder.RegisterType <WcfLayoutManageService>(); builder.RegisterType <WcfAreaManageService>(); builder.RegisterType <WcfSeatManageService>(); // Register your dependencies. builder.RegisterType <EfContext>().As <DbContext>() .WithParameter("connectionString", ConnectionStringManager.GetConnectionString()) .InstancePerLifetimeScope(); builder.RegisterType <Service <Venue, VenueDto> >().As <IService <VenueDto> >(); builder.RegisterType <Service <Event, EventDto> >().As <IService <EventDto> >(); builder.RegisterType <Service <Layout, LayoutDto> >().As <IService <LayoutDto> >(); builder.RegisterType <Service <Area, AreaDto> >().As <IService <AreaDto> >(); builder.RegisterType <Service <Seat, SeatDto> >().As <IService <SeatDto> >(); builder.RegisterType <Service <EventArea, EventAreaDto> >().As <IService <EventAreaDto> >(); builder.RegisterType <Service <EventSeat, EventSeatDto> >().As <IService <EventSeatDto> >(); builder.RegisterType <Service <PurchaseHistory, PurchaseHistoryDto> >().As <IService <PurchaseHistoryDto> >(); builder.RegisterType <PurchaseFlowService>().As <IPurchaseFlowService>(); builder.RegisterType <CartManageService>().As <ICartManageService>(); builder.RegisterType <EventManageService>().As <IEventManageService>(); builder.RegisterType <VenueManageService>().As <IVenueManageService>(); builder.RegisterType <LayoutManageService>().As <ILayoutManageService>(); builder.RegisterType <AreaManageService>().As <IAreaManageService>(); builder.RegisterType <SeatManageService>().As <ISeatManageService>(); builder.RegisterType <EfRepository <Venue> >().As <RepositoryBase <Venue> >(); builder.RegisterType <EfRepository <Event> >().As <RepositoryBase <Event> >(); builder.RegisterType <EfRepository <Layout> >().As <RepositoryBase <Layout> >(); builder.RegisterType <EfRepository <Area> >().As <RepositoryBase <Area> >(); builder.RegisterType <EfRepository <Seat> >().As <RepositoryBase <Seat> >(); builder.RegisterType <EfRepository <EventArea> >().As <RepositoryBase <EventArea> >(); builder.RegisterType <EfRepository <EventSeat> >().As <RepositoryBase <EventSeat> >(); builder.RegisterType <EfRepository <PurchaseHistory> >().As <RepositoryBase <PurchaseHistory> >(); // Set the dependency resolver. This works for both regular // WCF services and REST-enabled services. var container = builder.Build(); AutofacHostFactory.Container = container; }
public static void AppInitialize() { // put connection to your database here GlobalConfiguration.Configuration.UseSqlServerStorage(ConnectionStringManager.GetConnectionString()); new Thread(() => { using (new BackgroundJobServer()) { Console.WriteLine("Hangfire Server started. Press ENTER to exit..."); BackgroundJob.Enqueue(() => Console.WriteLine("New job was added")); Console.ReadLine(); } }).Start(); }
public DbTeste() { var con = new ConnectionStringManager(); var connectionString = con.GetConnectionString(); var serviceCollection = new ServiceCollection(); serviceCollection.AddDbContext <MyContext>(c => c.UseSqlServer($"Data Source=DESKTOP-CVF6VA6\\SQLEXPRESS;Initial Catalog={dataBaseNome};Persist Security Info=True;User ID=sa;Password=Dsm22"), ServiceLifetime.Transient ); serviceProvider = serviceCollection.BuildServiceProvider(); using (var context = serviceProvider.GetService <MyContext>()) { context.Database.EnsureCreated(); } }
public ChargesController() { // New 2019-08-20 _connectionString = @"Data Source=DELL-5490\SQLEXPRESS;Initial Catalog=Fitness;Integrated Security=True"; //_connectionString = ConnectionStringManager.GetConnectionString("Fitness"); if (String.IsNullOrEmpty(_connectionString)) { ConnectionStringManager.AddConnectionString("Fitness", @"Data Source=DELL-5490\SQLEXPRESS;Initial Catalog=Fitness;Integrated Security=True"); _connectionString = ConnectionStringManager.GetConnectionString("Fitness"); } IKernel ninjectKernel = new StandardKernel(); ninjectKernel.Bind <IChargeServise>().To <ChargeServise>().WithConstructorArgument("stringConnection", _connectionString); _chargeServise = ninjectKernel.Get <IChargeServise>(); // Old 2019-08-19 //_chargeServise = new ChargeServise(Properties.Settings.Default.DataBase); }
public void GetLogsFromManager() { _stopwatch.Start(); SQLiteCRUD sql = new(ConnectionStringManager.GetConnectionString(ConnectionStringManager.DataBases.PCControllerDB)); ProcMonitorModel procData = new(); int numLogs = _parser.GetLogs(NumberOfNetMsgToFetch); _log.Info("Getting Data Logs from {sql} number: {numOfMsgs}", sql, numLogs); IList <NetworkMessageModel> rows = sql.GetSomeNetData(numLogs); NetGridRows = rows; _stopwatch.Stop(); string timeToFetchFromDb = $" DB query time: {_stopwatch.ElapsedMilliseconds} ms"; DataBaseQueryTime = timeToFetchFromDb; RaisePropertyChanged(() => NetGridRows); RaisePropertyChanged(() => DataBaseQueryTime); }
public static string ExecuteScalar(ConnectionConstant connectionConstant, string sql, params SqlParam[] sqlParameters) { try { var connectionString = ConnectionStringManager.GetConnectionString(connectionConstant); object result = null; using (var sqlConnection = new SqlConnection(connectionString)) { using (var sqlCommand = new SqlCommand()) { sqlCommand.Connection = sqlConnection; sqlCommand.CommandText = sql; foreach (var parameter in sqlParameters) { sqlCommand.Parameters.Add(parameter.ParameterName, parameter.SqlDbType).Value = (parameter.Value).ToString() == "" ? DBNull.Value : parameter.Value; } sqlConnection.Open(); result = sqlCommand.ExecuteScalar(); } } if (result != null) { return(result.ToString()); } else { return(string.Empty); } } catch (SqlException sqlException) { throw; } catch (Exception ex) { throw; } }
public void ReturnsNullByDefault() { var connectionStringManager = new ConnectionStringManager(); Assert.AreEqual(null, connectionStringManager.GetConnectionString(typeof(TestDbContextContainer), null, null)); }
/// <summary> /// /// </summary> /// <param name="dbName"></param> public DBConnectionContext(DatabaseName dbName) : base(ConnectionStringManager.GetConnectionString(dbName)) { this.InitDLLs(); }