/// <summary> /// Returns extended properties based on the relation type. /// </summary> public RelationEditorPropertiesVM GetPropertiesForRelationType(RelationType relType) { return(new RelationEditorPropertiesVM { SourceName = RelationHelper.ComplementaryRelations[relType].GetEnumDescription(), DestinationName = relType.GetEnumDescription(), SourceTypes = RelationHelper.SuggestSourcePageTypes(relType), DestinationTypes = RelationHelper.SuggestDestinationPageTypes(relType), ShowDuration = RelationHelper.IsRelationDurationAllowed(relType), ShowEvent = RelationHelper.IsRelationEventReferenceAllowed(relType) }); }
public async Task OnGetAsync() { string token = await idData.GetAccessToken(HttpContext); IEnumerable <Relation> rs = await client.GetAll(token); Data = rs.Select(x => new RelationsViewModel { Data = x }).ToArray(); Graph = new GraphViewModel { Graph = await RelationHelper.GenerateGraph(nodesClient, tagsClient, rs, token, await nodesClient.GetAll(token)) }; }
public async Task <IActionResult> OnPostQueryAsync() { string token = await idData.GetAccessToken(HttpContext); IEnumerable <Relation> ms = await client.Query(token, PostData.QueryId, PostData.QueryFrom, PostData.QueryTo); Data = ms.Select(x => new RelationsViewModel { Data = x }).ToArray(); Graph = new GraphViewModel { Graph = await RelationHelper.GenerateGraph(nodesClient, tagsClient, ms, token, await nodesClient.GetAll(token)) }; return(Page()); }
/// <summary> /// Creates a new relation between two pages. /// </summary> public Relation AddRelation(Page source, RelationType type, Page target, string duration = null, Page eventPage = null) { if (!RelationHelper.IsRelationAllowed(source.Type, target.Type, type)) { throw new ArgumentException("This relation is not allowed!"); } if (eventPage != null) { if (!RelationHelper.IsRelationEventReferenceAllowed(type)) { throw new ArgumentException("This relation cannot have an event reference."); } if (eventPage.Type != PageType.Event) { throw new ArgumentException("The related event page must have Event type."); } } var rel = new Relation { Id = Guid.NewGuid(), Source = source, Destination = target, Event = eventPage, Type = type, Duration = duration, IsComplementary = false }; _db.Relations.Add(rel); var invRel = new Relation { Id = Guid.NewGuid(), Source = target, Destination = source, Event = eventPage, Type = RelationHelper.ComplementaryRelations[type], Duration = duration, IsComplementary = true }; _db.Relations.Add(invRel); return(rel); }
/// <summary> /// Checks if the create/update request contains valid data. /// </summary> private async Task ValidateRequestAsync(RelationEditorVM vm, bool isNew) { var val = new Validator(); vm.SourceIds = vm.SourceIds ?? new Guid[0]; var pageIds = vm.SourceIds .Concat(new [] { vm.DestinationId ?? Guid.Empty, vm.EventId ?? Guid.Empty }) .ToList(); var pages = await _db.Pages .Where(x => pageIds.Contains(x.Id)) .ToDictionaryAsync(x => x.Id, x => x.Type); var sourceTypes = vm.SourceIds.Select(x => pages.TryGetNullableValue(x)).ToList(); var destType = pages.TryGetNullableValue(vm.DestinationId ?? Guid.Empty); var eventType = pages.TryGetNullableValue(vm.EventId ?? Guid.Empty); if (vm.SourceIds == null || vm.SourceIds.Length == 0) { val.Add(nameof(vm.SourceIds), "Выберите страницу"); } else if (isNew == false && vm.SourceIds.Length > 1) { val.Add(nameof(vm.SourceIds), "При редактировании может быть указана только одна страница"); } else if (sourceTypes.Any(x => x == null)) { val.Add(nameof(vm.SourceIds), "Страница не найдена"); } if (vm.DestinationId == null) { val.Add(nameof(vm.DestinationId), "Выберите страницу"); } else if (destType == null) { val.Add(nameof(vm.DestinationId), "Страница не найдена"); } if (destType != null && sourceTypes.Any(x => x != null && !RelationHelper.IsRelationAllowed(x.Value, destType.Value, vm.Type))) { val.Add(nameof(vm.Type), "Тип связи недопустимм для данных страниц"); } if (vm.EventId != null) { if (eventType == null) { val.Add(nameof(vm.EventId), "Страница не найдена"); } else if (eventType != PageType.Event) { val.Add(nameof(vm.EventId), "Требуется страница события"); } else if (!RelationHelper.IsRelationEventReferenceAllowed(vm.Type)) { val.Add(nameof(vm.EventId), "Событие нельзя привязать к данному типу связи"); } } if (!string.IsNullOrEmpty(vm.DurationStart) || !string.IsNullOrEmpty(vm.DurationEnd)) { if (!RelationHelper.IsRelationDurationAllowed(vm.Type)) { val.Add(nameof(vm.DurationStart), "Дату нельзя указать для данного типа связи"); } else { var from = FuzzyDate.TryParse(vm.DurationStart); var to = FuzzyDate.TryParse(vm.DurationEnd); if (from > to) { val.Add(nameof(vm.DurationStart), "Дата начала не может быть больше даты конца"); } else if (FuzzyRange.TryParse(FuzzyRange.TryCombine(vm.DurationStart, vm.DurationEnd)) == null) { val.Add(nameof(vm.DurationStart), "Введите дату в корректном формате"); } } } var existingRelation = await _db.Relations .AnyAsync(x => vm.SourceIds.Contains(x.SourceId) && x.DestinationId == vm.DestinationId && x.Type == vm.Type && x.Id != vm.Id); if (existingRelation) { val.Add(nameof(vm.DestinationId), "Такая связь уже существует!"); } val.ThrowIfInvalid(); }
private void InitCache() { var ladderExchangeRate = CacheFactory.AppsettingCache.GetAppSetting(EnumAppsetting.LadderExchangeRate); _ladderDayPrzie = new Dictionary <int, List <ConfigLadderdayprizeEntity> >(); _relation = RelationHelper.BuildRelation(ladderExchangeRate); var list = DicLadderexchangeMgr.GetAll(); _exchangeTypeDic = new Dictionary <int, List <string> >(); _exchangeDic = new Dictionary <string, DicLadderexchangeEntity>(); foreach (var entity in list) { if (!_exchangeTypeDic.ContainsKey(entity.Type)) { _exchangeTypeDic.Add(entity.Type, new List <string>()); } var exkeylist = BuildExchangeKey(entity); _exchangeTypeDic[entity.Type].AddRange(exkeylist); foreach (var exkey in exkeylist) { _exchangeDic.Add(exkey, entity); } } var list2 = DicLadderprizeMgr.GetAll(); _prizeDic = new Dictionary <int, List <int> >(8); _prizeNewDic = new Dictionary <int, int>(7); _prizeSevenDic = new Dictionary <int, int>(7); foreach (var entity in list2) { for (int i = entity.MinRank; i <= entity.MaxRank; i++) { if (entity.SubType < 100) { if (!_prizeDic.ContainsKey(i)) { _prizeDic.Add(i, new List <int>(1)); } _prizeDic[i].Add(entity.SubType); } else if (entity.SubType > 300) { if (!_prizeSevenDic.ContainsKey(i)) { _prizeSevenDic.Add(i, entity.SubType); } } else { if (!_prizeNewDic.ContainsKey(i)) { _prizeNewDic.Add(i, entity.SubType); } } } } var listdayPrize = ConfigLadderdayprizeMgr.GetAll(); foreach (var item in listdayPrize) { if (!_ladderDayPrzie.ContainsKey(item.WinNumber)) { _ladderDayPrzie.Add(item.WinNumber, new List <ConfigLadderdayprizeEntity>()); } _ladderDayPrzie[item.WinNumber].Add(item); } }