public static void AssertSameUserWithViewSet(IEnumerable <UserWithViewOnCard> cardAllowedUsers, IEnumerable <UserWithViewOnCardPreviousVersion> cardPreviousVersionAllowedUsers) { Assert.IsTrue(CardVisibilityHelper.CardsHaveSameUsersWithView(cardAllowedUsers, cardPreviousVersionAllowedUsers)); }
protected override async Task <ResultWithMetrologyProperties <Result> > DoRunAsync(Request request) { var current = await DbContext.Cards .Include(c => c.CardLanguage) .Include(c => c.TagsInCards) .ThenInclude(t => t.Tag) .Include(c => c.Images) .ThenInclude(i => i.Image) .SingleAsync(c => c.Id == request.CurrentCardId); var original = await DbContext.CardPreviousVersions .Include(c => c.CardLanguage) .Include(c => c.Tags) .ThenInclude(t => t.Tag) .Include(c => c.Images) .ThenInclude(i => i.Image) .SingleAsync(c => c.Id == request.OriginalVersionId); var result = new Result(current.VersionCreator.UserName, original.VersionCreator.UserName, current.VersionUtcDate, original.VersionUtcDate, current.VersionDescription, original.VersionDescription); if (current.FrontSide != original.FrontSide) { result = result with { FrontSide = new(current.FrontSide, original.FrontSide) } } ; if (current.BackSide != original.BackSide) { result = result with { BackSide = new(current.BackSide, original.BackSide) } } ; if (current.AdditionalInfo != original.AdditionalInfo) { result = result with { AdditionalInfo = new(current.AdditionalInfo, original.AdditionalInfo) } } ; if (current.CardLanguage != original.CardLanguage) { result = result with { Language = new(current.CardLanguage.Name, original.CardLanguage.Name) } } ; if (!Enumerable.SequenceEqual(current.TagsInCards.Select(t => t.Tag.Name).OrderBy(tagName => tagName), original.Tags.Select(t => t.Tag.Name).OrderBy(tagName => tagName))) { var currentTags = string.Join(",", current.TagsInCards.Select(t => t.Tag.Name).OrderBy(tagName => tagName)); var originalTags = string.Join(",", original.Tags.Select(t => t.Tag.Name).OrderBy(tagName => tagName)); result = result with { Tags = new(currentTags, originalTags) }; } if (!CardVisibilityHelper.CardsHaveSameUsersWithView(current.UsersWithView, original.UsersWithView)) { var currentUsers = string.Join(",", current.UsersWithView.Select(u => u.User.UserName).OrderBy(userName => userName)); var originalUserIds = original.UsersWithView.Select(u => u.AllowedUserId).ToHashSet(); var originalUserNames = DbContext.Users.Where(u => originalUserIds.Contains(u.Id)).Select(u => u.UserName); var originalUsers = string.Join(",", originalUserNames.OrderBy(userName => userName)); result = result with { UsersWithView = new(currentUsers, originalUsers) }; } if (!ComparisonHelper.SameSetOfGuid(current.Images.Where(i => i.CardSide == ImageInCard.FrontSide).Select(i => i.ImageId), original.Images.Where(i => i.CardSide == ImageInCard.FrontSide).Select(i => i.ImageId))) { var currentImages = string.Join(",", current.Images.Where(i => i.CardSide == ImageInCard.FrontSide).Select(i => i.Image.Name).OrderBy(imageName => imageName)); var originalImages = string.Join(",", original.Images.Where(i => i.CardSide == ImageInCard.FrontSide).Select(i => i.Image.Name).OrderBy(imageName => imageName)); result = result with { ImagesOnFrontSide = new(currentImages, originalImages) }; } if (!ComparisonHelper.SameSetOfGuid(current.Images.Where(i => i.CardSide == ImageInCard.BackSide).Select(i => i.ImageId), original.Images.Where(i => i.CardSide == ImageInCard.BackSide).Select(i => i.ImageId))) { var currentImages = string.Join(",", current.Images.Where(i => i.CardSide == ImageInCard.BackSide).Select(i => i.Image.Name).OrderBy(imageName => imageName)); var originalImages = string.Join(",", original.Images.Where(i => i.CardSide == ImageInCard.BackSide).Select(i => i.Image.Name).OrderBy(imageName => imageName)); result = result with { ImagesOnBackSide = new(currentImages, originalImages) }; } if (!ComparisonHelper.SameSetOfGuid(current.Images.Where(i => i.CardSide == ImageInCard.AdditionalInfo).Select(i => i.ImageId), original.Images.Where(i => i.CardSide == ImageInCard.AdditionalInfo).Select(i => i.ImageId))) { var currentImages = string.Join(",", current.Images.Where(i => i.CardSide == ImageInCard.AdditionalInfo).Select(i => i.Image.Name).OrderBy(imageName => imageName)); var originalImages = string.Join(",", original.Images.Where(i => i.CardSide == ImageInCard.AdditionalInfo).Select(i => i.Image.Name).OrderBy(imageName => imageName)); result = result with { ImagesOnAdditionalSide = new(currentImages, originalImages) }; } return(new ResultWithMetrologyProperties <Result>(result, ("CurrentCardId", request.CurrentCardId.ToString()), ("OriginalVersionId", request.OriginalVersionId.ToString()))); }