Exemplo n.º 1
0
        void OnCreate(TEntity entity)
        {
            var repository = DependencyResolver.Resolve <IRepository <TJoin> >();

            var key   = KeyFunc(entity);
            var items = JoinFunc(entity);
            int sort  = 0;

            foreach (var item in items)
            {
                ForeignKeyAction(item, key);
                if (JoinSortAction != null)
                {
                    JoinSortAction(item, sort);
                }

                var itemKey = JoinKeyFunc(item);
                if (CascadeImpl.IsDefault(itemKey))
                {
                    repository.Create(item);
                }
                else
                {
                    repository.Update(item);
                }
                sort++;
            }
        }
Exemplo n.º 2
0
        void Cascade(IInvocation invocation, object entity)
        {
            switch (invocation.Method.Name)
            {
            case "Create":
                CascadeImpl.OnCreate(entity);
                break;

            case "Update":
                CascadeImpl.OnUpdate(entity);
                break;

            case "Delete":
                CascadeImpl.OnDelete(entity);
                break;
            }
        }
Exemplo n.º 3
0
        void OnUpdate(TEntity entity)
        {
            var repository = DependencyResolver.Resolve <IRepository <TJoin> >();

            var key   = KeyFunc(entity);
            var items = JoinFunc(entity);

            var sources = SourceJoinFunc(entity);

            var newItems    = items.Where(o => CascadeImpl.IsDefault(JoinKeyFunc(o)));
            var updateItems = items.Except(newItems);
            var deleteItems = sources.Except(items, new EntityEqualityComparer <TJoin>(JoinKeyFunc));

            foreach (var newItem in newItems)
            {
                ForeignKeyAction(newItem, key);
                if (JoinSortAction != null)
                {
                    JoinSortAction(newItem, items.IndexOf(newItem));
                }

                repository.Create(newItem);
            }

            foreach (var updateItem in updateItems)
            {
                ForeignKeyAction(updateItem, key);
                if (JoinSortAction != null)
                {
                    JoinSortAction(updateItem, items.IndexOf(updateItem));
                }

                repository.Update(updateItem);
            }
            foreach (var deleteItem in deleteItems)
            {
                repository.Delete(deleteItem);
            }
        }