Пример #1
0
        private async Task ProcessSlugs(Product product, Product clone, IEnumerable <Language> languages)
        {
            var slugResult = await _urlService.ValidateSlugAsync(clone, clone.Name, true);

            await _urlService.ApplySlugAsync(slugResult, true);

            foreach (var lang in languages)
            {
                string name = product.GetLocalized(x => x.Name, lang, false, false);

                slugResult = await _urlService.ValidateSlugAsync(clone, name, false, lang.Id);

                await _urlService.ApplySlugAsync(slugResult, true);
            }
        }
Пример #2
0
        public async Task <IActionResult> Create(TopicModel model, bool continueEditing)
        {
            if (ModelState.IsValid)
            {
                if (!model.IsPasswordProtected)
                {
                    model.Password = null;
                }

                // TODO: (mh) (core) Implement & use mapping extensions.
                var topic = await MapperFactory.MapAsync <TopicModel, Topic>(model);

                if (model.WidgetZone != null)
                {
                    topic.WidgetZone = string.Join(',', model.WidgetZone);
                }

                topic.CookieType = (CookieType?)model.CookieType;

                _db.Topics.Add(topic);
                await _db.SaveChangesAsync();

                var slugResult = await topic.ValidateSlugAsync(model.SeName, true);

                model.SeName = slugResult.Slug;
                await _urlService.ApplySlugAsync(slugResult, true);

                await SaveStoreMappingsAsync(topic, model.SelectedStoreIds);
                await SaveAclMappingsAsync(topic, model.SelectedCustomerRoleIds);
                await UpdateLocalesAsync(topic, model);

                AddCookieTypes(model, model.CookieType);

                await Services.EventPublisher.PublishAsync(new ModelBoundEvent(model, topic, Request.Form));

                NotifySuccess(T("Admin.ContentManagement.Topics.Updated"));
                return(continueEditing ? RedirectToAction("Edit", new { id = topic.Id }) : RedirectToAction("List"));
            }

            // If we got this far something failed. Redisplay form.
            return(View(model));
        }
Пример #3
0
        /// <summary>
        /// Applies a slug without sanitization or uniqueness check. This method
        /// throws if the given slug already exists in the database. The recommended
        /// way to apply a slug is to call <see cref="IUrlService.ValidateSlugAsync{T}(T, string, bool, int?)"/>
        /// first, then to call <see cref="IUrlService.ApplySlugAsync(ValidateSlugResult, bool)"/> by passing
        /// the return value from first call.
        /// </summary>
        /// <typeparam name="T">Type of slug supporting entity</typeparam>
        /// <param name="entity">Entity instance</param>
        /// <param name="slug">Slug to apply</param>
        /// <param name="languageId">Language ID</param>
        /// <param name="save"><c>true</c> will commit result to database.</param>
        /// <returns>
        /// The affected <see cref="UrlRecord"/> instance, either new or existing as tracked entity.
        /// </returns>
        public static Task <UrlRecord> ApplySlugAsync <T>(this IUrlService service, T entity, string slug, int languageId, bool save = false)
            where T : ISlugSupported
        {
            Guard.NotNull(entity, nameof(entity));

            var input = new ValidateSlugResult
            {
                Source     = entity,
                Slug       = slug,
                LanguageId = languageId
            };

            return(service.ApplySlugAsync(input, save));
        }