public async Task CheckValidityAsync(MemCheckDbContext dbContext) { if (QueryValidationHelper.IsReservedGuid(CurrentUserId)) { throw new RequestInputException($"Invalid user id '{CurrentUserId}'"); } if (QueryValidationHelper.IsReservedGuid(CardId)) { throw new RequestInputException($"Invalid card id '{CardId}'"); } await QueryValidationHelper.CheckUserIsAllowedToViewCardAsync(dbContext, CurrentUserId, CardId); }
public async Task CheckValidityAsync(MemCheckDbContext dbContext) { if (!CardIds.Any()) { throw new RequestInputException("No card to add label to"); } if (QueryValidationHelper.IsReservedGuid(VersionCreator.Id)) { throw new RequestInputException("Invalid user id"); } if (QueryValidationHelper.IsReservedGuid(TagId)) { throw new RequestInputException("Reserved tag id"); } foreach (var cardId in CardIds) { await QueryValidationHelper.CheckUserIsAllowedToViewCardAsync(dbContext, VersionCreator.Id, cardId); } if (!dbContext.Tags.Where(tag => tag.Id == TagId).Any()) { throw new RequestInputException("Invalid tag id"); } }
public async Task <IEnumerable <ResultCardVersion> > RunAsync(Guid cardId, Guid userId) { if (QueryValidationHelper.IsReservedGuid(cardId)) { throw new RequestInputException("Invalid card id"); } if (QueryValidationHelper.IsReservedGuid(userId)) { throw new RequestInputException("Invalid user id"); } await QueryValidationHelper.CheckUserIsAllowedToViewCardAsync(dbContext, userId, cardId); var cards = dbContext.Cards.Where(card => card.Id == cardId); if (!await cards.AnyAsync()) { throw new RequestInputException(localizer["UnknownCard"].Value); } var currentVersion = await cards.Include(card => card.PreviousVersion) .Select(card => new CardVersionFromDb( card.Id, card.PreviousVersion == null ? (Guid?)null : card.PreviousVersion.Id, card.VersionUtcDate, card.VersionCreator, card.VersionDescription, card.CardLanguage.Id, card.FrontSide, card.BackSide, card.AdditionalInfo, card.TagsInCards.Select(tag => tag.TagId), card.UsersWithView.Select(user => user.UserId), card.Images.Where(img => img.CardSide == 1).Select(img => img.ImageId), card.Images.Where(img => img.CardSide == 2).Select(img => img.ImageId), card.Images.Where(img => img.CardSide == 3).Select(img => img.ImageId) ) ).SingleAsync(); var allPreviousVersions = dbContext.CardPreviousVersions.Where(card => card.Card == cardId) .Select(card => new CardVersionFromDb( card.Id, card.PreviousVersion == null ? (Guid?)null : card.PreviousVersion.Id, card.VersionUtcDate, card.VersionCreator, card.VersionDescription, card.CardLanguage.Id, card.FrontSide, card.BackSide, card.AdditionalInfo, card.Tags.Select(tag => tag.TagId), card.UsersWithView.Select(u => u.AllowedUserId), card.Images.Where(img => img.CardSide == 1).Select(img => img.ImageId), card.Images.Where(img => img.CardSide == 2).Select(img => img.ImageId), card.Images.Where(img => img.CardSide == 3).Select(img => img.ImageId) ) ); var versionDico = allPreviousVersions.ToImmutableDictionary(ver => ver.Id, ver => ver); var result = new List <ResultCardVersion>(); var iterationVersion = currentVersion.PreviousVersion == null ? null : versionDico[currentVersion.PreviousVersion.Value]; result.Add(new ResultCardVersion(currentVersion, iterationVersion)); while (iterationVersion != null) { var previousVersion = iterationVersion.PreviousVersion == null ? null : versionDico[iterationVersion.PreviousVersion.Value]; result.Add(new ResultCardVersion(iterationVersion, previousVersion)); iterationVersion = previousVersion; } return(result); }