private (IEnumerable <TableName> selectedTables, List <TableName> tableNames) SelectedTables(ISqlConnections sqlConnections, string connectionKey) { ISchemaProvider schemaProvider; List <TableName> tableNames; using (var connection = sqlConnections.NewByKey(connectionKey)) { schemaProvider = SchemaHelper.GetSchemaProvider(connection.GetDialect().ServerType); tableNames = schemaProvider.GetTableNames(connection).ToList(); } var tables = tableNames.Select(x => x.Tablename).ToList(); var selectedTableNames = AnsiConsole.Prompt( new MultiSelectionPrompt <string>() .Title("[steelblue1]Select tables for code generation (single/multiple)[/]") .PageSize(10) .MoreChoicesText("[grey](Move up and down to reveal more tables)[/]") .InstructionsText( "[grey](Press [blue]<space>[/] to select/unselect, " + "[green]<enter>[/] to accept)[/]") .AddChoices(tables)); var selectedTables = tableNames.Where(s => selectedTableNames.Contains(s.Tablename)); return(selectedTables, tableNames); }
/// <summary> /// Creates a new connection for specified class, determining /// the connection key by checking its [ConnectionKey] attribute. /// </summary> /// <typeparam name="TClass">The type of the class.</typeparam> /// <param name="factory">Connection factory</param> /// <returns>A new connection</returns> /// <exception cref="ArgumentOutOfRangeException">Type has no ConnectionKey attribute!</exception> public static IDbConnection NewFor <TClass>(this ISqlConnections factory) { var attr = typeof(TClass).GetCustomAttribute <ConnectionKeyAttribute>(); if (attr == null) { throw new ArgumentOutOfRangeException("Type has no ConnectionKey attribute!", typeof(TClass).FullName); } return(factory.NewByKey(attr.Value)); }
public ActionResult Activate(string t, [FromServices] ISqlConnections sqlConnections) { using (var connection = sqlConnections.NewByKey("Default")) using (var uow = new UnitOfWork(connection)) { int userId; try { var bytes = HttpContext.RequestServices .GetDataProtector("Activate").Unprotect(Convert.FromBase64String(t)); using (var ms = new MemoryStream(bytes)) using (var br = new BinaryReader(ms)) { var dt = DateTime.FromBinary(br.ReadInt64()); if (dt < DateTime.UtcNow) { return(Error(Texts.Validation.InvalidActivateToken.ToString(Localizer))); } userId = br.ReadInt32(); } } catch (Exception) { return(Error(Texts.Validation.InvalidActivateToken.ToString(Localizer))); } var user = uow.Connection.TryById <UserRow>(userId); if (user == null || user.IsActive != 0) { return(Error(Texts.Validation.InvalidActivateToken.ToString(Localizer))); } uow.Connection.UpdateById(new UserRow { UserId = user.UserId.Value, IsActive = 1 }); Cache.InvalidateOnCommit(uow, UserRow.Fields); uow.Commit(); return(new RedirectResult("~/Account/Login?activated=" + Uri.EscapeDataString(user.Email))); } }
protected override IEnumerable GetItems() { var list = new List <TRow>(); var loader = new TRow(); var query = new SqlQuery() .From(loader); PrepareQuery(query); ApplyOrder(query); using (var connection = connections.NewByKey(loader.Fields.ConnectionKey)) { query.ForEach(connection, delegate() { list.Add(loader.Clone()); }); } return(list); }