protected override DriverResult Editor(TagsPart part, IUpdateModel updater, dynamic shapeHelper) { var model = new EditTagsViewModel(); updater.TryUpdateModel(model, Prefix, null, null); var tagNames = TagHelpers.ParseCommaSeparatedTagNames(model.Tags); // as the tag names are used in the route directly, prevent them from having ASP.NET disallowed chars // c.f., http://www.hanselman.com/blog/ExperimentsInWackinessAllowingPercentsAnglebracketsAndOtherNaughtyThingsInTheASPNETIISRequestURL.aspx var disallowedTags = tagNames.Where(x => DisalowedChars.Intersect(x).Any()).ToList(); if (disallowedTags.Any()) { _notifier.Warning(T("The tags \"{0}\" could not be added because they contain forbidden chars: {1}", String.Join(", ", disallowedTags), String.Join(", ", DisalowedChars))); tagNames = tagNames.Where(x => !disallowedTags.Contains(x)).ToList(); } if (part.ContentItem.Id != 0) { _tagService.UpdateTagsForContentItem(part.ContentItem, tagNames); } return(ContentShape("Parts_Tags_Edit", () => shapeHelper.EditorTemplate(TemplateName: TemplateName, Model: model, Prefix: Prefix))); }
protected override DriverResult Editor(TagsPart part, IUpdateModel updater, dynamic shapeHelper) { var model = new EditTagsViewModel(); updater.TryUpdateModel(model, Prefix, null, null); var tagNames = TagHelpers.ParseCommaSeparatedTagNames(model.Tags); if (part.ContentItem.Id != 0) { _tagService.UpdateTagsForContentItem(part.ContentItem, tagNames); } return(ContentShape("Parts_Tags_Edit", () => shapeHelper.EditorTemplate(TemplateName: TemplateName, Model: model, Prefix: Prefix))); }
private void MetaWeblogUpdateTags(int contentItemId, string userName, string password, XRpcStruct content, bool publish, ICollection <IXmlRpcDriver> drivers) { List <LocalizedString> validationErrors; var user = _membershipService.ValidateUser(userName, password, out validationErrors); var rawTags = content.Optional <string>("mt_keywords"); if (string.IsNullOrWhiteSpace(rawTags)) { return; } var tags = TagHelpers.ParseCommaSeparatedTagNames(rawTags); var driver = new XmlRpcDriver(item => { if (!(item is int)) { return; } var id = (int)item; var contentItem = _contentManager.Get(id, VersionOptions.Latest); if (contentItem == null) { return; } _orchardServices.WorkContext.CurrentUser = user; _tagService.UpdateTagsForContentItem(contentItem, tags); }); if (contentItemId > 0) { driver.Process(contentItemId); } else { drivers.Add(driver); } }