コード例 #1
0
ファイル: HccSimpleRepoBase.cs プロジェクト: wncoder/core
        protected virtual DalSingleOperationResult <V> UpdateAdv(V m, Expression <Func <T, bool> > predicate,
                                                                 bool mergeSubItems = true)
        {
            var result = new DalSingleOperationResult <V>();

            using (var s = CreateStrategy())
            {
                var entity = s.GetQuery(predicate).FirstOrDefault();
                if (entity == null)
                {
                    return(result);
                }

                CopyDataToModel(entity, result.OldValue);

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

            if (mergeSubItems)
            {
                MergeSubItems(m);
            }

            return(result);
        }
コード例 #2
0
        protected virtual DalSingleOperationResult <V> UpdateAdv(V m, Expression <Func <T, bool> > predicate,
                                                                 bool useModelCulture, bool mergeSubItems)
        {
            var result = new DalSingleOperationResult <V>();

            using (var s = CreateStrategy())
            {
                var entity = GetJoinedQuery(s, predicate, true).FirstOrDefault();
                if (entity == null)
                {
                    return(result);
                }

                CopyDataToModel(entity, result.OldValue);

                var createTrans = false;
                if (entity.ItemTranslation == null)
                {
                    createTrans            = true;
                    entity.ItemTranslation = new TT();
                }
                CopyModelToItem(entity, m);
                result.Success = s.SubmitChanges();

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

                if (HasTranslation(entity.ItemTranslation))
                {
                    if (createTrans)
                    {
                        s.AddEntity(entity.ItemTranslation);
                    }

                    result.Success &= s.SubmitChanges();
                }
                if (result.Success)
                {
                    CopyDataToModel(entity, m);
                }
            }

            if (mergeSubItems)
            {
                MergeSubItems(m);
            }

            return(result);
        }