private void ExportAttributeSetsAsync(MixCmsContext context, IDbContextTransaction transaction)
        {
            foreach (var item in AttributeSets)
            {
                item.Fields = MixAttributeFields.UpdateViewModel.Repository.GetModelListBy(a => a.AttributeSetId == item.Id, context, transaction).Data?.OrderBy(a => a.Priority).ToList();
                // Filter list reference field => Add to Export Data if not exist
                var refFields = item.Fields.Where(f => f.DataType == MixDataType.Reference);

                foreach (var field in refFields)
                {
                    var refSet = AttributeSets.FirstOrDefault(m => m.Name == field.AttributeSetName);
                    if (refSet == null)
                    {
                        var getSet = MixAttributeSets.ImportViewModel.Repository.GetSingleModel(m => m.Name == field.AttributeSetName, context, transaction);
                        if (getSet.IsSucceed)
                        {
                            refSet = getSet.Data;
                            refSet.IsExportData = refSet.IsExportData || item.IsExportData;
                            AttributeSets.Add(refSet);
                        }
                    }
                    else
                    {
                        refSet.IsExportData = refSet.IsExportData || item.IsExportData;
                    }
                }
                // Load export data if checked and did not process
                if (item.IsExportData && item.Data != null)
                {
                }
            }
        }
        private async Task <RepositoryResponse <bool> > ImportAttributeSetDatas(string destCulture, MixCmsContext context, IDbContextTransaction transaction)
        {
            var result = new RepositoryResponse <bool>()
            {
                IsSucceed = true
            };

            foreach (var item in AttributeSetDatas)
            {
                item.CreatedBy = CreatedBy;
                if (result.IsSucceed)
                {
                    item.CreatedBy = CreatedBy;
                    if (!context.MixAttributeSetData.Any(m => m.Id == item.Id && m.Specificulture == item.Specificulture))
                    {
                        item.Specificulture  = destCulture;
                        item.CreatedDateTime = DateTime.UtcNow;
                        // update new Id if not system attribute
                        if (item.AttributeSetName.IndexOf("sys_") != 0 && dicAttributeSetIds.ContainsKey(item.AttributeSetId))
                        {
                            item.AttributeSetId = dicAttributeSetIds[item.AttributeSetId];
                        }
                        item.Fields = item.Fields ?? MixAttributeFields.UpdateViewModel.Repository.GetModelListBy(
                            m => m.AttributeSetId == item.AttributeSetId, context, transaction).Data;
                        foreach (var field in item.Fields)
                        {
                            field.Specificulture = destCulture;
                            var newSet   = AttributeSets.FirstOrDefault(m => m.Name == field.AttributeSetName);
                            var newField = newSet?.Fields.FirstOrDefault(m => m.Name == field.Name);
                            if (newField != null)
                            {
                                field.Id               = newField.Id;
                                field.AttributeSetId   = newSet.Id;
                                field.AttributeSetName = newSet.Name;
                                field.CreatedDateTime  = DateTime.UtcNow;
                            }
                        }
                        var saveResult = await item.SaveModelAsync(true, context, transaction);

                        ViewModelHelper.HandleResult(saveResult, ref result);
                    }
                }
                else
                {
                    break;
                }
            }
            return(result);
        }
Exemple #3
0
        private async Task <RepositoryResponse <bool> > ImportAttributeSetDatas(MixCmsContext context, IDbContextTransaction transaction)
        {
            var result = new RepositoryResponse <bool>()
            {
                IsSucceed = true
            };

            foreach (var item in AttributeSetDatas)
            {
                if (result.IsSucceed)
                {
                    if (!context.MixAttributeSetData.Any(m => m.Id == item.Id && m.Specificulture == item.Specificulture))
                    {
                        item.Fields = item.Fields ?? MixAttributeFields.UpdateViewModel.Repository.GetModelListBy(
                            m => m.AttributeSetId == item.AttributeSetId, context, transaction).Data;
                        foreach (var field in item.Fields)
                        {
                            var newSet   = AttributeSets.FirstOrDefault(m => m.Name == field.AttributeSetName);
                            var newField = newSet?.Fields.FirstOrDefault(m => m.Name == field.Name);
                            if (newField != null)
                            {
                                field.Id               = newField.Id;
                                field.AttributeSetId   = newSet.Id;
                                field.AttributeSetName = newSet.Name;
                            }
                        }
                        var saveResult = await item.SaveModelAsync(true, context, transaction);

                        ViewModelHelper.HandleResult(saveResult, ref result);
                    }
                }
                else
                {
                    break;
                }
            }
            return(result);
        }
        private void ProcessAttributeSetsAsync(MixCmsContext context, IDbContextTransaction transaction)
        {
            foreach (var item in AttributeSets)
            {
                item.Fields = MixAttributeFields.UpdateViewModel.Repository.GetModelListBy(a => a.AttributeSetId == item.Id, context, transaction).Data?.OrderBy(a => a.Priority).ToList();
                // Filter list reference field => Add to Export Data if not exist
                var refFields = item.Fields.Where(f => f.DataType == MixEnums.MixDataType.Reference);

                foreach (var field in refFields)
                {
                    var refSet = AttributeSets.FirstOrDefault(m => m.Name == field.AttributeSetName);
                    if (refSet == null)
                    {
                        var getSet = MixAttributeSets.ImportViewModel.Repository.GetSingleModel(m => m.Name == field.AttributeSetName, context, transaction);
                        if (getSet.IsSucceed)
                        {
                            refSet = getSet.Data;
                            // Load ref data if export parent Data
                            if (item.IsExportData)
                            {
                                var refData = MixAttributeSetDatas.ImportViewModel.Repository.GetModelListBy(
                                    a => a.Specificulture == Specificulture && a.AttributeSetId == refSet.Id, context, transaction)
                                              .Data?.OrderBy(a => a.Priority).ToList();
                                if (refData != null)
                                {
                                    AttributeSetDatas.AddRange(refData);
                                }
                            }
                            AttributeSets.Add(getSet.Data);
                        }
                    }
                    else
                    {
                        refSet.IsExportData = refSet.IsExportData || item.IsExportData;
                        if (item.IsExportData)
                        {
                            refSet.Data = refSet.Data ?? MixAttributeSetDatas.ImportViewModel.Repository.GetModelListBy(
                                a => a.Specificulture == Specificulture && a.AttributeSetId == refSet.Id, context, transaction)
                                          .Data?.OrderBy(a => a.Priority).ToList();
                        }
                    }
                }
                // Load export data if checked and did not process
                if (item.IsExportData)
                {
                    var data = item.Data ?? MixAttributeSetDatas.ImportViewModel.Repository.GetModelListBy(
                        a => a.Specificulture == Specificulture && a.AttributeSetId == item.Id, context, transaction)
                               .Data?.OrderBy(a => a.Priority).ToList();
                    if (data != null)
                    {
                        AttributeSetDatas.AddRange(data);
                    }
                    foreach (var d in item.Data)
                    {
                        var getRelatedData = MixRelatedAttributeDatas.ReadViewModel.Repository.GetModelListBy(
                            m => m.ParentId == d.Id && d.Specificulture == Specificulture);
                        if (getRelatedData.IsSucceed)
                        {
                            RelatedData.AddRange(getRelatedData.Data);
                        }
                    }
                }
            }
        }