本文整理汇总了C#中IContent.As方法的典型用法代码示例。如果您正苦于以下问题:C# IContent.As方法的具体用法?C# IContent.As怎么用?C# IContent.As使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IContent
的用法示例。
在下文中一共展示了IContent.As方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetupViewModel
public void SetupViewModel(FrontendContext frontendContext, IContent node, NodeViewModel viewModel)
{
if (node.ContentItem.ContentType != "WikipediaPage") return;
viewModel.name = node.As<ITitleAspect>().Title;
viewModel.data["url"] = node.As<WikipediaPagePart>().Url;
}
示例2: SetupViewModel
public void SetupViewModel(FrontendContext frontendContext, IContent node, Frontends.Engines.Jit.ViewModels.NodeViewModel viewModel)
{
if (node.ContentItem.ContentType == "AssociativyTagNode")
{
viewModel.name = node.As<IAssociativyNodeLabelAspect>().Label;
}
else viewModel.name = node.As<ITitleAspect>().Title;
}
示例3: GetForum
public static ForumPart GetForum(IContent content) {
var postPart = content.As<PostPart>();
var threadPart = content.As<ThreadPart>();
if (postPart == null) {
return threadPart == null ? null : threadPart.ForumPart;
}
return postPart.ThreadPart.ForumPart;
}
示例4: ConvertBatchToNotification
public INotification ConvertBatchToNotification(IContent notificationBatch, IUser recipient)
{
return new Notification
{
Id = notificationBatch.ContentItem.Id,
ContentItem = notificationBatch.ContentItem,
TitleLazy = new Lazy<string>(() => _tokenizer.Replace(notificationBatch.As<TitlePart>().Title, new { User = recipient })),
BodyLazy = new Lazy<string>(() => _tokenizer.Replace(notificationBatch.As<BodyPart>().Text, new { User = recipient }))
};
}
示例5: SetupViewModel
public void SetupViewModel(FrontendContext frontendContext, IContent node, NodeViewModel viewModel)
{
// .Has<> doesn't work here
if (node.As<ITitleAspect>() != null) viewModel.name = node.As<ITitleAspect>().Title;
if (node.As<IAliasAspect>() != null)
{
viewModel.data["url"] = new UrlHelper(_orchardServices.WorkContext.HttpContext.Request.RequestContext)
.RouteUrl(_orchardServices.ContentManager.GetItemMetadata(node).DisplayRouteValues);
}
}
示例6:
void ILocalizationService.SetContentCulture(IContent content, string culture) {
var localized = content.As<LocalizationPart>();
if (localized == null || localized.MasterContentItem == null)
return;
localized.Culture = _cultureManager.GetCultureByName(culture);
}
示例7:
IEnumerable<LocalizationPart> ILocalizationService.GetLocalizations(IContent content, VersionOptions versionOptions) {
if (content.ContentItem.Id == 0)
return Enumerable.Empty<LocalizationPart>();
var localized = content.As<LocalizationPart>();
var query = versionOptions == null
? _contentManager.Query<LocalizationPart>(localized.ContentItem.ContentType)
: _contentManager.Query<LocalizationPart>(versionOptions, localized.ContentItem.ContentType);
int contentItemId = localized.ContentItem.Id;
if (localized.HasTranslationGroup) {
int masterContentItemId = localized.MasterContentItem.ContentItem.Id;
query = query.Where<LocalizationPartRecord>(l =>
l.Id != contentItemId // Exclude the content
&& (l.Id == masterContentItemId || l.MasterContentItemId == masterContentItemId));
}
else {
query = query.Where<LocalizationPartRecord>(l =>
l.MasterContentItemId == contentItemId);
}
// Warning: May contain more than one localization of the same culture.
return query.List().ToList();
}
示例8: GetTextDirection
public static string GetTextDirection(this WorkContext workContext, IContent content) {
var culture = workContext.CurrentSite.SiteCulture;
if (content != null && content.Has<ILocalizableAspect>()) {
culture = content.As<ILocalizableAspect>().Culture ?? culture;
}
return CultureInfo.GetCultureInfo(culture).TextInfo.IsRightToLeft ? "rtl" : "ltr"; ;
}
示例9: GetTemplates
private IList<LayoutPart> GetTemplates(IContent content = null) {
var query = _layoutManager.GetTemplates();
var layoutPart = content != null ? content.As<LayoutPart>() : null;
if (layoutPart != null) {
query = query.Where(x => x.Id != layoutPart.Id);
}
return query.ToList();
}
示例10: HasOwnership
private static bool HasOwnership(IUser user, IContent content) {
if (user == null || content == null)
return false;
var common = content.As<ICommonPart>();
if (common == null || common.Owner == null)
return false;
return user.Id == common.Owner.Id;
}
示例11: HasOwnership
private static bool HasOwnership(IUser user, IContent content)
{
if (user == null || content == null)
return false;
if (content.Is<CustomerPart>()) {
var customer = content.As<CustomerPart>();
return customer != null && user.Id == customer.UserId;
}
else if (content.Is<CustomerAddressPart>()) {
var address = content.As<CustomerAddressPart>();
return address != null && address.Customer != null && user.Id == address.Customer.UserId;
}
else if (content.Is<CustomerOrderPart>()) {
var order = content.As<CustomerOrderPart>();
return order != null && order.Customer != null && user.Id == order.Customer.UserId;
}
return false;
}
示例12: Invalidate
private void Invalidate(IContent content) {
// remove any page tagged with this content item id
_cacheService.RemoveByTag(content.ContentItem.Id.ToString(CultureInfo.InvariantCulture));
// search the cache for containers too
var commonPart = content.As<CommonPart>();
if (commonPart != null) {
if (commonPart.Container != null) {
_cacheService.RemoveByTag(commonPart.Container.Id.ToString(CultureInfo.InvariantCulture));
}
}
}
示例13: BuildOrder
public void BuildOrder(IShoppingCartService ShoppingCartService, IContent Order)
{
// Attach VAT infos to OrderDetails
var orderPart = Order.As<OrderPart>();
if (orderPart != null) {
var vatParts = _contentManager.GetMany<VatPart>(orderPart.Details.Select(d => d.ContentId), VersionOptions.Published, QueryHints.Empty);
foreach(var vatDetailPair in orderPart.Details.Join(vatParts, od => od.ContentId, vat => vat.Id, (od, vat) => new { Detail = od, Vat = vat})) {
if (vatDetailPair.Vat.VatRate != null) {
vatDetailPair.Detail.SetProperty("VAT", new Tax(vatDetailPair.Vat.VatRate));
}
}
}
}
示例14: BuildOrder
public void BuildOrder(IShoppingCartService ShoppingCartService, IContent Order)
{
var orderPart = Order.As<OrderPart>();
if (orderPart != null) {
var cartRecords = ShoppingCartService.ListItems();
var products = ListProducts(cartRecords);
foreach (var cartRecord in cartRecords.Where(cr => cr.ItemType == ProductPart.PartItemType)) {
var product = products.Where(p => p.Id == cartRecord.ItemId).FirstOrDefault();
if (product != null) {
orderPart.Details.Add(new OrderDetail(product, cartRecord.Quantity));
}
}
}
}
示例15: OrderDetailUpdated
public void OrderDetailUpdated(IContent order, OrderDetailRecord originalDetail, OrderDetailRecord updatedDetail)
{
if(originalDetail.ContentId == updatedDetail.ContentId) {
var orderPart = order.As<OrderPart>();
var stockPart = _contentManager.Get(updatedDetail.ContentId).As<StockPart>();
if (stockPart != null && stockPart.EnableStockMgmt && orderPart != null) {
if(orderPart.OriginalStatus != orderPart.OrderStatus) {
// OrderStatus changed
if (orderPart.OriginalStatus == OrderStatus.Canceled) {
if(orderPart.OrderStatus < OrderStatus.Completed) {
stockPart.InOrderQty += updatedDetail.Quantity;
}
else {
stockPart.InStockQty -= updatedDetail.Quantity;
}
}
else if (orderPart.OriginalStatus < OrderStatus.Completed) {
if (orderPart.OrderStatus == OrderStatus.Canceled) {
stockPart.InOrderQty -= originalDetail.Quantity;
}
else if (orderPart.OrderStatus == OrderStatus.Completed) {
stockPart.InOrderQty -= originalDetail.Quantity;
stockPart.InStockQty -= updatedDetail.Quantity;
}
else {
stockPart.InOrderQty += updatedDetail.Quantity - originalDetail.Quantity;
}
}
else {
stockPart.InStockQty += originalDetail.Quantity;
if (orderPart.OrderStatus != OrderStatus.Canceled) {
stockPart.InOrderQty += updatedDetail.Quantity;
}
}
}
else {
// OrderStatus unchanged
if (originalDetail.Quantity != updatedDetail.Quantity) {
stockPart.InOrderQty += updatedDetail.Quantity - originalDetail.Quantity;
}
}
}
}
else {
OrderDetailDeleted(order, originalDetail);
OrderDetailCreated(order, updatedDetail);
}
}