public IUmbracoEntity GetByKey(Guid key, Guid objectTypeId) { bool isContent = objectTypeId == new Guid(Constants.ObjectTypes.Document); bool isMedia = objectTypeId == new Guid(Constants.ObjectTypes.Media); var sql = GetFullSqlForEntityType(key, isContent, isMedia, objectTypeId); if (isMedia) { //for now treat media differently //TODO: We should really use this methodology for Content/Members too!! since it includes properties and ALL of the dynamic db fields var entities = _work.Database.Fetch <dynamic, UmbracoPropertyDto, UmbracoEntity>( new UmbracoEntityRelator().Map, sql); return(entities.FirstOrDefault()); } else { var nodeDto = _work.Database.FirstOrDefault <dynamic>(sql); if (nodeDto == null) { return(null); } var factory = new UmbracoEntityFactory(); var entity = factory.BuildEntityFromDynamic(nodeDto); return(entity); } }
private IEnumerable <IUmbracoEntity> PerformGetAll(Guid objectTypeId, Action <Sql> filter = null) { bool isContent = objectTypeId == new Guid(Constants.ObjectTypes.Document); bool isMedia = objectTypeId == new Guid(Constants.ObjectTypes.Media); var sql = GetFullSqlForEntityType(isContent, isMedia, objectTypeId, filter); var factory = new UmbracoEntityFactory(); if (isMedia) { //for now treat media differently //TODO: We should really use this methodology for Content/Members too!! since it includes properties and ALL of the dynamic db fields var entities = _work.Database.Fetch <dynamic, UmbracoPropertyDto, UmbracoEntity>( new UmbracoEntityRelator().Map, sql); foreach (var entity in entities) { yield return(entity); } } else { var dtos = _work.Database.Fetch <dynamic>(sql); foreach (var entity in dtos.Select(dto => factory.BuildEntityFromDynamic(dto))) { yield return(entity); } } }
internal UmbracoEntity Map(dynamic a, UmbracoPropertyDto p) { // Terminating call. Since we can return null from this function // we need to be ready for PetaPoco to callback later with null // parameters if (a == null) { return(Current); } // Is this the same UmbracoEntity as the current one we're processing if (Current != null && Current.Key == a.uniqueID) { if (p != null && p.PropertyAlias.IsNullOrWhiteSpace() == false) { // Add this UmbracoProperty to the current additional data Current.AdditionalData[p.PropertyAlias] = new UmbracoEntity.EntityProperty { PropertyEditorAlias = p.PropertyEditorAlias, Value = p.NTextValue.IsNullOrWhiteSpace() ? p.NVarcharValue : p.NTextValue.ConvertToJsonIfPossible() }; } // Return null to indicate we're not done with this UmbracoEntity yet return(null); } // This is a different UmbracoEntity to the current one, or this is the // first time through and we don't have a Tab yet // Save the current UmbracoEntityDto var prev = Current; // Setup the new current UmbracoEntity Current = _factory.BuildEntityFromDynamic(a); if (p != null && p.PropertyAlias.IsNullOrWhiteSpace() == false) { //add the property/create the prop list if null Current.AdditionalData[p.PropertyAlias] = new UmbracoEntity.EntityProperty { PropertyEditorAlias = p.PropertyEditorAlias, Value = p.NTextValue.IsNullOrWhiteSpace() ? p.NVarcharValue : p.NTextValue.ConvertToJsonIfPossible() }; } // Return the now populated previous UmbracoEntity (or null if first time through) return(prev); }
public IUmbracoEntity GetByKey(Guid key) { var sql = GetBaseWhere(GetBase, false, false, key); var nodeDto = _work.Database.FirstOrDefault<dynamic>(sql); if (nodeDto == null) return null; var factory = new UmbracoEntityFactory(); var entity = factory.BuildEntityFromDynamic(nodeDto); return entity; }
public IUmbracoEntity GetByKey(Guid key, Guid objectTypeId) { bool isContent = objectTypeId == new Guid(Constants.ObjectTypes.Document); bool isMedia = objectTypeId == new Guid(Constants.ObjectTypes.Media); var sql = GetBaseWhere(GetBase, isContent, isMedia, objectTypeId, key).Append(GetGroupBy(isContent, isMedia)); var nodeDto = _work.Database.FirstOrDefault<dynamic>(sql); if (nodeDto == null) return null; var factory = new UmbracoEntityFactory(); var entity = factory.BuildEntityFromDynamic(nodeDto); return entity; }
public virtual IUmbracoEntity Get(int id) { var sql = GetBaseWhere(GetBase, false, false, id); var nodeDto = _work.Database.FirstOrDefault <dynamic>(sql); if (nodeDto == null) { return(null); } var factory = new UmbracoEntityFactory(); var entity = factory.BuildEntityFromDynamic(nodeDto); return(entity); }
public IUmbracoEntity GetByKey(Guid key) { var sql = GetBaseWhere(GetBase, false, false, key); var nodeDto = UnitOfWork.Database.FirstOrDefault <dynamic>(sql); if (nodeDto == null) { return(null); } var factory = new UmbracoEntityFactory(); var entity = factory.BuildEntityFromDynamic(nodeDto); return(entity); }
public virtual IEnumerable <IUmbracoEntity> GetByQuery(IQuery <IUmbracoEntity> query, Guid objectTypeId) { bool isContent = objectTypeId == new Guid(Constants.ObjectTypes.Document); bool isMedia = objectTypeId == new Guid(Constants.ObjectTypes.Media); var wheres = string.Concat(" AND ", string.Join(" AND ", ((Query <IUmbracoEntity>)query).WhereClauses())); var sqlClause = GetBaseWhere(GetBase, isContent, isMedia, wheres, objectTypeId); var translator = new SqlTranslator <IUmbracoEntity>(sqlClause, query); var sql = translator.Translate().Append(GetGroupBy(isContent, isMedia)); var factory = new UmbracoEntityFactory(); if (isMedia) { //treat media differently for now var dtos = _work.Database.Fetch <UmbracoEntityDto, UmbracoPropertyDto, UmbracoEntityDto>( new UmbracoEntityRelator().Map, sql); return(dtos.Select(factory.BuildEntity).Cast <IUmbracoEntity>().ToArray()); } else { //use dynamic so that we can get ALL properties from the SQL //we'll have to stitch stuff together manually but we can get our //additional data to put in the dictionary. var dtos = _work.Database.Fetch <dynamic>(sql); var entityProps = TypeHelper.GetPublicProperties(typeof(IUmbracoEntity)).Select(x => x.Name).ToArray(); var result = new List <IUmbracoEntity>(); foreach (var d in dtos) { //build the initial entity IUmbracoEntity entity = factory.BuildEntityFromDynamic(d); //convert the dynamic row to dictionary var asDictionary = (IDictionary <string, object>)d; //figure out what extra properties we have that are not on the IUmbracoEntity and add them to additional data foreach (var k in asDictionary.Keys .Select(x => new { orig = x, title = x.ConvertCase(StringAliasCaseType.PascalCase) }) .Where(x => entityProps.InvariantContains(x.title) == false)) { entity.AdditionalData[k.title] = asDictionary[k.orig]; } result.Add(entity); } return(result); } }
public IUmbracoEntity BuildFromDynamic() { return(_factory.BuildEntityFromDynamic(_entity)); }
public virtual IEnumerable<IUmbracoEntity> GetByQuery(IQuery<IUmbracoEntity> query, Guid objectTypeId) { bool isContent = objectTypeId == new Guid(Constants.ObjectTypes.Document); bool isMedia = objectTypeId == new Guid(Constants.ObjectTypes.Media); var wheres = string.Concat(" AND ", string.Join(" AND ", ((Query<IUmbracoEntity>)query).WhereClauses())); var sqlClause = GetBaseWhere(GetBase, isContent, isMedia, wheres, objectTypeId); var translator = new SqlTranslator<IUmbracoEntity>(sqlClause, query); var sql = translator.Translate().Append(GetGroupBy(isContent, isMedia)); var factory = new UmbracoEntityFactory(); if (isMedia) { //treat media differently for now var dtos = _work.Database.Fetch<UmbracoEntityDto, UmbracoPropertyDto, UmbracoEntityDto>( new UmbracoEntityRelator().Map, sql); return dtos.Select(factory.BuildEntity).Cast<IUmbracoEntity>().ToArray(); } else { //use dynamic so that we can get ALL properties from the SQL //we'll have to stitch stuff together manually but we can get our //additional data to put in the dictionary. var dtos = _work.Database.Fetch<dynamic>(sql); var entityProps = TypeHelper.GetPublicProperties(typeof (IUmbracoEntity)).Select(x => x.Name).ToArray(); var result = new List<IUmbracoEntity>(); foreach (var d in dtos) { //build the initial entity IUmbracoEntity entity = factory.BuildEntityFromDynamic(d); //convert the dynamic row to dictionary var asDictionary = (IDictionary<string, object>) d; //figure out what extra properties we have that are not on the IUmbracoEntity and add them to additional data foreach (var k in asDictionary.Keys .Select(x => new {orig = x, title = x.ConvertCase(StringAliasCaseType.PascalCase)}) .Where(x => entityProps.InvariantContains(x.title) == false)) { entity.AdditionalData[k.title] = asDictionary[k.orig]; } result.Add(entity); } return result; } }
public virtual IEnumerable<IUmbracoEntity> GetAll(Guid objectTypeId, params int[] ids) { if (ids.Any()) { foreach (var id in ids) { yield return Get(id, objectTypeId); } } else { bool isContent = objectTypeId == new Guid(Constants.ObjectTypes.Document); bool isMedia = objectTypeId == new Guid(Constants.ObjectTypes.Media); var sql = GetBaseWhere(GetBase, isContent, isMedia, string.Empty, objectTypeId).Append(GetGroupBy(isContent, isMedia)); var factory = new UmbracoEntityFactory(); if (isMedia) { //for now treat media differently //TODO: We should really use this methodology for Content/Members too!! since it includes properties and ALL of the dynamic db fields var entities = _work.Database.Fetch<dynamic, UmbracoPropertyDto, UmbracoEntity>( new UmbracoEntityRelator().Map, sql); foreach (var entity in entities) { yield return entity; } } else { var dtos = _work.Database.Fetch<dynamic>(sql); foreach (var entity in dtos.Select(dto => factory.BuildEntityFromDynamic(dto))) { yield return entity; } } } }