Example #1
0
            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);
            }
Example #2
0
            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);
            }
Example #3
0
            private async Task CheckNewVisibilityAsync(Card card, ILocalized localizer, MemCheckDbContext dbContext)
            {
                if (!UsersWithVisibility.Any())
                {
                    return;
                }
                await CheckVisibilityForUsersAsync(await GetAllAuthorsAsync(card, dbContext), localizer, "HeCreatedAVersionOfThisCard", dbContext);

                IEnumerable <Guid> userIds = await GetAllUsersWithCardInADeckAsync(dbContext);

                await CheckVisibilityForUsersAsync(userIds, localizer, "HeHasThisCardInADeck", dbContext);
            }
Example #4
0
        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"));
        }
Example #5
0
 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") + ")");
         }
     }
 }
Example #6
0
 public static void CheckCanCreateImageWithDescription(string description, ILocalized localizer)
 {
     if (description != description.Trim())
     {
         throw new InvalidOperationException("Invalid description: not trimmed");
     }
     if (description.Length < ImageMinDescriptionLength || description.Length > ImageMaxDescriptionLength)
     {
         throw new RequestInputException(localizer.Get("InvalidDescriptionLength") + $" {description.Length}, " + localizer.Get("MustBeBetween") + $" {ImageMinDescriptionLength} " + localizer.Get("And") + $" {ImageMaxDescriptionLength}");
     }
     foreach (var forbiddenChar in ForbiddenCharsInImageDescription)
     {
         if (description.Contains(forbiddenChar))
         {
             throw new RequestInputException(localizer.Get("InvalidImageDescription") + " '" + description + "' ('" + forbiddenChar + ' ' + localizer.Get("IsForbidden") + ")");
         }
     }
 }
Example #7
0
 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;
 }
Example #8
0
        public static T Value <T>(this ILocalized <T> localized, Language language)
            where T : class
        {
            switch (language)
            {
            case Language.En:
                return(localized.En);

            case Language.Fr:
                return(localized.Fr ?? localized.En);

            case Language.De:
                return(localized.De ?? localized.En);

            case Language.It:
                return(localized.It ?? localized.En);

            case Language.Ja:
                return(localized.Ja ?? localized.En);

            case Language.Ko:
                return(localized.Ko ?? localized.En);

            case Language.Ru:
                return(localized.Ru ?? localized.En);

            case Language.Zh:
                return(localized.Zh ?? localized.En);

            case Language.Pt:
                return(localized.Pt ?? localized.En);

            case Language.Tr:
                return(localized.Tr ?? localized.En);

            case Language.Pl:
                return(localized.Pl ?? localized.En);

            default:
                throw new ArgumentOutOfRangeException(nameof(language), language, null);
            }
        }
Example #9
0
		public ActionResult ChangeCulture(string culture)
		{
			if (String.IsNullOrEmpty(culture)) {
				return JsonError("Культура не указана", JsonRequestBehavior.AllowGet);
			}

			ILocalized localized = HttpContext.ApplicationInstance as ILocalized;

			if (localized == null) {
				return JsonError("Приложение не поддерживает смену языка/культуры.", JsonRequestBehavior.AllowGet);
			}

			if (!localized.SetCulture(culture)) {
				return JsonError("Культура не найдена", JsonRequestBehavior.AllowGet);
			}
			UserContext.Culture = culture;
			//Kesco.ApplicationServices.Manager.SaveUserLanguage(culture.Substring(0, 2));

			return JsonModel(culture, JsonRequestBehavior.AllowGet);
		}
Example #10
0
            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"));
                }
            }
Example #11
0
 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"));
     }
 }
Example #12
0
        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);
        }
Example #13
0
 public static string HeapName(int heap, ILocalized localizer)
 {
     return(heap == 0 ? localizer.Get("UnknownCardsHeap") : heap.ToString());
 }
Example #14
0
 public GetImageListViewModel(GetImageList.Result applicationResult, ILocalized localizer)
 {
     TotalCount = applicationResult.TotalCount;
     PageCount  = applicationResult.PageCount;
     Images     = applicationResult.Images.Select(img => new GetImageListImageViewModel(img, localizer));
 }
Example #15
0
 public GetUserDecksWithHeapsViewModel(Guid deckId, string description, string heapingAlgorithmName, string heapingAlgorithmDescription, int cardCount, IEnumerable <GetUserDecksWithHeaps.ResultHeap> heaps, ILocalized localizer)
 {
     DeckId                      = deckId;
     Description                 = description;
     HeapingAlgorithmName        = heapingAlgorithmName;
     HeapingAlgorithmDescription = heapingAlgorithmDescription;
     CardCount                   = cardCount;
     Heaps = heaps.Select(heap => new GetUserDecksWithHeapsHeapViewModel(heap.HeapId, DisplayServices.HeapName(heap.HeapId, localizer), heap.TotalCardCount, heap.ExpiredCardCount, heap.NextExpiryUtcDate));
 }
Example #16
0
            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));
                }
            }
Example #17
0
            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);
                }
            }
Example #18
0
            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)}'");
            }
Example #19
0
            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 + "'";
            }
Example #20
0
            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)}");
                    }
                }
            }
Example #21
0
            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;
            }
Example #22
0
 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;
 }
Example #23
0
 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;
 }
Example #24
0
            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;
            }
Example #25
0
 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());
     }
 }
Example #26
0
 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")}");
     }
 }
Example #27
0
 public HitEvent(ILocalized attacker, ILocalized defender)
 {
     _attacker = attacker;
     _defender = defender;
 }
Example #28
0
        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"));
                }
            }
        }