本文整理汇总了C#中Orchard.ContentManagement.ContentItem.As方法的典型用法代码示例。如果您正苦于以下问题:C# ContentItem.As方法的具体用法?C# ContentItem.As怎么用?C# ContentItem.As使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Orchard.ContentManagement.ContentItem
的用法示例。
在下文中一共展示了ContentItem.As方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: EditAsync
public override async Task<IDisplayResult> EditAsync(ContentItem model, IUpdateModel updater)
{
// This method can get called when a new content item is created, at that point
// the query string contains a ListPart.ContainerId value, or when an
// existing content item has ContainedPart value. In both cases the hidden field
// needs to be rendered in the edit form to maintain the relationship with the parent.
if (model.Is<ContainedPart>())
{
return BuildShape(model.As<ContainedPart>().ListContentItemId);
}
var viewModel = new EditContainedPartViewModel();
if ( await updater.TryUpdateModelAsync(viewModel, "ListPart"))
{
// We are editing a content item that needs to be added to a container
// so we render the container id as part of the form
return BuildShape(viewModel.ContainerId);
}
return null;
}
示例2: AreEqual
private static bool AreEqual(ContentItem item1, ContentItem item2, XElement item1Export, XElement item2Export)
{
//todo: this is a little too generous
if (!item1.SharesIdentifierWith(item2))
return false;
if (item1.Has<TitlePart>() && item2.Has<TitlePart>())
{
if (!item1.As<TitlePart>().Title.Equals(item2.As<TitlePart>().Title, StringComparison.CurrentCulture))
{
return false;
}
}
if (item1.Has<BodyPart>() && item2.Has<BodyPart>())
{
var text1 = item1.As<BodyPart>().Text;
var text2 = item2.As<BodyPart>().Text;
if (text1 == null || text2 == null)
return false;
if (!item1.As<BodyPart>().Text.Equals(item2.As<BodyPart>().Text, StringComparison.CurrentCulture))
{
return false;
}
}
// compare xml elements
return Differences(item1Export, item2Export) == 0;
}
示例3: sendEmail
public void sendEmail(int idMenu, ContentItem item)
{
var slug = item.As<RoutePart>().Slug;
var request = httpContextAccessor.Current().Request;
var containerUrl = new UriBuilder(request.ToRootUrlString()) { Path = (request.ApplicationPath ?? "").TrimEnd('/') + "/" + (item.As<RoutePart>().GetContainerPath() ?? "") };
var link = containerUrl.Uri.ToString().TrimEnd('/');
var menu = menuService.Get(idMenu);
var course = courseService.Get(menu.Course.Id);
var year = yearService.Get(course.Year.Id);
var props = new Dictionary<string, string> {
{ "ContentTypeName", item.ContentType },
{ "Title", ContentHelper.tryGetRouteTitle(item) },
{ "Link", link + slug},
{ "Year", year.Name},
{ "Course", course.Name},
{ "CourseMenu", menu.Name}
};
var users = mailRepo.Fetch(x => x.Menu.Id == idMenu).Select(x => membershipService.GetUser(x.UserName));
foreach (var user in users)
{
messageManager.Send(user.ContentItem.Record, MessageTypes.MailNotification, "email", props);
}
}
示例4: Display
public override IDisplayResult Display(ContentItem contentItem, IUpdateModel updater)
{
var testContentPart = contentItem.As<TestContentPartA>();
if (testContentPart == null)
{
return null;
}
return Combine(
// A new shape is created and the properties of the object are bound to it when rendered
Shape("TestContentPartA", testContentPart).Location("Detail", "Content"),
// New shape, no initialization, custom location
Shape("LowerDoll").Location("Detail", "Footer"),
// New shape
Shape("TestContentPartA",
ctx => ctx.New.TestContentPartA().Creating(_creating++),
shape =>
{
shape.Processing = _processing++;
return Task.CompletedTask;
})
.Location("Detail", "Content")
.Cache("lowerdoll2", cache => cache.During(TimeSpan.FromSeconds(5))),
// A strongly typed shape model is used and initialized when rendered
Shape<TestContentPartAShape>(shape => { shape.Line = "Strongly typed shape"; return Task.CompletedTask; })
.Location("Detail", "Content:2"),
// Cached shape
Shape("LowerDoll")
.Location("Detail", "/Footer")
.Cache("lowerdoll", cache => cache.During(TimeSpan.FromSeconds(5)))
);
}
示例5: UpdateBundleProducts
public void UpdateBundleProducts(ContentItem item, IEnumerable<ProductEntry> products) {
var record = item.As<BundlePart>().Record;
var oldProducts = _bundleProductsRepository.Fetch(
r => r.BundlePartRecord == record);
var lookupNew = products
.Where(e => e.Quantity > 0)
.ToDictionary(r => r.ProductId, r => r.Quantity);
// Delete the products that are no longer there
// and updtes the ones that should stay
foreach (var bundleProductRecord in oldProducts) {
var key = bundleProductRecord.ContentItemRecord.Id;
if (lookupNew.ContainsKey(key)) {
bundleProductRecord.Quantity = lookupNew[key];
_bundleProductsRepository.Update(bundleProductRecord);
lookupNew.Remove(key);
}
else {
_bundleProductsRepository.Delete(bundleProductRecord);
}
}
// Add the new products
foreach (var productQuantity in lookupNew
.Where(kvp => kvp.Value > 0)
.Select(kvp => new ProductQuantity {ProductId = kvp.Key, Quantity = kvp.Value})) {
AddProduct(productQuantity.Quantity, productQuantity.ProductId, record);
}
}
示例6: UpdatePresentationForContentItem
public void UpdatePresentationForContentItem(
ContentItem item, EditPresentationViewModel model)
{
var presentationPart = item.As<PresentationPart>();
presentationPart.Abstract = model.Abstract;
presentationPart.Name = model.Name;
presentationPart.Speaker = _speakerRepository.Get(
s => s.Id == model.SpeakerId);
}
示例7: SharesIdentifierWith
public static bool SharesIdentifierWith(this ContentItem item1, ContentItem item2)
{
if (item1.Has<IdentityPart>() && item2.Has<IdentityPart>())
{
return item1.As<IdentityPart>().Identifier.Equals(item2.As<IdentityPart>().Identifier,
StringComparison.InvariantCultureIgnoreCase);
}
return false;
}
示例8: CreateTask
public void CreateTask(ContentItem item) {
var name = TransformalizeTaskHandler.GetName(item.As<TitlePart>().Title);
var tasks = _manager.GetTasks(name);
if (tasks != null && tasks.Any())
return;
_manager.CreateTask(name, DateTime.UtcNow.AddSeconds(30), item);
}
示例9: Edit
public override IDisplayResult Edit(ContentItem contentItem, IUpdateModel updater)
{
var testContentPart = contentItem.As<TestContentPartA>();
if (testContentPart == null)
{
return null;
}
return Shape("TestContentPartA_Edit", testContentPart).Location("Content");
}
示例10: GetUniqueIdentifier
public string GetUniqueIdentifier(ContentItem item)
{
string slug = null;
if (item.Has<AutoroutePart>())
{
var route = item.As<AutoroutePart>();
slug = route.Path;
}
return string.Format("{0} {1}", item.Id, slug);
}
示例11: UpdatePrettyGalleryForContentItem
public void UpdatePrettyGalleryForContentItem(
ContentItem item,
EditPrettyGalleryViewModel model)
{
var prettyGalleryPart = item.As<PrettyGalleryPart>();
prettyGalleryPart.Description = model.Description;
prettyGalleryPart.MediaPath = model.MediaPath;
prettyGalleryPart.PrettyParameters = SerializePrettyParams(model.PrettyParams);
prettyGalleryPart.ThumbnailHeight = model.ThumbnailHeight;
prettyGalleryPart.ThumbnailWidth = model.ThumbnailWidth;
prettyGalleryPart.Layout = model.Layout;
prettyGalleryPart.Mode = (Mode)model.Mode;
}
示例12: SendNotification
public void SendNotification(NotificationTypePartSettings settings, ContentItem subject) {
List<IUser> users = String.IsNullOrWhiteSpace(settings.UsersToNotify)
? new List<IUser>()
: settings.UsersToNotify.Split(new[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries)
.Select(s => _membershipService.GetUser(s)).ToList();
if (settings.NotifyOwner)
{
users.Add(subject.As<CommonPart>().Owner);
}
if (settings.NotifyContainerOwner)
{
// Ignore this for now
var common = subject.As<ICommonPart>();
var container = common.Container;
if (container!=null) {
users.Add(container.As<ICommonPart>().Owner);
}
}
// Set up some values before we perform send
var routable = subject.As<IRoutableAspect>();
var title = routable==null?"...":routable.Title;
var props = new Dictionary<string, string> {
{ "PublishedUrl",GetItemDisplayUrl(subject) },
{ "ContentTypeName", subject.ContentType },
{ "Title", title }
};
foreach ( var recipient in users ) {
if (recipient==null) {
continue;
}
_messageManager.Send(recipient.ContentItem.Record, settings.MessageType,
// TODO: Support other channels
"email" , props);
}
}
示例13: GetStepsForContentItem
public List<StepInformationRecord> GetStepsForContentItem(ContentItem item) {
var stepPart = item.As<StepPart>();
if (stepPart != null)
{
var steps = _stepInformationRepository.Fetch(s => s.StepPartId == stepPart.Id && !s.IsDeleted).OrderBy(s => s.Position).ToList();
foreach (var step in steps) {
step.Substeps = _substepInformationRepository.Fetch(s => s.StepInformationRecord == step && !s.IsDeleted).OrderBy(s => s.Position).ToList();
}
return steps;
}
return null;
}
示例14: GetRelatedMovies
private IEnumerable<ContentItem> GetRelatedMovies(ContentItem displayedMovie) {
var searchBuilder = GetSearchBuilder();
var movie = displayedMovie.As<MoviePart>();
// foo,bar,fizz buzz => "foo" "bar" "fizz buzz"
var keywords = string.Join(" ", movie.Keywords.Split(',').Select(k => '"' + k + '"'));
var relatedItemIds = searchBuilder
.WithField("type", "Movie").Mandatory().ExactMatch()
.Parse("movie-keywords", keywords).Mandatory()
.Search()
.Where(h => h.ContentItemId != displayedMovie.Id)
.Select(h => h.ContentItemId)
.Take(5).ToList();
return _contentManager.GetMany<ContentItem>(relatedItemIds, VersionOptions.Published, QueryHints.Empty);
}
示例15: UpdateImagesForContentItem
public void UpdateImagesForContentItem(ContentItem item, List<string> urls)
{
var imageSetPart = item.As<ImageSetPart>().Record;
var oldImageList = _imageSetItemRepository.Table.Where(i => i.ImageSet.Id == item.Id).ToList();
foreach (var oldImageRecord in oldImageList) {
_imageSetItemRepository.Delete(oldImageRecord);
}
var position = 0;
foreach (var url in urls) {
_imageSetItemRepository.Create(new ImageSetItemRecord
{
Url = url,
Position = position,
ImageSet = imageSetPart
});
position++;
}
}