1
- using System ;
2
- using System . Collections . Generic ;
1
+ using System . Collections . Generic ;
3
2
4
3
using System . Linq ;
5
-
4
+ using System . Runtime . CompilerServices ;
6
5
using Umbraco . Cms . Integrations . Automation . Zapier . Configuration ;
7
6
using Umbraco . Cms . Integrations . Automation . Zapier . Models . Dtos ;
8
7
using Umbraco . Cms . Integrations . Automation . Zapier . Services ;
9
8
10
9
#if NETCOREAPP
11
10
using Microsoft . Extensions . Options ;
12
11
12
+ using Umbraco . Cms . Core . Web ;
13
13
using Umbraco . Cms . Web . Common . Controllers ;
14
14
using Umbraco . Cms . Core . Services ;
15
+ using Umbraco . Cms . Core . Models . PublishedContent ;
16
+ using Umbraco . Extensions ;
15
17
#else
16
18
using System . Configuration ;
17
19
20
+ using Umbraco . Web ;
18
21
using Umbraco . Web . WebApi ;
19
22
using Umbraco . Core . Services ;
23
+ using Umbraco . Core . Models . PublishedContent ;
24
+
20
25
#endif
21
26
22
27
namespace Umbraco . Cms . Integrations . Automation . Zapier . Controllers
23
28
{
24
29
public class PollingController : UmbracoApiController
25
30
{
26
- private readonly ZapierSettings Options ;
31
+ private IUmbracoContextFactory _umbracoContextFactory ;
27
32
28
33
private IContentService _contentService ;
29
34
35
+ private readonly ZapierSettings Options ;
36
+
30
37
private ZapierFormService _zapierFormService ;
31
38
32
39
private readonly IUserValidationService _userValidationService ;
33
40
34
41
#if NETCOREAPP
35
- public PollingController ( IOptions < ZapierSettings > options , IContentService contentService , ZapierFormService zapierFormService , IUserValidationService userValidationService )
42
+ public PollingController ( IOptions < ZapierSettings > options , IUmbracoContextFactory umbracoContextFactory , IContentService contentService , ZapierFormService zapierFormService , IUserValidationService userValidationService )
36
43
#else
37
- public PollingController ( IContentService contentService , ZapierFormService zapierFormService , IUserValidationService userValidationService )
44
+ public PollingController ( IUmbracoContextFactory umbracoContextFactory , IContentService contentService , ZapierFormService zapierFormService , IUserValidationService userValidationService )
38
45
#endif
39
46
{
40
47
#if NETCOREAPP
@@ -43,6 +50,8 @@ public PollingController(IContentService contentService, ZapierFormService zapie
43
50
Options = new ZapierSettings ( ConfigurationManager . AppSettings ) ;
44
51
#endif
45
52
53
+ _umbracoContextFactory = umbracoContextFactory ;
54
+
46
55
_contentService = contentService ;
47
56
48
57
_zapierFormService = zapierFormService ;
@@ -88,6 +97,40 @@ public IEnumerable<PublishedContentDto> GetSampleContent()
88
97
} ) ;
89
98
}
90
99
100
+ public List < Dictionary < string , string > > GetContentByAlias ( string contentTypeAlias )
101
+ {
102
+ var list = new List < Dictionary < string , string > > ( ) ;
103
+
104
+ using ( var cref = _umbracoContextFactory . EnsureUmbracoContext ( ) )
105
+ {
106
+ var cache = cref . UmbracoContext . Content ;
107
+
108
+ var nodes = cache . GetByXPath ( $ "//{ contentTypeAlias } ")
109
+ . Where ( p => p . IsPublished ( ) )
110
+ . OrderByDescending ( p => p . UpdateDate ) ;
111
+
112
+ foreach ( var node in nodes )
113
+ {
114
+ var content = new Dictionary < string , string >
115
+ {
116
+ { Constants . Content . Id , node . Id . ToString ( ) } ,
117
+ { Constants . Content . Name , node . Name } ,
118
+ { Constants . Content . PublishDate , node . UpdateDate . ToString ( "s" ) }
119
+ } ;
120
+
121
+ foreach ( var prop in node . Properties )
122
+ {
123
+ content . Add ( prop . Alias , prop . GetValue ( ) . ToString ( ) ) ;
124
+ }
125
+
126
+
127
+ list . Add ( content ) ;
128
+ }
129
+
130
+ return list ;
131
+ }
132
+ }
133
+
91
134
public IEnumerable < FormDto > GetSampleForm ( )
92
135
{
93
136
return _zapierFormService . GetAll ( ) ;
0 commit comments