public async Task <RuleResult> CreateRule(CreateRule createRule) { RuleResult ruleResult = new RuleResult(); IEnumerable <RuleValidationMessage> ruleValidationMessages = this.createRuleValidator.Validate(createRule); foreach (RuleValidationMessage validationMessage in ruleValidationMessages) { ruleResult.AddErrorMessage(validationMessage.Code, validationMessage.Message); } if (!ruleResult.HasErrors) { // Fetch content type and validate. ContentTypeKey contentTypeKey = ContentTypeKey.New(createRule.TenantId, createRule.ContentTypeCode); ContentType contentType = await this.contentTypeRepository.GetById(contentTypeKey); IConditionNode rootCondition = null; if (createRule.RootCondition != null) { rootCondition = await this.CreateConditionNodeRecursive(createRule.TenantId, createRule.RootCondition); } CreateRuleArgs createRuleArgs = new CreateRuleArgs { Content = createRule.Content, ContentType = contentType, DateBegin = createRule.DateBegin, DateEnd = createRule.DateEnd, Name = createRule.Name, Priority = createRule.Priority, RootCondition = rootCondition, TenantId = createRule.TenantId }; Rule rule = this.ruleFactory.CreateRule(createRuleArgs); IEnumerable <Rule> existentRules = await this.ruleRepository.GetAll( createRule.TenantId, new RulesFilter { ContentTypeCode = contentType.Key.Code }, null); // Move rules w/ priority >= to new rule's priority 1 value forward. foreach (Rule existentRule in existentRules.Where(r => r.Priority >= createRule.Priority)) { existentRule.Priority++; await this.ruleRepository.Update(existentRule); } await this.ruleRepository.Add(rule); ruleResult.AffectedRule = rule; } return(ruleResult); }
public static bool ContentIsSameType(this IContent content, ContentTypeKey key) { if (content == null) { return(false); } return(content.ContentType.Alias.Equals(key.ToString(), StringComparison.InvariantCultureIgnoreCase)); }
public static Func <IEnumerable <IContent> > MyGetIContentsByTypeFromService(ContentTypeKey key, IContentService service, IContentTypeService typeService) { var type = typeService.GetContentType(key.ToString()); return(() => { return service.GetContentOfContentType(type.Id); }); }
public static IContent GetIContentWithType(this ContentTypeKey key, int id) { var page = E.GetIContentById(id, false); if (page == null || !page.ContentIsSameType(key)) { return(null); } return(page); }
public OptionsStorage(ISettingsService settingsService) { if (settingsService == null) { throw new ArgumentNullException(nameof(settingsService)); } toGroupSection = new Dictionary <string, ISettingsSection>(StringComparer.Ordinal); toContentTypeSection = new Dictionary <ContentTypeKey, ISettingsSection>(); toOptionSection = new Dictionary <OptionKey, ISettingsSection>(); settingsSection = settingsService.GetOrCreateSection(SETTINGS_GUID); foreach (var groupSect in settingsSection.SectionsWithName(GroupName)) { var groupName = groupSect.Attribute <string>(GroupNameAttr); if (groupName == null) { continue; } if (toGroupSection.ContainsKey(groupName)) { continue; } toGroupSection[groupName] = groupSect; foreach (var ctSect in groupSect.SectionsWithName(ContentTypeName)) { var contentType = ctSect.Attribute <string>(ContentTypeNameAttr); if (contentType == null) { continue; } var key = new ContentTypeKey(groupName, contentType); if (toContentTypeSection.ContainsKey(key)) { continue; } toContentTypeSection[key] = ctSect; foreach (var optSect in ctSect.SectionsWithName(OptionName)) { var name = optSect.Attribute <string>(OptionNameAttr); if (name == null) { continue; } var optKey = new OptionKey(key, name); if (toOptionSection.ContainsKey(optKey)) { continue; } toOptionSection[optKey] = optSect; } } } }
public InvariantResult IsValid(CreateRule obj) { ContentTypeKey contentTypeKey = ContentTypeKey.New(obj.TenantId, obj.ContentTypeCode); ContentType contentType = this.contentTypeRepository.GetById(contentTypeKey).GetAwaiter().GetResult(); // Validate content type. if (contentType == null) { return(InvariantResult.ForInvalid(this.Code, string.Format(InvariantResources.R004, obj.TenantId, obj.ContentTypeCode))); } return(InvariantResult.ForValid(this.Code)); }
ISettingsSection GetOrCreateContentTypeSection(string groupName, string contentType) { var key = new ContentTypeKey(groupName, contentType); if (toContentTypeSection.TryGetValue(key, out var sect)) { return(sect); } var groupSect = GetOrCreateGroupSection(groupName); sect = groupSect.CreateSection(ContentTypeName); toContentTypeSection.Add(key, sect); sect.Attribute(ContentTypeNameAttr, contentType); return(sect); }
public async Task <ContentTypeDto> GetBy(Guid tenantId, int code) { ContentTypeKey key = ContentTypeKey.New(tenantId, code); return(await this.contentTypeRepository.GetById(key) .ContinueWith(contentTypeTask => { ContentType contentType = contentTypeTask.GetAwaiter().GetResult(); if (contentType != null) { return this.ConvertToDto(contentType); } return null; })); }
public bool Update(ContentTypeKey key, string value) { ResultManager.IsCorrect = false; //initial validations //-sys validations if (value == null) { ResultManager.Add(ErrorDefault, Trace + "ContenDataEdit.111 Value del contenido a editar no puede ser nulo"); return(false); } //update item try { string lookupKey = Keys.ContainsKey(key) ? Keys[key] : string.Empty; ContentData item = Repository.ContentData.GetAll().Where(x => string.Equals(x.Key, lookupKey)).FirstOrDefault(); bool isNewContentKey = false; if (item == null) { isNewContentKey = true; item = new ContentData(); } item.Key = Keys[key]; item.Value = value; if (isNewContentKey) { Repository.ContentData.Add(item); } Repository.Complete(); ResultManager.IsCorrect = true; return(true); } catch (Exception ex) { ResultManager.Add(ErrorDefault, Trace + "ContenDataEdit.511 Excepción al editar el contenido con key '" + key + "': " + ex.Message); } return(false); }
public async Task <ContentTypeDto> Update(ContentTypeDto contentTypeDto) { ContentTypeKey key = ContentTypeKey.New(contentTypeDto.TenantId, contentTypeDto.Code); ContentType conditionType = await this.contentTypeRepository.GetById(key); if (conditionType == null) { throw new NotFoundException(FormattableString.Invariant($"{nameof(ContentType)} was not found. Key = {key}")); } conditionType.Name = contentTypeDto.Name; return(await this.contentTypeRepository.Update(conditionType) .ContinueWith(tenantTask => { tenantTask.GetAwaiter().GetResult(); return this.ConvertToDto(conditionType); })); }
public ContentData GetContentDataByKey(ContentTypeKey key) { ResultManager.IsCorrect = false; ContentData item = null; try { string lookupKey = Keys.ContainsKey(key) ? Keys[key] : string.Empty; item = Repository.ContentData.GetAll().Where(x => string.Equals(x.Key, lookupKey)).FirstOrDefault(); } catch (Exception ex) { ResultManager.Add(ErrorDefault, Trace + "Retrieve.511 Excepción al obtener el contenido con llave " + key + ": " + ex.Message); } return(item); }
public OptionKey(ContentTypeKey contentTypeKey, string name) { this.contentTypeKey = contentTypeKey; this.name = name; }
public static string ContentTypeViewPath(this ContentTypeKey type) { return($"~/Views/{type.ToString()}.cshtml"); }
public static Func <IDictionary <int, CacheIContent>, IEnumerable <CacheIContent> > MyGetContentByTypeFromCache(ContentTypeKey key) { return((cacheInput) => { var cache = new Dictionary <int, CacheIContent>(cacheInput); return cache .Where(b => b.Value.Content.ContentType.Alias.Equals(key.ToString(), StringComparison.InvariantCultureIgnoreCase)) .Select(b => b.Value); }); }