Exemple #1
0
        public ActionResult _Index(string tabId, int parentId, int page, int pageSize, string orderBy)
        {
            var listCommand   = GetListCommand(page, pageSize, orderBy);
            var serviceResult = FieldService.List(parentId, listCommand);

            return(new TelerikResult(serviceResult.Data, serviceResult.TotalRecords));
        }
        public async Task <List <Role_FieldDTO> > SingleListField([FromBody] Role_FieldFilterDTO Role_FieldFilterDTO)
        {
            FieldFilter FieldFilter = new FieldFilter();

            FieldFilter.Skip      = 0;
            FieldFilter.Take      = 200;
            FieldFilter.OrderBy   = FieldOrder.Id;
            FieldFilter.OrderType = OrderType.ASC;
            FieldFilter.Selects   = FieldSelect.ALL;
            FieldFilter.Id        = Role_FieldFilterDTO.Id;
            FieldFilter.MenuId    = Role_FieldFilterDTO.MenuId;
            FieldFilter.Name      = Role_FieldFilterDTO.Name;

            List <Field> Fieldes = await FieldService.List(FieldFilter);

            List <Role_FieldDTO> Role_FieldDTOs = Fieldes
                                                  .Select(x => new Role_FieldDTO(x)).ToList();

            return(Role_FieldDTOs);
        }
Exemple #3
0
 public IEnumerable <Field> List(int contentId)
 {
     return(_fieldService.List(contentId));
 }
        public RemoteValidationResult Validate(RemoteValidationContext model, RemoteValidationResult result)
        {
            var helper = new ValidationHelper(model, result, _provider, _service);

            int productTypesContentId = helper.GetSettingValue(SettingsTitles.PRODUCT_TYPES_CONTENT_ID);
            var marketingContentId    = helper.GetSettingValue(SettingsTitles.MARKETING_PRODUCT_CONTENT_ID);
            var parametersContentId   = helper.GetSettingValue(SettingsTitles.PRODUCTS_PARAMETERS_CONTENT_ID);
            var regionsContentId      = helper.GetSettingValue(SettingsTitles.REGIONS_CONTENT_ID);

            var contentId = model.ContentId;
            int productId = helper.GetValue <int>(Constants.FieldId);

            using (new QPConnectionScope(helper.Customer.ConnectionString, (DatabaseType)helper.Customer.DatabaseType))
            {
                var articleService = new ArticleService(helper.Customer.ConnectionString, 1);

                var product         = productId > 0 ? articleService.Read(productId) : articleService.New(contentId);
                var markProductName = helper.GetRelatedFieldName(product, marketingContentId);
                var markProductId   = helper.GetValue <int>(markProductName);
                var markProduct     = articleService.Read(markProductId);
                var productsName    = helper.GetRelatedFieldName(markProduct, contentId);

                var productTypeName = helper.GetClassifierFieldName(product);
                int typeId          = helper.GetValue <int>(productTypeName);

                var regionsName = helper.GetRelatedFieldName(product, regionsContentId);

                var parametersName = helper.GetRelatedFieldName(product, parametersContentId);

                int[] regionsIds    = helper.GetValue <ListOfInt>(regionsName).ToArray();
                int[] parametersIds = helper.GetValue <ListOfInt>(parametersName)?.ToArray();


                helper.CheckSiteId(productTypesContentId);

                //Проверка того, что продукт не имеет общих регионов с другими региональными продуктами этого МП
                var productsIds = markProduct
                                  .FieldValues.Where(a => a.Field.Name == productsName)
                                  .SelectMany(a => a.RelatedItems)
                                  .ToArray();

                helper.IsProductsRegionsWithModifierIntersectionsExist(articleService, productId, regionsIds,
                                                                       productsIds,
                                                                       regionsName, Constants.FieldProductModifiers, 0);


                if (productId > 0)
                {
                    //Проверка того, что тарифное направление встречается только один раз в продукте
                    var contentProductsParametersId =
                        helper.GetSettingValue(SettingsTitles.PRODUCTS_PARAMETERS_CONTENT_ID);
                    if (parametersIds != null && parametersIds.Any())
                    {
                        var parameters = helper.GetParameters(articleService, contentProductsParametersId,
                                                              parametersIds, "c.BaseParameter is not null");
                        helper.CheckTariffAreaDuplicateExist(parameters, parametersName);
                    }

                    int    contentServiceOnTariffId = 0;
                    string tariffRelationFieldName  = null;
                    bool   hasServicesOnTariff      = true;

                    try
                    {
                        contentServiceOnTariffId = helper.GetSettingValue(SettingsTitles.SERVICES_ON_TARIFF_CONTENT_ID);
                        tariffRelationFieldName  =
                            helper.GetSettingStringValue(SettingsTitles.TARIFF_RELATION_FIELD_NAME);
                    }
                    catch (ValidationException)
                    {
                        hasServicesOnTariff = false;
                    }

                    if (hasServicesOnTariff)
                    {
                        //Получение id поля Tariffs
                        var fieldService = new FieldService(helper.Customer.ConnectionString, 1);
                        var fieldId      = fieldService.List(contentServiceOnTariffId)
                                           .Where(w => w.Name.Equals(tariffRelationFieldName)).Select(s => s.Id).FirstOrDefault();
                        //Получение Id услуг из контента "Услуги на тарифах"
                        var relationsIds = articleService.GetRelatedItems(fieldId, productId, true)?
                                           .Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries)
                                           .Select(int.Parse)
                                           .ToArray();
                        if (relationsIds != null && relationsIds.Any())
                        {
                            //Проверка того, что тарифное направление встречается только один раз в связи продуктов
                            helper.CheckRelationServicesProductsTariff(articleService, contentServiceOnTariffId,
                                                                       tariffRelationFieldName, relationsIds, parametersName);

                            //Проверка того, что связь между продуктами встречается единожды
                            helper.CheckRelationProductsDuplicate(articleService, Constants.FieldId,
                                                                  contentServiceOnTariffId, relationsIds);
                        }

                        var relatedIds = new List <string>();

                        //Проверка того, что сущность с другой стороны связи не в архиве
                        var productRelationsContentId = helper.GetSettingValue(SettingsTitles.PRODUCT_RELATIONS_CONTENT_ID);
                        var contentService            = new ContentService(helper.Customer.ConnectionString, 1);

                        //Получение связанных контентов
                        var contents = contentService.Read(productRelationsContentId)
                                       .AggregatedContents
                                       .Where(w => w.Fields
                                              .Count(a => a.ExactType == FieldExactTypes.O2MRelation &&
                                                     a.RelateToContentId == product.ContentId) >= 2).ToArray();
                        foreach (var con in contents)
                        {
                            //Получение полей, по которым может быть связь
                            var productField = con.Fields
                                               .Where(w => w.ExactType == FieldExactTypes.O2MRelation &&
                                                      w.RelateToContentId == product.ContentId
                                                      ).ToArray();
                            foreach (var field in productField)
                            {
                                //Получение ids связанных статей
                                var relatedArticlesId = articleService.GetRelatedItems(field.Id, productId, true)?
                                                        .Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries)
                                                        .Select(int.Parse)
                                                        .ToArray();

                                if (relatedArticlesId != null && relatedArticlesId.Any())
                                {
                                    var relatedArticles = articleService.List(con.Id, relatedArticlesId, true)
                                                          .Where(w => !w.Archived).Select(s => s).ToList();
                                    var relField = productField.Where(f => f.Name != field.Name).Select(s => s).First();
                                    var rel      = relatedArticles.Select(s =>
                                                                          s.FieldValues.First(f => f.Field.Name == relField.Name).Value).ToArray();
                                    if (rel.Any())
                                    {
                                        relatedIds.AddRange(rel);
                                    }
                                }
                            }
                        }

                        helper.CheckArchivedRelatedEntity(articleService, relatedIds, productId, Constants.FieldId,
                                                          helper.GetSettingValue(SettingsTitles.PRODUCTS_CONTENT_ID));
                    }
                }

                string markProductType =
                    articleService.Read(markProductId)
                    .FieldValues.FirstOrDefault(a => a.Field.Name == productTypeName)?
                    .Value;

                //Проверка, что тип маркетингового продукта и тип продукта -- сопоставимы
                if (!articleService.List(productTypesContentId, null, true).Any(x =>
                                                                                x.FieldValues.FirstOrDefault(a => a.Field.Name == Constants.FieldProductContent)?.Value ==
                                                                                typeId.ToString() &&
                                                                                x.FieldValues.FirstOrDefault(a => a.Field.Name == Constants.FieldMarkProductContent)?.Value ==
                                                                                markProductType))
                {
                    var message = new ActionTaskResultMessage()
                    {
                        ResourceClass = ValidationHelper.ResourceClass,
                        ResourceName  = nameof(RemoteValidationMessages.SameTypeProductMarketingProduct)
                    };

                    result.AddModelError(
                        helper.GetPropertyName(markProductName), helper.ToString(message)
                        );
                }
            }

            return(result);
        }
Exemple #5
0
        public ActionResult _Index(string tabId, int parentId, GridCommand command)
        {
            var serviceResult = FieldService.List(parentId, command.GetListCommand());

            return(new TelerikResult(serviceResult.Data, serviceResult.TotalRecords));
        }
        /// <summary>
        /// Рекурсивно обходит <see cref="Content"/>, генерирует корневую схему и заполняет
        /// <see cref="SchemaContext.SchemasByContent"/> - созданные схемы контентов
        /// и <see cref="SchemaContext.RepeatedContents"/> - повторяющиеся контенты
        /// </summary>
        /// <exception cref="NotSupportedException" />
        /// <exception cref="InvalidOperationException" />
        private ContentSchema GetContentSchema(Content content, SchemaContext context, string path)
        {
            if (context.SchemasByContent.ContainsKey(content))
            {
                ContentSchema repeatedSchema = context.SchemasByContent[content];
                context.RepeatedSchemas.Add(repeatedSchema);
                return(repeatedSchema);
            }

            ContentSchema contentSchema = CreateContentSchema(content, path);

            context.SchemasByContent[content] = contentSchema;

            var qpFields = _fieldService.List(content.ContentId).ToArray();

            var fieldsToAdd = content.Fields
                              .Where(field => !(field is Dictionaries || field is BaseVirtualField) &&
                                     !context.IgnoredFields.Contains(Tuple.Create(content, field)));

            foreach (Field field in fieldsToAdd)
            {
                if (field.FieldName == null)
                {
                    throw new InvalidOperationException(
                              $"FieldName is null: {new { field.FieldId, field.FieldName }}");
                }

                var qpField = field is BackwardRelationField
                        ? _fieldService.Read(field.FieldId)
                        : qpFields.SingleOrDefault(f => f.Id == field.FieldId);

                if (qpField == null)
                {
                    throw new InvalidOperationException(
                        $@"There is a field id={field.FieldId} specified in the definition and missing in the content id={content.ContentId}"
                              );
                }
                if (qpField.ExactType != FieldExactTypes.DynamicImage)
                {
                    contentSchema.Fields[field.FieldName] = GetFieldSchema(field, qpField, context, path);
                }
            }

            if (content.LoadAllPlainFields)
            {
                var qpFieldsToAdd = qpFields
                                    .Where(qpField => qpField.RelationType == Quantumart.QP8.BLL.RelationType.None &&
                                           qpField.ExactType != FieldExactTypes.DynamicImage &&
                                           content.Fields.All(field => field.FieldId != qpField.Id) &&
                                           !context.IgnoredFields
                                           .Any(tuple => tuple.Item1.Equals(content) &&
                                                tuple.Item2.FieldId == qpField.Id));

                foreach (var qpField in qpFieldsToAdd)
                {
                    contentSchema.Fields[qpField.Name] = GetFieldSchema(null, qpField, context, path);
                }
            }

            contentSchema.DisplayFieldName = contentSchema.Fields.Values
                                             .OfType <PlainFieldSchema>()
                                             .Where(f => f.FieldType == FieldExactTypes.String)
                                             .OrderByDescending(f => f.ViewInList)
                                             .ThenBy(f => f.FieldOrder)
                                             .Select(f => f.FieldName)
                                             .FirstOrDefault();

            return(contentSchema);
        }
Exemple #7
0
        public Dictionary <int, int[]> GetAffectedProducts(int articleId, Dictionary <int, ChangedValue> changedFields, bool isLive = false, int?definitionId = null)
        {
            var allDefinitionsFields = GetAllDefinitionsFields(isLive, definitionId);

            var affectedProductIdsByContentId = new Dictionary <int, List <int> >();

            using (new QPConnectionScope(_customer.ConnectionString, (DatabaseType)_customer.DatabaseType))
            {
                int contentId = _articleService.Read(articleId).ContentId;

                var contentFields = _fieldService.List(contentId).Where(x => changedFields.ContainsKey(x.Id)).ToArray();

                var rootPathsToTrack = new Dictionary <int, List <PathToRootContent> >();

                var linkFieldsWithBackFieldsToTrack = contentFields.Where(x => x.RelationType != RelationType.None);

                foreach (var contentField in linkFieldsWithBackFieldsToTrack)
                {
                    List <PathToRootContent> paths = null;

                    //если есть обратная связь то тоже нужно искать зависимости по добавленным и удаленным значениям
                    if (contentField.BackRelationId.HasValue && allDefinitionsFields.MonitoredFieldIds.ContainsKey(contentField.BackRelationId.Value))
                    {
                        paths = allDefinitionsFields.MonitoredFieldIds[contentField.BackRelationId.Value];
                    }
                    else if (allDefinitionsFields.MonitoredBackwardRelationFields.ContainsKey(contentField.Id))
                    {
                        paths = allDefinitionsFields.MonitoredBackwardRelationFields[contentField.Id];
                    }

                    if (paths == null)
                    {
                        continue;
                    }

                    int[] changedIds = GetChangedIds(changedFields[contentField.Id]);

                    foreach (var changedArticleId in changedIds)
                    {
                        if (!rootPathsToTrack.ContainsKey(changedArticleId))
                        {
                            rootPathsToTrack[changedArticleId] = new List <PathToRootContent>();
                        }

                        rootPathsToTrack[changedArticleId].AddRange(paths);
                    }
                }

                //изменили plain поле а мы по этому контенту все plain поля мониторим
                if (allDefinitionsFields.ContentIdsDependentOfAllPlainFields.ContainsKey(contentId) && contentFields.Any(x => x.RelationType == RelationType.None))
                {
                    if (!rootPathsToTrack.ContainsKey(articleId))
                    {
                        rootPathsToTrack[articleId] = new List <PathToRootContent>();
                    }

                    rootPathsToTrack[articleId].AddRange(allDefinitionsFields.ContentIdsDependentOfAllPlainFields[contentId]);
                }


                foreach (int changedFieldId in changedFields.Keys)
                {
                    if (allDefinitionsFields.MonitoredFieldIds.ContainsKey(changedFieldId))
                    {
                        if (!rootPathsToTrack.ContainsKey(articleId))
                        {
                            rootPathsToTrack[articleId] = new List <PathToRootContent>();
                        }

                        rootPathsToTrack[articleId].AddRange(allDefinitionsFields.MonitoredFieldIds[changedFieldId]);
                    }
                }

                foreach (var articleToTrackKV in rootPathsToTrack)
                {
                    var paths = articleToTrackKV.Value;

                    var pathDistinct = paths.Distinct(new PathToRootCompaper());

                    foreach (var path in pathDistinct)
                    {
                        int rootContentId = path.ContentId;

                        if (!affectedProductIdsByContentId.ContainsKey(rootContentId))
                        {
                            affectedProductIdsByContentId[rootContentId] = new List <int>();
                        }

                        if (path.PathFields.Length == 0)
                        {
                            affectedProductIdsByContentId[rootContentId].Add(articleToTrackKV.Key);
                        }
                        else
                        {
                            affectedProductIdsByContentId[rootContentId].AddRange(GetRootArticleIds(path.PathFields, articleToTrackKV.Key));
                        }
                    }
                }
            }

            return(affectedProductIdsByContentId
                   .Where(x => x.Value.Count > 0)
                   .ToDictionary(x => x.Key, x => x.Value.Distinct().ToArray()));
        }