コード例 #1
1
        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
0
        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
0
ファイル: PostHandler.cs プロジェクト: prakasha/Orchard1.4
        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
0
        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
0
ファイル: BundleService.cs プロジェクト: richinoz/Orchard1.6
        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
0
 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
0
 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
0
        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
0
        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
0
ファイル: Shapes.cs プロジェクト: Timbioz/SciGitAzure
        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
0
        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
0
		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
0
        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
0
ファイル: MovieHandler.cs プロジェクト: richinoz/Orchard1.6
        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
0
ファイル: ImageService.cs プロジェクト: rgardler/dpp
        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++;
            }
        }
コード例 #16
0
        public void UpdateStepsForContentItem(ContentItem item, IEnumerable<StepInformationRecord> steps) 
        {
            var record = item.As<StepPart>().Record;

            var oldSteps = steps.Where(s => s.Id != -1);
            var newSteps = steps.Where(s => s.Id == -1);

            foreach (var oldStep in oldSteps) 
            {
                oldStep.StepPartId = record.Id;
                UpdateSubstepForStep(oldStep);
                _stepInformationRepository.Update(oldStep);
            }

            foreach (var newStep in newSteps) 
            {
                newStep.StepPartId = record.Id;
                newStep.CreateDate = DateTime.UtcNow;
                _stepInformationRepository.Create(newStep);
                UpdateSubstepForStep(newStep);
            }
        }
コード例 #17
0
          public void UpdateRowsWithTiles(ContentItem item, RowWithTilesViewModel model)
          {
              var rows = item.As<RowWithTilesPart>().Record;
              var allRows = rows.Rows;
              //rows. = model.RelatedLinksGroup;
              rows.TilesJson = model.TilesJson;

              var tilesJson = model.TilesJson;
              

              var oldLinks = _singleRowWithTilesRepository.Fetch(r => r.RowWithTilesRecord.Id == rows.Id).ToList();
              var updatedLinks = (List<SingleRowWithTilesRecord>)JsonConvert.DeserializeObject(tilesJson, typeof(List<SingleRowWithTilesRecord>));

              var deletedLinks = oldLinks.Where(x => !updatedLinks.Select(ui => ui.Id).Contains(x.Id));

              foreach (var deletedLink in deletedLinks)
              {
                  _singleRowWithTilesRepository.Delete(deletedLink);
              }

              foreach (var updatedLink in updatedLinks)
              {
                  if (updatedLink.Id == 0 || !allRows.Any())
                  {
                      updatedLink.RowWithTilesRecord = rows;
                      _singleRowWithTilesRepository.Create(updatedLink);
                  }
                  else if (updatedLink.Id > 0)
                  {
                      updatedLink.RowWithTilesRecord = rows;
                      _singleRowWithTilesRepository.Update(updatedLink); //NEVER HITS THIS
                  }
              }

              //Updating Links in the part manually. 
              //NOTE: Deleting this line will have a delay of 5 mins to update Links on the edit page
              rows.Rows = _singleRowWithTilesRepository.Fetch(r => r.RowWithTilesRecord.Id == rows.Id).ToList();
          }
コード例 #18
0
        public override async Task<IDisplayResult> UpdateAsync(ContentItem contentItem, IUpdateModel updater)
        {
            var testContentPart = contentItem.As<TestContentPartA>();

            if (testContentPart == null)
            {
                return null;
            }

            if (await updater.TryUpdateModelAsync(testContentPart, ""))
            {
                if (testContentPart.Line.EndsWith(" "))
                {
                    updater.ModelState.AddModelError(nameof(testContentPart.Line), "Value cannot end with a space");
                }
                else
                {
                    contentItem.Weld(testContentPart);
                }
            }
            
            return Shape("TestContentPartA_Edit", testContentPart).Location("Content");
        }
コード例 #19
0
ファイル: MailApiService.cs プロジェクト: dioptre/nkd
 private void ProcessApiRequest(ContentItem c)
 {
     var m = c.As<MailApiPart>();
     ProcessApiRequest(m);
 }
コード例 #20
0
 public void UpdateBannerPartForContentItem(ContentItem item, EditBannerViewModel model) {
     var bannerPart = item.As<BannerWidgetPart>();
     bannerPart.Season = _seasonRepository.Get(s => s.Id == model.SeasonId);
 }
コード例 #21
0
        public void UpdateTagsForContentItem(ContentItem contentItem, IEnumerable<string> tagNamesForContentItem) {
            if (contentItem.Id == 0)
                throw new OrchardException(T("Error adding tag to content item: the content item has not been created yet."));

            var tags = tagNamesForContentItem.Select(CreateTag);
            var newTagsForContentItem = new List<TagRecord>(tags);
            var currentTagsForContentItem = contentItem.As<TagsPart>().Record.Tags;

            foreach (var tagContentItem in currentTagsForContentItem) {
                if (!newTagsForContentItem.Contains(tagContentItem.TagRecord)) {
                    _contentTagRepository.Delete(tagContentItem);
                }

                newTagsForContentItem.Remove(tagContentItem.TagRecord);
            }

            foreach (var newTagForContentItem in newTagsForContentItem) {
                _contentTagRepository.Create(new ContentTagRecord { TagsPartRecord = contentItem.As<TagsPart>().Record, TagRecord = newTagForContentItem });
            }
        }
コード例 #22
0
        public void RemoveTagsForContentItem(ContentItem contentItem) {
            if (contentItem.Id == 0)
                throw new OrchardException(T("Error removing tag to content item: the content item has not been created yet."));

            _contentTagRepository.Flush();

            var tagsPart = contentItem.As<TagsPart>();

            // delete orphan tags (for each tag, if there is no other contentItem than the one being deleted, it's an orphan)
            foreach (var tag in tagsPart.CurrentTags) {
                if (_contentTagRepository.Count(x => x.TagsPartRecord.Id != contentItem.Id) == 0) {
                    _tagRepository.Delete(tag);
                }
            }

            // delete tag links with this contentItem (ContentTagRecords)
            foreach (var record in _contentTagRepository.Fetch(x => x.TagsPartRecord.Id == contentItem.Id)) {
                _contentTagRepository.Delete(record);
            }
        }
コード例 #23
0
ファイル: TaxonomyService.cs プロジェクト: wezmag/Coevery
        public void UpdateTerms(ContentItem contentItem, IEnumerable<TermPart> terms, string field) {
            var termsPart = contentItem.As<TermsPart>();

            // removing current terms for specific field
            var fieldIndexes = termsPart.Terms
                .Where(t => t.Field == field)
                .Select((t, i) => i)
                .OrderByDescending(i => i)
                .ToList();
            
            foreach(var x in fieldIndexes) {
                termsPart.Terms.RemoveAt(x);
            }
            
            // adding new terms list
            foreach(var term in terms) {
                termsPart.Terms.Add( 
                    new TermContentItem {
                        TermsPartRecord = termsPart.Record, 
                        TermRecord = term.Record, Field = field
                    });
            }
        }
コード例 #24
0
ファイル: TagService.cs プロジェクト: Zlatinsz/podnebeto
        public void UpdateTagsForContentItem(ContentItem contentItem, IEnumerable<string> tagNamesForContentItem)
        {
            var tags = tagNamesForContentItem.Select(CreateTag);
            var newTagsForContentItem = new List<TagRecord>(tags);
            var currentTagsForContentItem = contentItem.As<TagsPart>().Record.Tags;

            foreach (var tagContentItem in currentTagsForContentItem) {
                if (!newTagsForContentItem.Contains(tagContentItem.TagRecord)) {
                    _contentTagRepository.Delete(tagContentItem);
                }

                newTagsForContentItem.Remove(tagContentItem.TagRecord);
            }

            foreach (var newTagForContentItem in newTagsForContentItem) {
                _contentTagRepository.Create(new ContentTagRecord { TagsPartRecord = contentItem.As<TagsPart>().Record, TagRecord = newTagForContentItem });
            }

            contentItem.As<TagsPart>().CurrentTags = tagNamesForContentItem;
        }
コード例 #25
0
        public void UpdateTerms(ContentItem contentItem, IEnumerable<TermPart> terms, string field) {
            var termsPart = contentItem.As<TermsPart>();

            // removing current terms for specific field
            var termList = termsPart.Terms.Select((t, i) => new { Term = t, Index = i })
                .Where(x => x.Term.Field == field)
                .Select(x => x)
                .OrderByDescending(i => i.Index)
                .ToList();

            foreach (var x in termList) {
                termsPart.Terms.RemoveAt(x.Index);
            }

            // adding new terms list
            foreach (var term in terms) {
                // Remove the newly added terms because they will get processed by the Published-Event
                termList.RemoveAll(t => t.Term.Id == term.Id);
                termsPart.Terms.Add(
                    new TermContentItem {
                        TermsPartRecord = termsPart.Record,
                        TermRecord = term.Record,
                        Field = field
                    });
            }

            var termPartRecordIds = termList.Select(t => t.Term.TermRecord.Id).ToArray();
            _processingEngine.AddTask(_shellSettings, _shellDescriptorManager.GetShellDescriptor(), "ITermCountProcessor.Process", new Dictionary<string, object> { { "termPartRecordIds", termPartRecordIds } });


        }
コード例 #26
0
 public void Delete(ContentItem blog)
 {
     contentManager.Remove(blog);
     destinationPathConstraint.RemovePath(blog.As<IAliasAspect>().Path);
 }
コード例 #27
0
        public void UpdateCalendarForContentItem(
            ContentItem item,
            EditCalendarPartViewModel model)
        {

            var calendarPart = item.As<CalendarPart>();
            //calendarPart.Title = model.Title;
            calendarPart.Description = model.Description;
            calendarPart.ShortDescription = model.ShortDescription;
            calendarPart.FeedProxyUrl = model.FeedProxyUrl;

            _categoryService.UpdateCategoriesForCalendar(item, model.SelectedEventCategoryIds.Split(','));

        }
コード例 #28
0
        public void UpdateCalendarForSchedulerEventViewModel(ContentItem item, SchedulerEventViewModel model)
        {
            //var categories = _eventCategoryService.GetEventCategoriesByIdList(model.EventCategoryIds).ToList();

            var eventPart = item.As<EventPart>();

            if (model.EventCategoryIds != null && model.EventCategoryIds.Any())
            {
                _categoryService.UpdateCategoriesForEvent(item, model.EventCategoryIds);
            }

            eventPart.As<TitlePart>().Title = model.Title.Replace(@"\,",",");
            eventPart.RecurrenceId = model.RecurrenceId;
            eventPart.RecurrenceRule = model.RecurrenceRule;
            eventPart.RecurrenceException = model.RecurrenceException;
            eventPart.TimeZone = model.Timezone;
            eventPart.Description = model.Description.Replace(@"\,", ",");
            eventPart.AddressLocation = model.Location.Replace(@"\,", ",");
            eventPart.Url = model.Url;
            eventPart.ImportedFromGoogleCalendar = model.ImportFromGoogleCalendar;
            eventPart.ImportUid = model.ImportUid;

            eventPart.AllDayEvent = model.IsAllDay;

            if (model.IsAllDay && model.ImportFromGoogleCalendar)
            {
                model.End = model.End.AddDays(-1); // catch for import 
            }

            eventPart.StartDate = model.Start;
            eventPart.EndDate = model.End;
        }
コード例 #29
0
ファイル: ContactFormService.cs プロジェクト: SeyDutch/Gilde
 public void SendMaiLOnContactFormCreated(ContentItem contentItem)
 {
     var values = new ContactFormEntry()
     {
         Name = contentItem.As<ContactFormEntryPart>().SenderName,
         Email = contentItem.As<ContactFormEntryPart>().SenderEmail,
         Subject = contentItem.As<TitlePart>().Title,
         MessageBody = contentItem.As<BodyPart>().Text,
         CreatedUtc = contentItem.As<CommonPart>().CreatedUtc.Value
     };
     MailService.SendMail(values);
     int y = 0;
 }
コード例 #30
0
ファイル: VideoService.cs プロジェクト: rgardler/dpp
        public void UpdateVideosForContentItem(ContentItem item, int[] ids)
        {
            var currentVideoRecord = item.As<VideoPart>().Record;
            var oldMedia = _videoMediaItemRepository.Fetch(r => r.VideoRecord == currentVideoRecord);
            var newVideos = _mediaItemRepository.Table.Where(mi => ids.Contains(mi.Id)).ToList();

            foreach (var videoMediaItemRecord in oldMedia)
            {
               _videoMediaItemRepository.Delete(videoMediaItemRecord);
            }
            for (var position = 0; position < ids.Count(); position++) {
                var mediaItem = newVideos.First(v => v.Id == ids[position]);
                _videoMediaItemRepository.Create(new VideoMediaItemRecord
                {
                    VideoRecord = currentVideoRecord,
                    MediaItemRecord = mediaItem,
                    Position = position
                });
            }
        }