Example #1
0
        public Task GenerateStoreSlugAsync(User user)
        {
            user.StoreSlug = SanitizerHelper.GenerateSlug($"{user.StoreName}",
                                                          slug => Users.Any(x => x.Id != user.Id && x.StoreSlug == slug));

            return(Task.CompletedTask);
        }
Example #2
0
        protected Task GenerateSlugAsync(Product product)
        {
            product.Slug = SanitizerHelper.GenerateSlug(product.Name,
                                                        productSlug => GetQuery().Any(x => x.SellerId == product.SellerId && x.Id != product.Id && x.Slug == productSlug));

            return(Task.CompletedTask);
        }
Example #3
0
        public Task PrepareStoreAsync(User user, StoreEditModel model)
        {
            if (user == null)
            {
                throw new ArgumentNullException(nameof(user));
            }
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }

            user = _mapper.Map(model, user);

            user.StoreCategory = model.StoreCategorySelections.MergeEnums();

            user.StoreSlug = SanitizerHelper.GenerateSlug(model.StoreSlug);

            user.AboutNote   = SanitizerHelper.SanitizeHtml(model.AboutNote);
            user.TermsNote   = SanitizerHelper.SanitizeHtml(model.TermsNote);
            user.PrivacyNote = SanitizerHelper.SanitizeHtml(model.PrivacyNote);
            user.ReturnsNote = SanitizerHelper.SanitizeHtml(model.ReturnsNote);
            user.ReviewsNote = SanitizerHelper.SanitizeHtml(model.ReviewsNote);


            user.FacebookLink   = SanitizerHelper.AppendUrlScheme(model.FacebookLink);
            user.TwitterLink    = SanitizerHelper.AppendUrlScheme(model.TwitterLink);
            user.YoutubeLink    = SanitizerHelper.AppendUrlScheme(model.YoutubeLink);
            user.InstagramLink  = SanitizerHelper.AppendUrlScheme(model.InstagramLink);
            user.LinkedInLink   = SanitizerHelper.AppendUrlScheme(model.LinkedInLink);
            user.PinterestLink  = SanitizerHelper.AppendUrlScheme(model.PinterestLink);
            user.WhatsAppNumber = SanitizerHelper.ExtractPhoneNumber(model.WhatsAppNumber);
            user.MapLink        = SanitizerHelper.AppendUrlScheme(model.MapLink);

            return(Task.CompletedTask);
        }
Example #4
0
        public Task GenerateSlugAsync(Category category, bool uniqueness = true)
        {
            bool slugExists(string slug) => GetQuery().Any(x => x.SellerId == category.SellerId && x.Id != category.Id && x.Slug == slug);

            category.Slug = SanitizerHelper.GenerateSlug(category.Name,
                                                         uniqueness ? (Func <string, bool>)slugExists : null);

            return(Task.CompletedTask);
        }
Example #5
0
        private async Task SaveProductTags(Product product, ProductEditModel model)
        {
            var tagObjects = product.Tags.ToList();

            // Ensure the newTageNames are safe to access.
            var newTagNames = model.TagNames?.Where(x => !string.IsNullOrWhiteSpace(x)) ?? Enumerable.Empty <string>();
            var oldTagNames = tagObjects.Select(x => x.Name).ToList();

            var createTagNames = newTagNames.Except(oldTagNames);
            var deleteTagNames = oldTagNames.Except(newTagNames);

            bool tagPredicate(Tag tag, string slug, string name) => tag.Slug == slug || tag.Name == name;

            foreach (var tagName in deleteTagNames)
            {
                var tagSlug   = SanitizerHelper.GenerateSlug(tagName);
                var tagObject = tagObjects.FirstOrDefault(x => tagPredicate(x, tagSlug, tagName));

                if (tagObject != null)
                {
                    tagObjects.Remove(tagObject);
                    await _tagService.DeleteAsync(tagObject);
                }
            }

            foreach (var tagName in createTagNames)
            {
                var tagSlug = SanitizerHelper.GenerateSlug(tagName);

                if (!tagObjects.Any(x => tagPredicate(x, tagSlug, tagName)))
                {
                    var tagObject = new Tag
                    {
                        Name      = tagName,
                        ProductId = product.Id,
                        Slug      = tagSlug
                    };

                    tagObjects.Add(tagObject);
                    await _tagService.CreateAsync(tagObject);
                }
            }
        }
Example #6
0
        public static IRuleBuilderOptions <T, string> Slug <T>(this IRuleBuilder <T, string> ruleBuilder)
        {
            var options = ruleBuilder
                          .MinimumLength(3)
                          .MaximumLength(255)
                          .Must(x => string.IsNullOrWhiteSpace(x) || !string.IsNullOrWhiteSpace(SanitizerHelper.GenerateSlug(x)))
                          .WithMessage(ValidationHelper.SlugRegexMessage);

            return(options);
        }
Example #7
0
 public Task GenerateUserNameAsync(User user)
 {
     user.UserName = SanitizerHelper.GenerateSlug($"{user.FirstName} {user.LastName}",
                                                  userName => Users.Any(x => x.Id != user.Id && x.UserName == userName));
     return(Task.CompletedTask);
 }