Esempio n. 1
0
        public static bool Save <T>(IEntity entity, bool bypassConflicts) where T : IEntity, new()
        {
            bool ret = true;

            try
            {
                IEntity copy = new T();
                copy.ConnectionString = entity.ConnectionString;
                entity.__Elements.Where(ebd => ebd.UseForMatching).ToList().ForEach(ebd => copy.__Elements.Find(c => c.Name.Equals(ebd.Name)).Data = ebd.Data);
                //copy.Elements[0].Data = entity.Elements[0].Data;

                CRUDActions.Retrieve <T>(copy);

                if (copy.Notifications.Count == 0)
                {
                    if (entity.__Memento.Count == 0)
                    {
                        long fieldsToSave = entity.Compare(copy);
                        CRUDActions.Update <T>(entity, fieldsToSave);
                    }
                    else
                    {
                        long fieldsToSave = entity.Compare();
                        if (fieldsToSave == 0)
                        {
                            return(false);
                        }

                        Utility.SetWarnings(entity, copy);

                        if (!bypassConflicts)
                        {
                            Utility.SetConflicts(entity, copy);
                            ret = entity.CRUDConflict.Fields.Count == 0;
                        }

                        if (ret)
                        {
                            entity.__Elements.ForEach(e => UpdateField(e, copy, fieldsToSave));
                            CRUDActions.Update <T>(copy, fieldsToSave);

                            entity.__Elements.Where(e => !e.IsCollection).ToList().ForEach(e => SaveCollection(e, copy));
                        }
                    }
                }
                else
                {
                    //copy.Notifications.ForEach(n => getNLogger().Info(n.Message));
                    CRUDActions.Create <T>(entity);
                }
            }
            catch (System.Exception ex)
            {
                entity.Exceptions.Add(new EntityException(1, ex.Message, ex));
            }
            return(ret);
        }
        public static Collection <Enumeration> GetCollection(List <CriteriaParameter> Parameters, string ConnectionString, string CollectionName = "Enumerations")
        {
            Collection <Enumeration> collection = new Collection <Enumeration>();

            collection.CollectionName   = CollectionName;
            collection.ConnectionString = ConnectionString;
            collection.Parameters       = Parameters;
            CRUDActions.Retrieve <Enumeration>(collection);
            return(collection);
        }
Esempio n. 3
0
        public static List <FieldPresentation> Summary(string ConnectionString = null)
        {
            Collection <FieldPresentation> collection = new Collection <FieldPresentation>();

            if (!String.IsNullOrWhiteSpace(ConnectionString))
            {
                collection.ConnectionString = ConnectionString;
            }
            CRUDActions.Retrieve <FieldPresentation>(collection);

            return(collection.ToList());
        }
Esempio n. 4
0
        public static void Load <T>(IEntity entity) where T : IEntity
        {
            entity.Populated = true;
            CRUDActions.Retrieve <T>(entity);

            for (int i = 0; i < entity.__Elements.Count(); i++)
            {
                entity.__Memento.Add(new DataProxy()
                {
                    ElementId = i, Data = entity.__Elements[i].Data
                });
            }
        }
Esempio n. 5
0
        public static void Load <T>(IEntity entity) where T : IEntity
        {
            //getNLogger().Info(String.Format("Calling CRUDActions.Retrieve<T>({0})", entity.EntityName));
            entity.Populated = true;
            CRUDActions.Retrieve <T>(entity);

            for (int i = 0; i < entity.__Elements.Count(); i++)
            {
                entity.__Memento.Add(new DataProxy()
                {
                    ElementId = i, Data = entity.__Elements[i].Data
                });
            }
        }
Esempio n. 6
0
        public static bool Update <T>(IEntity entity, bool bypassConflicts = false) where T : IEntity, new()
        {
            bool ret = true;

            try
            {
                IEntity copy = new T();
                copy.ConnectionString   = entity.ConnectionString;
                copy.__Elements[0].Data = entity.__Elements[0].Data;

                //getNLogger().Info(String.Format("Calling CRUDActions.Retrieve<T>({0}) for copy", entity.EntityName));
                CRUDActions.Retrieve <T>(copy);

                if (copy.Notifications.Count == 0)
                {
                    long fieldsToSave = entity.Compare();
                    //getNLogger().Info(String.Format("fieldsToSave {0}", fieldsToSave));
                    if (fieldsToSave == 0)
                    {
                        return(false);
                    }

                    Utility.SetWarnings(entity, copy);

                    if (!bypassConflicts)
                    {
                        Utility.SetConflicts(entity, copy);
                        ret = entity.CRUDConflict.Fields.Count == 0;
                    }

                    if (ret)
                    {
                        entity.__Elements.ForEach(e => UpdateField(e, copy, fieldsToSave));
                        //getNLogger().Info(String.Format("Calling CRUDActions.Update({0}, {1})", entity.EntityName, fieldsToSave.ToString()));
                        CRUDActions.Update <T>(copy, fieldsToSave);
                    }
                }
                else
                {
                    throw new System.Exception("CRUDActions.Retrieve failed during Update");
                }
            }
            catch (System.Exception ex)
            {
                entity.Exceptions.Add(new EntityException(1, ex.Message, ex));
                ret = false;
            }
            return(ret);
        }
Esempio n. 7
0
 public void Load()
 {
     CRUDActions.Retrieve <Field>(this);
 }
Esempio n. 8
0
 public void Load()
 {
     CRUDActions.Retrieve <Attribute>(this);
 }
Esempio n. 9
0
 public static void Load <T>(Collection <T> entities) where T : IEntity
 {
     //getNLogger().Info(String.Format("Calling CRUDActions.Retrieve<T>({0})", entities.GetType()));
     CRUDActions.Retrieve <T>(entities);
 }
Esempio n. 10
0
 public void Load()
 {
     CRUDActions.Retrieve <Argument>(this);
 }
 public void Load()
 {
     CRUDActions.Retrieve <FieldPresentation>(this);
 }
Esempio n. 12
0
 public static void Load <T>(Collection <T> entities) where T : IEntity
 {
     CRUDActions.Retrieve <T>(entities);
 }
Esempio n. 13
0
        public static bool Merge <T>(IEntity entity, bool bypassConflicts = false) where T : IEntity, new()
        {
            bool ret = true;

            try
            {
                bool isNew = true;
                foreach (ElementBaseData ebd in entity.__Elements.Where(ebd => ebd.SqlDbIsPrimaryKey).ToList())
                {
                    if ((ebd.TypeName.Equals("int") && int.Parse(ebd.Data.ToString()) != 0) || (ebd.TypeName.Equals("Guid") && !Guid.Parse(ebd.Data.ToString()).Equals(Guid.Empty)))
                    {
                        isNew = false;
                        break;
                    }
                }

                if (isNew)
                {
                    CRUDActions.Create <T>(entity);
                    return(true);
                }

                IEntity copy = new T();
                copy.ConnectionString = entity.ConnectionString;
                entity.__Elements.Where(ebd => ebd.SqlDbIsPrimaryKey).ToList().ForEach(ebd => copy.__Elements.Find(c => c.Name.Equals(ebd.Name)).Data = ebd.Data);

                CRUDActions.Retrieve <T>(copy);

                if (copy.Notifications.Count == 0)
                {
                    if (entity.__Memento.Count == 0)
                    {
                        long fieldsToSave = entity.Compare(copy);
                        CRUDActions.Merge <T>(entity, fieldsToSave);
                    }
                    else
                    {
                        long fieldsToSave = entity.Compare();
                        if (fieldsToSave == 0)
                        {
                            return(false);
                        }

                        SetWarnings(entity, copy);

                        if (!bypassConflicts)
                        {
                            SetConflicts(entity, copy);
                            ret = entity.CRUDConflict.Fields.Count == 0;
                        }

                        if (ret)
                        {
                            entity.__Elements.ForEach(e => UpdateField(e, copy, fieldsToSave));
                            CRUDActions.Merge <T>(copy, fieldsToSave);

                            entity.__Elements.Where(e => !e.IsCollection).ToList().ForEach(e => SaveCollection(e, copy));
                        }
                    }
                }
                else
                {
                    CRUDActions.Create <T>(entity);
                }
            }
            catch (System.Exception ex)
            {
                entity.Exceptions.Add(new EntityException(1, ex.Message, ex));
            }
            return(ret);
        }
Esempio n. 14
0
 public void Load()
 {
     CRUDActions.Retrieve <Interface>(this);
 }
Esempio n. 15
0
 public void Load()
 {
     CRUDActions.Retrieve <Entity>(this);
 }
Esempio n. 16
0
 public void Load()
 {
     CRUDActions.Retrieve <Action>(this);
 }
Esempio n. 17
0
 public void Load()
 {
     CRUDActions.Retrieve <DataType>(this);
 }
Esempio n. 18
0
 public void Load()
 {
     CRUDActions.Retrieve <Method>(this);
 }