Beispiel #1
0
        public static bool Upsert <T, TE>(T modelObject, bool forceUpdate          = false,
                                          EditObjectFactoryCreator <T, TE> creator = null, bool refetch = false)
            where T : ModelEditBase, new()
            where TE : EntityBase, new()
        {
            var objectFactory = ObjectFactoryCreator.Edit(creator);

            objectFactory.ModelObject = modelObject;

            if (forceUpdate)
            {
                objectFactory.Get(modelObject.IdValue);
                if (objectFactory.DbEntity == null)
                {
                    return(false);
                }

                objectFactory.UpdatePreparation();
                objectFactory.Update();
            }
            else
            {
                objectFactory.InsertPreparation();
                objectFactory.Insert();
            }
            if (refetch)
            {
                objectFactory.Fetch();
            }
            return(true);
        }
Beispiel #2
0
        public static T NewModelObject <T, TE>(T modelObject, EditObjectFactoryCreator <T, TE> creator = null)
            where T : ModelBase, new()
            where TE : EntityBase, new()
        {
            var objectFactory = ObjectFactoryCreator.Edit(creator);

            objectFactory.ModelObject = modelObject;
            objectFactory.NewModelObject();
            return(objectFactory.ModelObject);
        }
Beispiel #3
0
        public static bool Delete <T, TE>(object id, EditObjectFactoryCreator <T, TE> creator = null)
            where T : ModelEditBase, new()
            where TE : EntityBase, new()
        {
            var objectFactory = ObjectFactoryCreator.Edit(creator);

            objectFactory.Get(id);
            if (objectFactory.DbEntity == null)
            {
                return(false);
            }
            objectFactory.Delete();
            return(true);
        }
Beispiel #4
0
 public static EditObjectFactory <T, TE> Edit <T, TE>(EditObjectFactoryCreator <T, TE> creator)
     where T : ModelBase, new()
     where TE : EntityBase, new()
 {
     return(creator == null ? new EditObjectFactory <T, TE>() : creator());
 }
Beispiel #5
0
        public static TE UpdateChild <T, TE, TKey>(T modelObject, ICollection <TE> collection, EditObjectFactoryCreator <T, TE> creator = null)
            where T : ModelEditBase, new()
            where TE : Entity <TKey>, new()
        {
            var dbEntity = GetDbEntity <T, TE, TKey>(modelObject, collection);

            if (dbEntity == null)
            {
                return(null);
            }

            if (modelObject.IsDelete)
            {
                dbEntity.ObjectState = ObjectState.Deleted;
                collection.Remove(dbEntity);
                return(dbEntity);
            }

            var objectFactory = ObjectFactoryCreator.Edit(creator);

            objectFactory.ModelObject = modelObject;
            objectFactory.DbEntity    = dbEntity;
            objectFactory.UpdatePreparation();
            if (modelObject.IsNew)
            {
                collection.Add(dbEntity);
            }
            return(dbEntity);
        }
Beispiel #6
0
 public static T GetEdit <T, TE>(object id, EditObjectFactoryCreator <T, TE> creator = null)
     where T : ModelBase, new()
     where TE : EntityBase, new()
 {
     return(GetAndFetch(id, ObjectFactoryCreator.Edit(creator)));
 }