Beispiel #1
0
        protected virtual DalBatchOperationResult <V> BatchUpdateAdv(List <V> items, Expression <Func <T, bool> > predicate,
                                                                     bool mergeSubItems = true)
        {
            var result = new DalBatchOperationResult <V>();

            if (items.Count == 0)
            {
                return(result);
            }

            using (var s = CreateStrategy())
            {
                var entities = s.GetQuery(predicate).ToList();
                if (entities.Count == 0)
                {
                    return(result);
                }

                foreach (var item in items)
                {
                    var entity = entities.Where(MatchItems(item)).FirstOrDefault();

                    var oldValue = new V();
                    CopyDataToModel(entity, oldValue);
                    result.OldValues.Add(oldValue);

                    CopyModelToData(entity, item);
                }
                result.Success = s.SubmitChanges();
            }

            if (mergeSubItems)
            {
                foreach (var item in items)
                {
                    MergeSubItems(item);
                }
            }

            return(result);
        }
Beispiel #2
0
        protected override DalBatchOperationResult <V> DeleteAdv(Expression <Func <T, bool> > predicate)
        {
            var result = new DalBatchOperationResult <V>();

            using (var s = CreateStrategy())
            {
                var entities = GetJoinedQuery(s, predicate, true).ToList();
                if (entities.Count == 0)
                {
                    return(result);
                }

                foreach (var entity in entities)
                {
                    DeleteAllSubItems(entity.Item);

                    s.Delete(entity.Item);
                }
                result.Success   = s.SubmitChanges();
                result.OldValues = ListPoco(entities);
            }

            return(result);
        }
Beispiel #3
0
        protected virtual DalBatchOperationResult <V> BatchUpdateAdv(List <V> items, Expression <Func <T, bool> > predicate,
                                                                     bool useModelCulture, bool mergeSubItems)
        {
            var result = new DalBatchOperationResult <V>();

            if (items.Count == 0)
            {
                return(result);
            }

            using (var s = CreateStrategy())
            {
                var entities = GetJoinedQuery(s, predicate, true).ToList();
                if (entities.Count == 0)
                {
                    return(result);
                }

                foreach (var item in items)
                {
                    var entity = entities.Where(MatchItems(item)).FirstOrDefault();

                    var oldValue = new V();
                    CopyDataToModel(entity, oldValue);
                    result.OldValues.Add(oldValue);

                    CopyModelToItem(entity, item);
                }

                result.Success = s.SubmitChanges();

                foreach (var item in items)
                {
                    var entity = entities.Where(MatchItems(item)).FirstOrDefault();

                    var createTrans = false;
                    if (entity.ItemTranslation == null)
                    {
                        createTrans            = true;
                        entity.ItemTranslation = new TT();
                    }

                    CopyModelToTrans(entity, item);
                    UpdateTransCulture(entity.ItemTranslation, item as ILocalizableModel, useModelCulture);

                    if (createTrans && HasTranslation(entity.ItemTranslation))
                    {
                        s.AddEntity(entity.ItemTranslation);
                    }
                }
                result.Success &= s.SubmitChanges();

                foreach (var item in items)
                {
                    var entity = entities.Where(MatchItems(item)).FirstOrDefault();
                    CopyDataToModel(entity, item);
                }
            }

            if (mergeSubItems)
            {
                foreach (var item in items)
                {
                    MergeSubItems(item);
                }
            }

            return(result);
        }