コード例 #1
0
        private void GetAdditionalData(string id, MixEnums.MixAttributeSetDataType type, MixCmsContext context, IDbContextTransaction transaction)
        {
            var getRelatedData = MixRelatedAttributeDatas.ImportViewModel.Repository.GetSingleModel(
                m => m.Specificulture == Specificulture && m.ParentType == type.ToString() &&
                m.ParentId == id, context, transaction);

            if (getRelatedData.IsSucceed)
            {
                RelatedData = (getRelatedData.Data);
            }
        }
コード例 #2
0
ファイル: Helper.cs プロジェクト: wangchengqun/mix.core
        public static async Task <RepositoryResponse <List <MixRelatedAttributeData> > > RemoveRelatedDataAsync(
            string parentId, MixEnums.MixAttributeSetDataType parentType, string specificulture
            , MixCmsContext context, IDbContextTransaction transaction)
        {
            var result = await MixRelatedAttributeDatas.DeleteViewModel.Repository.RemoveListModelAsync(
                true
                , a => a.ParentId == parentId && a.ParentType == parentType.ToString() &&
                a.Specificulture == specificulture
                , context, transaction);

            return(result);
        }
コード例 #3
0
        public void LoadData(string parentId, MixEnums.MixAttributeSetDataType parentType, string specificulture, int?pageSize = null, int?pageIndex = 0
                             , MixCmsContext _context = null, IDbContextTransaction _transaction = null)
        {
            var getData = MixRelatedAttributeDatas.ReadMvcViewModel.Repository
                          .GetModelListBy(
                m => m.ParentId == parentId && m.ParentType == parentType.ToString() && m.Specificulture == specificulture
                , MixService.GetConfig <string>(MixConstants.ConfigurationKeyword.OrderBy), 0
                , pageSize, pageIndex
                , _context: _context, _transaction: _transaction);

            Data = getData.Data;
        }
コード例 #4
0
        public void LoadReferenceData(string parentId, MixEnums.MixAttributeSetDataType parentType,
                                      MixCmsContext _context = null, IDbContextTransaction _transaction = null)
        {
            var refFields = Values.Where(m => m.DataType == MixEnums.MixDataType.Reference).OrderBy(v => v.Priority).ToList();

            foreach (var item in refFields)
            {
                item.Field = item.Field ?? MixAttributeFields.ReadViewModel.Repository.GetSingleModel(m => m.Id == item.AttributeFieldId
                                                                                                      , _context, _transaction).Data;
                Expression <Func <MixRelatedAttributeData, bool> > predicate = model =>
                                                                               (model.AttributeSetId == item.Field.ReferenceId) &&
                                                                               (model.ParentId == parentId && model.ParentType == parentType.ToString()) &&
                                                                               model.Specificulture == Specificulture
                ;
                var getData = MixRelatedAttributeDatas.NavigationViewModel.Repository.GetModelListBy(predicate, _context, _transaction);

                JArray arr = new JArray();

                foreach (var nav in getData.Data.OrderBy(d => d.Priority))
                {
                    nav.Data.Obj.Add(new JProperty("data", nav.Data.Obj));
                    arr.Add(nav.Data.Obj);
                }
                if (Obj.ContainsKey(item.AttributeFieldName))
                {
                    Obj[item.AttributeFieldName] = arr;
                }
                else
                {
                    Obj.Add(new JProperty(item.AttributeFieldName, arr));
                }
            }
        }
コード例 #5
0
        public static async Task <RepositoryResponse <AddictionalViewModel> > GetAddictionalData(
            MixEnums.MixAttributeSetDataType parentType, int parentId,
            HttpRequest request, string culture = null,
            MixCmsContext _context = null, IDbContextTransaction _transaction = null)
        {
            UnitOfWorkHelper <MixCmsContext> .InitTransaction(_context, _transaction, out MixCmsContext context, out IDbContextTransaction transaction, out bool isRoot);

            try
            {
                // Addictional Data is sub data of page / post / module only
                culture = culture ?? MixService.GetConfig <string>("DefaultCulture");
                var databaseName = request.Query["databaseName"].ToString();
                var dataId       = (await context.MixRelatedAttributeData.FirstOrDefaultAsync(
                                        m => m.AttributeSetName == databaseName && m.ParentType == parentType.ToString() && m.ParentId == parentId.ToString() && m.Specificulture == culture))?.DataId;
                if (!string.IsNullOrEmpty(dataId))
                {
                    return(await AddictionalViewModel.Repository.GetSingleModelAsync(
                               m => m.Id == dataId && m.Specificulture == culture));
                }
                else
                {
                    // Init default data
                    var getAttrSet = await Lib.ViewModels.MixAttributeSets.UpdateViewModel.Repository.GetSingleModelAsync(
                        m => m.Name == request.Query["databaseName"].ToString());

                    if (getAttrSet.IsSucceed)
                    {
                        AddictionalViewModel result = new AddictionalViewModel()
                        {
                            Specificulture   = culture,
                            AttributeSetId   = getAttrSet.Data.Id,
                            AttributeSetName = getAttrSet.Data.Name,
                            Status           = MixEnums.MixContentStatus.Published,
                            Fields           = getAttrSet.Data.Fields,
                            ParentType       = parentType
                        };
                        result.ExpandView();
                        return(new RepositoryResponse <AddictionalViewModel>()
                        {
                            IsSucceed = true,
                            Data = result
                        });
                    }
                }
                return(new RepositoryResponse <AddictionalViewModel>());
            }
            catch (Exception ex)
            {
                return(UnitOfWorkHelper <MixCmsContext> .HandleException <AddictionalViewModel>(ex, isRoot, transaction));
            }
            finally
            {
                if (isRoot)
                {
                    //if current Context is Root
                    UnitOfWorkHelper <MixCmsContext> .CloseDbContext(ref context, ref transaction);
                }
            }
        }
コード例 #6
0
ファイル: Helper.cs プロジェクト: rodrigofdz/mix.core
        public static async Task <RepositoryResponse <PaginationModel <TView> > > GetAttributeDataByParent <TView>(
            string culture, string attributeSetName,
            string parentId, MixEnums.MixAttributeSetDataType parentType,
            string orderBy, Heart.Enums.MixHeartEnums.DisplayDirection direction,
            int?pageSize, int?pageIndex,
            MixCmsContext _context = null, IDbContextTransaction _transaction = null)
            where TView : ViewModelBase <MixCmsContext, MixAttributeSetData, TView>
        {
            UnitOfWorkHelper <MixCmsContext> .InitTransaction(_context, _transaction, out MixCmsContext context, out IDbContextTransaction transaction, out bool isRoot);

            try
            {
                var tasks = new List <Task <RepositoryResponse <TView> > >();

                Expression <Func <MixRelatedAttributeData, bool> > predicate = m => m.Specificulture == culture &&
                                                                               (m.AttributeSetName == attributeSetName) &&
                                                                               (m.Status == MixEnums.MixContentStatus.Published.ToString()) &&
                                                                               (string.IsNullOrEmpty(parentId) ||
                                                                                (m.ParentId == parentId && m.ParentType == parentType.ToString())
                                                                               );
                ;
                var query   = context.MixRelatedAttributeData.Where(predicate).Select(m => m.DataId).Distinct();
                var dataIds = query.ToList();
                Expression <Func <MixAttributeSetData, bool> > pre = m => dataIds.Any(id => m.Id == id);
                return(await DefaultRepository <MixCmsContext, MixAttributeSetData, TView> .Instance.GetModelListByAsync(
                           pre, orderBy, direction, pageSize, pageIndex, null, null, context, transaction));
            }
            catch (Exception ex)
            {
                return(UnitOfWorkHelper <MixCmsContext> .HandleException <PaginationModel <TView> >(ex, isRoot, transaction));
            }
            finally
            {
                if (isRoot)
                {
                    //if current Context is Root
                    context.Database.CloseConnection(); transaction.Dispose(); context.Dispose();
                }
            }
        }