Exemplo n.º 1
0
 private void ReadFromInstance(M m)
 {
     foreach (var property in Definitions.Properties.Where(x => !x.IsLink && !x.IsId))
     {
         Backer.SetValue(property.PropertyName, property.GetValue(m));
     }
 }
Exemplo n.º 2
0
        internal void AddRelation(IModl to)
        {
            foreach (LinkProperty property in Definitions.Properties.Where(x => x.IsLink && to.GetType() == (x as LinkProperty).LinkedModlType))
            {
                Backer.GetRelation(property.PropertyName).Add(to.Modl.Id);
            }

            WriteRelationsToAllInstances();
        }
Exemplo n.º 3
0
 private void WriteToInstance(M m, string propertyName = null)
 {
     foreach (var property in Definitions.Properties.Where(x => !x.IsLink && !x.IsId))
     {
         if (propertyName == null || property.PropertyName == propertyName)
         {
             property.SetValue(m, Backer.GetValue <object>(property.PropertyName));
         }
     }
 }
Exemplo n.º 4
0
        internal bool Save()
        {
            if (Backer.IsDeleted)
            {
                throw new NotFoundException(string.Format("Trying to save a deleted object. Class: {0}, Id: {1}", Backer.ModlType, Id));
            }

            //if (includeRelations)
            //{
            //    foreach (var property in Definitions.Properties.Where(x => x.IsLink))
            //    {
            //        typeof(Backer)
            //            .GetMethod("SaveRelation", BindingFlags.Instance | BindingFlags.NonPublic)
            //            .MakeGenericMethod(property.PropertyType)
            //            .Invoke(this, new object[] { property });
            //    }
            //}

            if (!Backer.IsNew && !Backer.IsModified())
            {
                return(false);
            }

            var settings = Settings.Get(Backer.ModlType);

            if (!Id.IsSet && !Id.IsInternal && !Id.IsAutomatic && !settings.Endpoint.CanGenerateIds)
            {
                throw new InvalidIdException($"Id not set. Class: {Backer.ModlType}");
            }

            Materializer.Write(Definitions.GetStorage(Id, Backer), settings);

            Backer.IsNew = false;
            Backer.ResetValuesToUnmodified();
            WriteToAllInstances();

            return(true);
        }