/// <summary> /// Charge dans un objet le bean à partir de sa clef primaire. /// </summary> /// <param name="destination">Objet à charger.</param> /// <param name="primaryKey">Valeur de la clef primaire.</param> public override void Load(T destination, object primaryKey) { if (primaryKey == null) { throw new ArgumentNullException("primaryKey"); } FilterCriteria criteria = new FilterCriteria(); criteria.AddCriteria(_pkName, Expression.Equals, primaryKey); criteria.AddCriteria(_propertyName, Expression.Equals, true); T newObject = GetByCriteria(criteria); BeanFactory <T> factory = new BeanFactory <T>(); factory.CloneBean(newObject, destination); }
/// <summary> /// Crée une nouvelle entrée pour le type. /// </summary> /// <param name="referenceList">Liste de référence.</param> /// <param name="resourceList">Liste des resources disponible.</param> void IReferenceEntry.Initialize(ICollection referenceList, ICollection <ReferenceResource> resourceList) { BeanDefinition definition = BeanDescriptor.GetDefinition(typeof(T)); BeanPropertyDescriptor primaryKey = definition.PrimaryKey; if (primaryKey == null) { throw new NotSupportedException("Reference type " + typeof(T).FullName + " doesn't have a primary key defined. Use the ColumnAttribute to set the primary key property."); } BeanPropertyDescriptor propertyIsActif = null; if (definition.Properties.Contains(PropertyIsActif)) { propertyIsActif = definition.Properties[PropertyIsActif]; } ICollection <T> initialList = (ICollection <T>)referenceList; ICollection <T> activeList = (propertyIsActif == null) ? initialList : new List <T>(); foreach (T reference in initialList) { _resourceMap.Add(DefaultLocale + primaryKey.GetValue(reference), reference); if (propertyIsActif != null) { bool?isActif = (bool?)propertyIsActif.GetValue(reference); if (isActif.HasValue && isActif.Value) { activeList.Add(reference); } } } _localizedList.Add(DefaultLocale, activeList); if (resourceList == null) { return; } BeanFactory <T> factory = new BeanFactory <T>(); foreach (ReferenceResource resource in resourceList) { T reference; string locale = resource.Locale.Trim(); if (!_localizedList.ContainsKey(locale)) { // Construction des entrées pour la locale. List <T> list = new List <T>(); foreach (T initialReference in initialList) { reference = factory.CloneBean(initialReference); _resourceMap.Add(locale + primaryKey.GetValue(reference), reference); if (propertyIsActif != null) { bool?isActif = (bool?)propertyIsActif.GetValue(reference); if (isActif.HasValue && isActif.Value) { list.Add(reference); } } else { list.Add(reference); } } _localizedList.Add(locale, list); } reference = _resourceMap[locale + resource.Id]; definition.Properties[resource.PropertyName].SetValue(reference, resource.Label); } }