private async Task CheckCardVersionsCreatorsAsync(Guid cardId, MemCheckDbContext dbContext, ILocalized localizer) { var currentVersionCreator = await dbContext.Cards .Include(card => card.VersionCreator) .Where(card => card.Id == cardId) .Select(card => card.VersionCreator) .SingleAsync(); if (currentVersionCreator.Id != UserId && currentVersionCreator.DeletionDate == null) { //You are not the creator of the current version of the card with front side //Vous n'êtes pas l'auteur de la version actuelle de la carte avec avant throw new RequestInputException(localizer.Get("YouAreNotTheCreatorOfCurrentVersion") + await CardFrontSideInfoForExceptionMessageAsync(cardId, dbContext, localizer)); } var anyPreviousVersionHasOtherCreator = await dbContext.CardPreviousVersions .Include(version => version.VersionCreator) .Where(version => version.Card == cardId && version.VersionCreator.Id != UserId && version.VersionCreator.DeletionDate == null) .AnyAsync(); if (anyPreviousVersionHasOtherCreator) { //You are not the creator of all the previous versions of the card with front side //Vous n'êtes pas l'auteur de toutes les versions précédentes de la carte avec avant throw new RequestInputException(localizer.Get("YouAreNotTheCreatorOfAllPreviousVersions") + await CardFrontSideInfoForExceptionMessageAsync(cardId, dbContext, localizer)); } }
public static async Task CheckUserDoesNotHaveDeckWithNameAsync(MemCheckDbContext dbContext, Guid userId, string name, ILocalized localizer) { if (await dbContext.Decks.AsNoTracking().Where(deck => (deck.Owner.Id == userId) && EF.Functions.Like(deck.Description, name)).AnyAsync()) { throw new RequestInputException($"{localizer.Get("ADeckWithName")} '{name}' {localizer.Get("AlreadyExists")}"); } }
private static void AddField(List <string> changedFields, List <string> unChangedFields, string fieldNameResourceId, string fieldValueInCard, string fieldValueInSelectedVersion, ILocalized localizer) { if (fieldValueInCard == fieldValueInSelectedVersion) { unChangedFields.Add($"<strong>{localizer.Get(fieldNameResourceId)}</strong> {(fieldValueInCard.Length > 0 ? fieldValueInCard : localizer.Get("Empty"))}"); } else { var html = new StringBuilder(); html.Append($"<strong>{localizer.Get(fieldNameResourceId)}</strong>"); html.Append("<ul>"); html.Append($"<li><strong>{localizer.Get("SelectedVersion")}</strong> {(fieldValueInSelectedVersion.Length > 0 ? fieldValueInSelectedVersion : localizer.Get("Empty"))}</li>"); html.Append($"<li><strong>{localizer.Get("LastVersion")}</strong> {(fieldValueInCard.Length > 0 ? fieldValueInCard : localizer.Get("Empty"))}</li>"); html.Append("</ul>"); changedFields.Add(html.ToString()); } }
public static void CheckCanCreateImageWithSource(string source, ILocalized localizer) { if (source != source.Trim()) { throw new InvalidOperationException("Invalid source: not trimmed"); } if (source.Length < ImageMinSourceLength || source.Length > ImageMaxSourceLength) { throw new RequestInputException(localizer.Get("InvalidSourceLength") + $" {source.Length}, " + localizer.Get("MustBeBetween") + $" {ImageMinSourceLength} " + localizer.Get("And") + $" {ImageMaxSourceLength}"); } foreach (var forbiddenChar in ForbiddenCharsInImageSource) { if (source.Contains(forbiddenChar)) { throw new RequestInputException(localizer.Get("InvalidImageSource") + " '" + source + "' ('" + forbiddenChar + ' ' + localizer.Get("IsForbidden") + ")"); } } }
public static void CheckCanCreateImageWithVersionDescription(string versionDescription, ILocalized localizer) { if (versionDescription != versionDescription.Trim()) { throw new InvalidOperationException("Invalid version description: not trimmed"); } if (versionDescription.Length < ImageMinVersionDescriptionLength || versionDescription.Length > ImageMaxVersionDescriptionLength) { throw new RequestInputException(localizer.Get("InvalidVersionDescriptionLength") + $" {versionDescription.Length}, " + localizer.Get("MustBeBetween") + $" {ImageMinVersionDescriptionLength} " + localizer.Get("And") + $" {ImageMaxVersionDescriptionLength}"); } foreach (var forbiddenChar in ForbiddenCharsInImageVersionDescription) { if (versionDescription.Contains(forbiddenChar)) { throw new RequestInputException(localizer.Get("InvalidImageVersionDescription") + " '" + versionDescription + "' ('" + forbiddenChar + ' ' + localizer.Get("IsForbidden") + ")"); } } }
private static async Task <string> CardFrontSideInfoForExceptionMessageAsync(Guid cardId, MemCheckDbContext dbContext, ILocalized localizer) { var cardFrontSide = await dbContext.Cards.Where(card => card.Id == cardId).Select(card => card.FrontSide).SingleAsync(); if (cardFrontSide.Length < 100) { return($" '{cardFrontSide}'"); } return($"{localizer.Get("StartingWith")} '{cardFrontSide.Substring(0, 100)}'"); }
private async Task CheckVisibilityForUsersAsync(IEnumerable <Guid> userIds, ILocalized localizer, string messageSuffixId, MemCheckDbContext dbContext) { foreach (var userId in userIds) { if (!UsersWithVisibility.Any(u => u == userId)) { var user = await dbContext.Users.SingleAsync(u => u.Id == userId); throw new RequestInputException($"{localizer.Get("User")} {user.UserName} {localizer.Get("MustHaveVisibilityBecause")} {localizer.Get(messageSuffixId)}"); } } }
public GetImageInfoForDeletionResult(GetImageInfoFromId.Result appResult, ILocalized localizer) { ImageName = appResult.Name; CardCount = appResult.CardCount; CurrentVersionUserName = appResult.Owner.UserName; Description = appResult.Description; Source = appResult.Source; InitialUploadUtcDate = appResult.InitialUploadUtcDate; DeletionAlertMessage = localizer.Get("AreYouSure"); LastChangeUtcDate = appResult.LastChangeUtcDate; CurrentVersionDescription = appResult.CurrentVersionDescription; }
public SearchSubscriptionViewModel(GetSearchSubscriptions.Result searchSubscription, ILocalized localizer) { Id = searchSubscription.Id; Name = searchSubscription.Name; var details = new StringBuilder(); if (searchSubscription.ExcludedDeck != null) { details.Append(localizer.Get("ExcludedDeck") + ' ' + searchSubscription.ExcludedDeck + ", "); } if (searchSubscription.RequiredText.Length > 0) { details.Append(localizer.Get("RequiredText") + " '" + searchSubscription.RequiredText + "', "); } if (searchSubscription.RequiredTags.Count() == 1) { details.Append(localizer.Get("RequiredTag") + ' ' + string.Join(',', searchSubscription.RequiredTags) + ", "); } if (searchSubscription.RequiredTags.Count() > 1) { details.Append(localizer.Get("RequiredTags") + ' ' + string.Join(',', searchSubscription.RequiredTags) + ", "); } if (searchSubscription.ExcludeAllTags) { details.Append(localizer.Get("OnlyCardsWithNoTag") + ", "); } else if (searchSubscription.ExcludedTags.Count() == 1) { details.Append(localizer.Get("ExcludedTag") + ' ' + string.Join(',', searchSubscription.ExcludedTags) + ", "); } if (searchSubscription.ExcludedTags.Count() > 1) { details.Append(localizer.Get("ExcludedTags") + ' ' + string.Join(',', searchSubscription.ExcludedTags) + ", "); } if (details.Length == 0) { details.Append(localizer.Get("AllCards")); } Details = details.ToString(); CardCountOnLastRun = searchSubscription.CardCountOnLastRun; RegistrationUtcDate = searchSubscription.RegistrationUtcDate; LastRunUtcDate = searchSubscription.LastRunUtcDate; DeleteConfirmMessage = localizer.Get("AreYouSureYouWantToDeleteTheSearch") + " '" + Name + "'"; }
public CardSelectedVersionDiffWithCurrentResult(GetCardForEdit.ResultModel card, GetCardVersion.Result selectedVersion, ILocalized localizer) { FirstVersionUtcDate = card.FirstVersionUtcDate; LastVersionUtcDate = card.LastVersionUtcDate; LastVersionCreatorName = card.LastVersionCreatorName; LastVersionDescription = card.LastVersionDescription; InfoAboutUsage = card.UsersOwningDeckIncluding.Any() ? localizer.Get("AppearsInDecksOf") + ' ' + string.Join(',', card.UsersOwningDeckIncluding) : localizer.Get("NotIncludedInAnyDeck"); AverageRating = card.AverageRating; CountOfUserRatings = card.CountOfUserRatings; SelectedVersionUtcDate = selectedVersion.VersionUtcDate; SelectedVersionDescription = selectedVersion.VersionDescription; SelectedVersionCreatorName = selectedVersion.CreatorName; var changedFields = new List <string>(); var unChangedFields = new List <string>(); AddField(changedFields, unChangedFields, "FrontSide", card.FrontSide, selectedVersion.FrontSide, localizer); AddField(changedFields, unChangedFields, "BackSide", card.BackSide, selectedVersion.BackSide, localizer); AddField(changedFields, unChangedFields, "AdditionalInfo", card.AdditionalInfo, selectedVersion.AdditionalInfo, localizer); AddField(changedFields, unChangedFields, "LanguageName", card.LanguageName, selectedVersion.LanguageName, localizer); var cardTags = card.Tags.Any() ? string.Join(",", card.Tags.Select(t => t.TagName).OrderBy(name => name)) : localizer.Get("NoneMasc"); var versionTags = selectedVersion.Tags.Any() ? string.Join(",", selectedVersion.Tags.OrderBy(name => name)) : localizer.Get("NoneMasc"); AddField(changedFields, unChangedFields, card.Tags.Count() > 1 && selectedVersion.Tags.Count() > 1 ? "Tags" : "Tag", cardTags, versionTags, localizer); var cardVisibility = card.UsersWithVisibility.Any() ? string.Join(",", card.UsersWithVisibility.Select(u => u.UserName).OrderBy(name => name)) : localizer.Get("Public"); var versionVisibility = selectedVersion.UsersWithVisibility.Any() ? string.Join(",", selectedVersion.UsersWithVisibility.OrderBy(name => name)) : localizer.Get("Public"); AddField(changedFields, unChangedFields, "Visibility", cardVisibility, versionVisibility, localizer); var cardFrontSideImageNames = card.Images.Where(i => i.CardSide == ImageInCard.FrontSide).Select(i => i.Name).OrderBy(name => name); var cardFrontSideImageNamesJoined = cardFrontSideImageNames.Any() ? string.Join(",", cardFrontSideImageNames) : localizer.Get("NoneFeminine"); var versionFrontSideImages = selectedVersion.FrontSideImageNames.Any() ? string.Join(",", selectedVersion.FrontSideImageNames.OrderBy(name => name)) : localizer.Get("NoneFeminine"); AddField(changedFields, unChangedFields, "FrontSideImages", cardFrontSideImageNamesJoined, versionFrontSideImages, localizer); var cardBackSideImageNames = card.Images.Where(i => i.CardSide == ImageInCard.BackSide).Select(i => i.Name).OrderBy(name => name); var cardBackSideImageNamesJoined = cardBackSideImageNames.Any() ? string.Join(",", cardBackSideImageNames) : localizer.Get("NoneFeminine"); var versionBackSideImages = selectedVersion.BackSideImageNames.Any() ? string.Join(",", selectedVersion.BackSideImageNames.OrderBy(name => name)) : localizer.Get("NoneFeminine"); AddField(changedFields, unChangedFields, "BackSideImages", cardBackSideImageNamesJoined, versionBackSideImages, localizer); var cardAdditionalImageNames = card.Images.Where(i => i.CardSide == ImageInCard.AdditionalInfo).Select(i => i.Name).OrderBy(name => name); var cardAdditionalImageNamesJoined = cardAdditionalImageNames.Any() ? string.Join(",", cardAdditionalImageNames) : localizer.Get("NoneFeminine"); var versionAdditionalImages = selectedVersion.AdditionalInfoImageNames.Any() ? string.Join(",", selectedVersion.AdditionalInfoImageNames.OrderBy(name => name)) : localizer.Get("NoneFeminine"); AddField(changedFields, unChangedFields, "AdditionalInfoImages", cardAdditionalImageNamesJoined, versionAdditionalImages, localizer); ChangedFields = changedFields; UnchangedFields = unChangedFields; }
public static async Task CheckCanCreateImageWithNameAsync(string name, MemCheckDbContext dbContext, ILocalized localizer) { if (name != name.Trim()) { throw new InvalidOperationException("Invalid Name: not trimmed"); } if (name.Length < ImageMinNameLength || name.Length > ImageMaxNameLength) { throw new RequestInputException(localizer.Get("InvalidNameLength") + $" {name.Length}, " + localizer.Get("MustBeBetween") + $" {ImageMinNameLength} " + localizer.Get("And") + $" {ImageMaxNameLength}"); } foreach (var forbiddenChar in ForbiddenCharsInImageNames) { if (name.Contains(forbiddenChar)) { throw new RequestInputException(localizer.Get("InvalidImageName") + " '" + name + "' ('" + forbiddenChar + ' ' + localizer.Get("IsForbidden") + ")"); } } if (await dbContext.Images.AsNoTracking().Where(img => EF.Functions.Like(img.Name, name)).AnyAsync()) { throw new RequestInputException(localizer.Get("AnImageWithName") + " '" + name + "' " + localizer.Get("AlreadyExistsCaseInsensitive")); } }
private async Task CheckUsersWithCardInADeckAsync(Guid cardId, MemCheckDbContext dbContext, ILocalized localizer) { var decksWithOtherOwner = dbContext.CardsInDecks .Include(cardInDeck => cardInDeck.Deck) .ThenInclude(deck => deck.Owner) .Where(cardInDeck => cardInDeck.CardId == cardId && cardInDeck.Deck.Owner.Id != UserId); var count = await decksWithOtherOwner.CountAsync(); if (count > 0) { var msg = count == 1 ? localizer.Get("OneUserHasCardWithFrontSide") : (count.ToString() + localizer.Get("UsersHaveCardWithFrontSide")); msg += await CardFrontSideInfoForExceptionMessageAsync(cardId, dbContext, localizer); throw new RequestInputException(msg); } }
public GetImageListImageViewModel(GetImageList.ResultImage img, ILocalized localizer) { ImageId = img.ImageId; ImageName = img.ImageName; CardCount = img.CardCount; UploaderUserName = img.Uploader; Description = img.Description; Source = img.Source; OriginalImageContentType = img.OriginalImageContentType; OriginalImageSize = img.OriginalImageSize; SmallSize = img.SmallSize; MediumSize = img.MediumSize; BigSize = img.BigSize; InitialUploadUtcDate = img.InitialUploadUtcDate; LastChangeUtcDate = img.LastChangeUtcDate; RemoveAlertMessage = $"{localizer.Get("SureYouWantToDeletePart1")} '{ImageName}' ? {localizer.Get("SureYouWantToDeletePart2")} {UploaderUserName} {localizer.Get("SureYouWantToDeletePart3")} "; CurrentVersionDescription = img.CurrentVersionDescription; }
public static async Task CheckCanCreateTag(string name, string description, Guid?updatingId, MemCheckDbContext dbContext, ILocalized localizer) { if (name != name.Trim()) { throw new InvalidOperationException("Invalid Name: not trimmed"); } if (description != description.Trim()) { throw new InvalidOperationException("Invalid Description: not trimmed"); } if (name.Length < Tag.MinNameLength || name.Length > Tag.MaxNameLength) { throw new RequestInputException(localizer.Get("InvalidNameLength") + $" {name.Length}, " + localizer.Get("MustBeBetween") + $" {Tag.MinNameLength} " + localizer.Get("And") + $" {Tag.MaxNameLength}"); } if (description.Length > Tag.MaxDescriptionLength) { throw new RequestInputException(localizer.Get("InvalidDescriptionLength") + $" {name.Length}, " + localizer.Get("MustBeNoMoreThan") + $" {Tag.MaxDescriptionLength}"); } foreach (var forbiddenChar in ForbiddenCharsInTags) { if (name.Contains(forbiddenChar)) { throw new RequestInputException(localizer.Get("InvalidTagName") + " '" + name + "' ('" + forbiddenChar + ' ' + localizer.Get("IsForbidden") + ")"); } } if (updatingId != null) { var current = await dbContext.Tags.AsNoTracking().SingleAsync(tag => tag.Id == updatingId.Value); if (current.Name.Equals(name, StringComparison.OrdinalIgnoreCase)) { if (current.Description == description) { throw new RequestInputException(localizer.Get("NoDifference")); } } else { if (await dbContext.Tags.AsNoTracking().Where(tag => EF.Functions.Like(tag.Name, name)).AnyAsync()) { throw new RequestInputException(localizer.Get("ATagWithName") + " '" + name + "' " + localizer.Get("AlreadyExistsCaseInsensitive")); } } } else { if (await dbContext.Tags.AsNoTracking().Where(tag => EF.Functions.Like(tag.Name, name)).AnyAsync()) { throw new RequestInputException(localizer.Get("ATagWithName") + " '" + name + "' " + localizer.Get("AlreadyExistsCaseInsensitive")); } } }
public static async Task CheckCanCreateDeckAsync(Guid userId, string deckName, int heapingAlgorithmId, MemCheckDbContext dbContext, ILocalized localizer) { if (deckName != deckName.Trim()) { throw new InvalidOperationException("Invalid Name: not trimmed"); } if (deckName.Length < DeckMinNameLength || deckName.Length > DeckMaxNameLength) { throw new RequestInputException(localizer.Get("InvalidNameLength") + $" {deckName.Length}" + localizer.Get("MustBeBetween") + $" {DeckMinNameLength} " + localizer.Get("And") + $" {DeckMaxNameLength}"); } if (!HeapingAlgorithms.Instance.Ids.Contains(heapingAlgorithmId)) { throw new InvalidOperationException($"Invalid heaping algorithm: {heapingAlgorithmId}"); } await CheckUserExistsAsync(dbContext, userId); await CheckUserDoesNotHaveDeckWithNameAsync(dbContext, userId, deckName, localizer); }
private void CheckAtLeastOneFieldDifferent(Card card, ILocalized localizer) { var dataBeforeUpdate = new { CardLanguageId = card.CardLanguage.Id, card.FrontSide, card.BackSide, card.AdditionalInfo, TagIds = card.TagsInCards.Select(tag => tag.TagId), UserWithVisibilityIds = card.UsersWithView.Select(u => u.UserId), card.Images }; if ((dataBeforeUpdate.CardLanguageId == LanguageId) && (dataBeforeUpdate.FrontSide == FrontSide) && (dataBeforeUpdate.BackSide == BackSide) && (dataBeforeUpdate.AdditionalInfo == AdditionalInfo) && Enumerable.SequenceEqual(dataBeforeUpdate.TagIds.OrderBy(tagId => tagId), Tags.OrderBy(tagId => tagId)) && Enumerable.SequenceEqual(dataBeforeUpdate.UserWithVisibilityIds.OrderBy(userId => userId), UsersWithVisibility.OrderBy(userId => userId)) && SameImageLists(dataBeforeUpdate.Images)) { throw new RequestInputException(localizer.Get("CanNotUpdateBecauseNoDifference")); } }
public static void Run(ICardInput input, ILocalized localizer) { if (QueryValidationHelper.IsReservedGuid(input.VersionCreatorId)) throw new InvalidOperationException(localizer.Get("InvalidOwner")); if (input.FrontSide != input.FrontSide.Trim()) throw new InvalidOperationException("Invalid front side: not trimmed"); if (input.FrontSide.Length < minFrontSideLength || input.FrontSide.Length > maxFrontSideLength) throw new RequestInputException(localizer.Get("InvalidFrontSideLength") + $" {input.FrontSide.Length}" + localizer.Get("MustBeBetween") + $" {minFrontSideLength} " + localizer.Get("And") + $" {maxFrontSideLength}"); if (input.FrontSideImageList.Count() > maxImageCountPerSide) throw new RequestInputException(localizer.Get("InvalidFrontSideImageCount") + $" {input.FrontSideImageList.Count()}" + localizer.Get("MustBeNotBeAvove") + $" {maxImageCountPerSide}"); if (input.BackSide != input.BackSide.Trim()) throw new InvalidOperationException("Invalid back side: not trimmed"); if ((input.BackSide.Length < minBackSideLength || input.BackSide.Length > maxBackSideLength) && !(input.BackSide.Length == 0 && input.BackSideImageList.Any())) throw new RequestInputException(localizer.Get("InvalidBackSideLength") + $" {input.BackSide.Length}" + localizer.Get("MustBeBetween") + $" {minBackSideLength} " + localizer.Get("And") + $" {maxBackSideLength}"); if (input.BackSideImageList.Count() > maxImageCountPerSide) throw new RequestInputException(localizer.Get("InvalidBackSideImageCount") + $" {input.BackSideImageList.Count()}" + localizer.Get("MustBeNotBeAvove") + $" {maxImageCountPerSide}"); if (input.AdditionalInfo != input.AdditionalInfo.Trim()) throw new InvalidOperationException("Invalid additional info: not trimmed"); if (input.AdditionalInfo.Length < minAdditionalInfoLength || input.AdditionalInfo.Length > maxAdditionalInfoLength) throw new RequestInputException(localizer.Get("InvalidAdditionalInfoLength") + $" {input.AdditionalInfo.Length}" + localizer.Get("MustBeBetween") + $" {minAdditionalInfoLength} " + localizer.Get("And") + $" {maxAdditionalInfoLength}"); if (input.AdditionalInfoImageList.Count() > maxImageCountPerSide) throw new RequestInputException(localizer.Get("InvalidAdditionalInfoImageCount") + $" {input.AdditionalInfoImageList.Count()}" + localizer.Get("MustBeNotBeAvove") + $" {maxImageCountPerSide}"); if (input.VersionDescription != input.VersionDescription.Trim()) throw new InvalidOperationException("Invalid VersionDescription: not trimmed"); if (input.VersionDescription.Length < MinVersionDescriptionLength || input.VersionDescription.Length > MaxVersionDescriptionLength) throw new RequestInputException(localizer.Get("InvalidVersionDescriptionLength") + $" {input.VersionDescription.Length}" + localizer.Get("MustBeBetween") + $" {MinVersionDescriptionLength} " + localizer.Get("And") + $" {MaxVersionDescriptionLength}"); var unionedImageLists = input.FrontSideImageList.Concat(input.BackSideImageList).Concat(input.AdditionalInfoImageList); if (unionedImageLists.GroupBy(guid => guid).Where(guid => guid.Count() > 1).Any()) throw new RequestInputException(localizer.Get("ImageDuplicated")); if (QueryValidationHelper.IsReservedGuid(input.LanguageId)) throw new RequestInputException(localizer.Get("InvalidInputLanguage")); if (input.Tags.Where(tag => QueryValidationHelper.IsReservedGuid(tag)).Any()) throw new RequestInputException(localizer.Get("InvalidTag")); if (input.UsersWithVisibility.Where(userWithVisibility => QueryValidationHelper.IsReservedGuid(userWithVisibility)).Any()) throw new RequestInputException(localizer.Get("InvalidUserWithVisibility")); if (!CardVisibilityHelper.CardIsVisibleToUser(input.VersionCreatorId, input.UsersWithVisibility)) throw new InvalidOperationException(localizer.Get("OwnerMustHaveVisibility")); }
public ImageVersion(GetImageVersions.ResultImageVersion appResult, ILocalized localizer) { VersionUtcDate = appResult.VersionUtcDate; Author = appResult.Author; VersionDescription = appResult.VersionDescription; var fieldsDisplayNames = appResult.ChangedFieldNames.Select(fieldName => localizer.Get(fieldName)); ChangedFieldList = string.Join(',', fieldsDisplayNames); }
public CardVersion(GetCardVersions.IResultCardVersion appResult, ILocalized localizer) { VersionId = appResult.VersionId; VersionUtcDate = appResult.VersionUtcDate; VersionCreator = appResult.VersionCreator; VersionDescription = appResult.VersionDescription; var fieldsDisplayNames = appResult.ChangedFieldNames.Select(fieldName => localizer.Get(fieldName)); ChangedFieldList = string.Join(',', fieldsDisplayNames); }
public GetCardForEditViewModel(GetCardForEdit.ResultModel applicationResult, ILocalized localizer) { FrontSide = applicationResult.FrontSide; BackSide = applicationResult.BackSide; AdditionalInfo = applicationResult.AdditionalInfo; LanguageId = applicationResult.LanguageId; Tags = applicationResult.Tags.Select(tag => new GetAllAvailableTagsViewModel(tag.TagId, tag.TagName)); UsersWithVisibility = applicationResult.UsersWithVisibility.Select(user => new GetUsersViewModel(user.UserId, user.UserName)); CreationUtcDate = applicationResult.FirstVersionUtcDate; LastChangeUtcDate = applicationResult.LastVersionUtcDate; InfoAboutUsage = applicationResult.UsersOwningDeckIncluding.Any() ? localizer.Get("AppearsInDecksOf") + ' ' + string.Join(',', applicationResult.UsersOwningDeckIncluding) : localizer.Get("NotIncludedInAnyDeck"); Images = applicationResult.Images.Select(applicationImage => new GetCardForEditImageViewModel(applicationImage)); CurrentUserRating = applicationResult.UserRating; AverageRating = Math.Round(applicationResult.AverageRating, 1); CountOfUserRatings = applicationResult.CountOfUserRatings; }
public GetAllDeckViewModel(GetDecksWithLearnCounts.Result applicationDeck, ILocalized localizer) { NextExpiryUTCDate = applicationDeck.NextExpiryUTCDate; var lines = new List <string>(); if (applicationDeck.CardCount == 0) { HeadLine = localizer.Get("ThereIsNoCardInYourDeck") + $" <a href=\"/Decks/Index?DeckId={applicationDeck.Id}\">{applicationDeck.Description}</a>."; lines.Add($"<a href=\"/Search/Index\" >{localizer.Get("ClickHereToSearchAndAddCards")}</a>..."); lines.Add($"<a href=\"/Authoring/Index\">{localizer.Get("ClickHereToCreateCards")}</a>..."); } else { HeadLine = $"{localizer.Get("AmongThe")} {applicationDeck.CardCount} {localizer.Get("CardsOfYourDeck")} <a href=\"/Decks/Index?DeckId={applicationDeck.Id}\">{applicationDeck.Description}</a>..."; if (applicationDeck.UnknownCardCount == 0) { lines.Add(localizer.Get("NoUnknownCard")); } else { var linkText = applicationDeck.UnknownCardCount == 1 ? localizer.Get("OneUnknownCard") : $"{applicationDeck.UnknownCardCount} {localizer.Get("UnknownCards")}"; lines.Add($"<a href=\"/Learn/Index?LearnMode=Unknown\">{linkText}</a>"); } if (applicationDeck.ExpiredCardCount == 0) { lines.Add(localizer.Get("NoExpiredCard")); } else { var linkText = applicationDeck.ExpiredCardCount == 1 ? localizer.Get("OneExpiredCard") : $"{applicationDeck.ExpiredCardCount} {localizer.Get("ExpiredCards")}"; lines.Add($"<a href=\"/Learn/Index?LearnMode=Expired\">{linkText}</a>"); } if (applicationDeck.ExpiringNextHourCount == 0) { lines.Add(localizer.Get("NoCardToExpireInTheNextHour")); } else { if (applicationDeck.ExpiringNextHourCount == 1) { lines.Add(localizer.Get("OneCardWillExpireInTheNextHour")); } else { lines.Add($"{applicationDeck.ExpiringNextHourCount} {localizer.Get("CardsWillExpireInTheNextHour")}"); } } if (applicationDeck.ExpiringFollowing24hCount == 0) { lines.Add(localizer.Get("NoCardToExpireInTheFollowing24h")); } else { if (applicationDeck.ExpiringFollowing24hCount == 1) { lines.Add(localizer.Get("OneCardWillExpireInTheFollowing24h")); } else { lines.Add($"{applicationDeck.ExpiringFollowing24hCount} {localizer.Get("CardsWillExpireInTheFollowing24h")}"); } } if (applicationDeck.ExpiringFollowing3DaysCount == 0) { lines.Add(localizer.Get("NoCardToExpireInTheFollowing3Days")); } else { if (applicationDeck.ExpiringFollowing3DaysCount == 1) { lines.Add(localizer.Get("OneCardWillExpireInTheFollowing3Days")); } else { lines.Add($"{applicationDeck.ExpiringFollowing3DaysCount} {localizer.Get("CardsWillExpireInTheFollowing3Days")}"); } } } Lines = lines; }
public static string HeapName(int heap, ILocalized localizer) { return(heap == 0 ? localizer.Get("UnknownCardsHeap") : heap.ToString()); }