当前位置: 首页>>代码示例>>C#>>正文


C# ContentItem.As方法代码示例

本文整理汇总了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;
        }
开发者ID:MichaelPetrinolis,项目名称:Orchard2,代码行数:23,代码来源:ContainedPartDisplayDriver.cs

示例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;
        }
开发者ID:JustGiving,项目名称:Tad.ContentSync,代码行数:31,代码来源:ContentItemExtensions.cs

示例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);
            }
        }
开发者ID:prakasha,项目名称:Orchard1.4,代码行数:26,代码来源:PostHandler.cs

示例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)))
                );
        }
开发者ID:MichaelPetrinolis,项目名称:Orchard2,代码行数:33,代码来源:TestContentDisplay.cs

示例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);
            }
        }
开发者ID:richinoz,项目名称:Orchard1.6,代码行数:28,代码来源:BundleService.cs

示例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);
 }
开发者ID:sclarson,项目名称:CodeCamp,代码行数:9,代码来源:PresentationService.cs

示例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;
 }
开发者ID:JustGiving,项目名称:Tad.ContentSync,代码行数:9,代码来源:ContentItemExtensions.cs

示例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);
        }
开发者ID:modulexcite,项目名称:Transformalize,代码行数:9,代码来源:TransformalizeTaskManager.cs

示例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");
        }
开发者ID:MichaelPetrinolis,项目名称:Orchard2,代码行数:11,代码来源:TestContentDisplay.cs

示例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);
        }
开发者ID:Timbioz,项目名称:SciGitAzure,代码行数:11,代码来源:Shapes.cs

示例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;
        }
开发者ID:richinoz,项目名称:Orchard1.6,代码行数:14,代码来源:PrettyGalleryService.cs

示例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);
                }
		}
开发者ID:akhurst,项目名称:ricealumni,代码行数:36,代码来源:ContentNotificationService.cs

示例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;
        }
开发者ID:ShuanWang,项目名称:devoffice.com-shuanTestRepo,代码行数:15,代码来源:StepDataService.cs

示例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);
        }
开发者ID:richinoz,项目名称:Orchard1.6,代码行数:17,代码来源:MovieHandler.cs

示例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++;
            }
        }
开发者ID:rgardler,项目名称:dpp,代码行数:19,代码来源:ImageService.cs


注:本文中的Orchard.ContentManagement.ContentItem.As方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。