Ejemplo n.º 1
0
        public static bool Populate <T>(this IMvxDBRecord record, ref T entityToPopulate) where T : IMvxDBEntity
        {
            var map = MvxDBMapping.Get(typeof(T));

            if (map == null || map.PropertiesInfos == null || map.PropertiesInfos.Count == 0)
            {
                return(false);
            }
            var result = false;
            //Property Key
            var keyValue = map.PropertyInfoKey.GetValue(entityToPopulate) as string;

            if (keyValue != record.Id)
            {
                map.PropertyInfoKey.SetValue(entityToPopulate, record.Id);
                result = true;
            }
            //Others
            foreach (var fieldName in record.FieldNames)
            {
                var property = map.PropertiesInfos.FirstOrDefault(p => p.Name == fieldName);
                if (property != null)
                {
                    var oldValue = property.GetValue(entityToPopulate);
                    var value    = record[fieldName];
                    if (oldValue != value)
                    {
                        property.SetValue(entityToPopulate, value.ConvertValue(property.PropertyType));
                        result = true;
                    }
                }
            }
            return(result);
        }
Ejemplo n.º 2
0
        public static void UpdateFrom <T>(this IMvxDBRecord record, T sourceEntity) where T : IMvxDBEntity
        {
            if (sourceEntity == null)
            {
                return;
            }
            var map = MvxDBMapping.Get(sourceEntity.GetType());

            if (map == null || map.PropertiesInfos == null || map.PropertiesInfos.Count == 0)
            {
                return;
            }
            foreach (var property in map.PropertiesInfos)
            {
                var value = property.GetValue(sourceEntity);
                if (value == null)
                {
                    continue;
                }
                if (record[property.Name] != value)
                {
                    record[property.Name] = value;
                }
            }
        }
Ejemplo n.º 3
0
 public void Delete(IMvxDBRecord record, bool autoSync = true)
 {
     record.DeleteRecord();
     if (autoSync)
     {
         Store.Sync();
     }
 }
Ejemplo n.º 4
0
 public DrbxReceivedMessage(object sender, IMvxDBRecord record)
     : base(sender)
 {
     Record = record;
 }