protected string GetQuotedValue(object?val) { if (val == null) { return("NULL"); } var type = val.GetType(); switch (Type.GetTypeCode(type)) { case TypeCode.Boolean: return(((bool)val) ? "1" : "0"); case TypeCode.Single: case TypeCode.Double: case TypeCode.Decimal: case TypeCode.SByte: case TypeCode.Int16: case TypeCode.Int32: case TypeCode.Int64: case TypeCode.Byte: case TypeCode.UInt16: case TypeCode.UInt32: case TypeCode.UInt64: return(val.ToString() !); case TypeCode.DateTime: return(SqlSyntax.GetQuotedValue(SqlSyntax.FormatDateTime((DateTime)val))); default: return(SqlSyntax.GetQuotedValue(val.ToString() !)); } }
public IEnumerable <IUserGroup> GetGroupsAssignedToSection(string sectionAlias) { //Here we're building up a query that looks like this, a sub query is required because the resulting structure // needs to still contain all of the section rows per user group. //SELECT * //FROM [umbracoUserGroup] //LEFT JOIN [umbracoUserGroup2App] //ON [umbracoUserGroup].[id] = [umbracoUserGroup2App].[user] //WHERE umbracoUserGroup.id IN (SELECT umbracoUserGroup.id // FROM [umbracoUserGroup] // LEFT JOIN [umbracoUserGroup2App] // ON [umbracoUserGroup].[id] = [umbracoUserGroup2App].[user] // WHERE umbracoUserGroup2App.app = 'content') var sql = GetBaseQuery(false); var innerSql = GetBaseQuery("umbracoUserGroup.id"); innerSql.Where("umbracoUserGroup2App.app = " + SqlSyntax.GetQuotedValue(sectionAlias)); sql.Where(string.Format("umbracoUserGroup.id IN ({0})", innerSql.SQL)); AppendGroupBy(sql); //must be included for relator to work sql.OrderBy <UserGroupDto>(x => x.Id, SqlSyntax); return(ConvertFromDtos(Database.Fetch <UserGroupDto, UserGroup2AppDto, UserGroupDto>(new UserGroupSectionRelator().Map, sql))); }
public IEnumerable <IUserGroup> GetGroupsAssignedToSection(string sectionAlias) { // Here we're building up a query that looks like this, a sub query is required because the resulting structure // needs to still contain all of the section rows per user group. // SELECT * // FROM [umbracoUserGroup] // LEFT JOIN [umbracoUserGroup2App] // ON [umbracoUserGroup].[id] = [umbracoUserGroup2App].[user] // WHERE umbracoUserGroup.id IN (SELECT umbracoUserGroup.id // FROM [umbracoUserGroup] // LEFT JOIN [umbracoUserGroup2App] // ON [umbracoUserGroup].[id] = [umbracoUserGroup2App].[user] // WHERE umbracoUserGroup2App.app = 'content') Sql <ISqlContext> sql = GetBaseQuery(QueryType.Many); Sql <ISqlContext> innerSql = GetBaseQuery(QueryType.Ids); innerSql.Where("umbracoUserGroup2App.app = " + SqlSyntax.GetQuotedValue(sectionAlias)); sql.Where($"umbracoUserGroup.id IN ({innerSql.SQL})"); AppendGroupBy(sql); return(Database.Fetch <UserGroupDto>(sql).Select(x => UserGroupFactory.BuildEntity(_shortStringHelper, x))); }