Ejemplo n.º 1
0
        private int CreateAnnouncementPage(NewAnnouncementRequest request)
        {
            var contentService = Services.ContentService;
            var homepage       = UmbracoContext.ContentCache.GetByRoute("/");
            var announcements  = homepage.DescendantOrSelf("announcementsFolder");

            var parent = contentService.GetById(announcements.Id);

            var newContent = contentService.CreateContent($"{DateTime.Now.ToString("yyyyMMdd")}-{request.ShortName}", parent, "newsPage");

            newContent.SetValue("headerTitle", request.Heading);
            newContent.SetValue("introduction", request.Text);
            newContent.SetValue("offsetHeader", true);
            newContent.SetValue("noIndex", true);
            newContent.SetValue("hideFromSitemap", true);

            var result = contentService.SaveAndPublishWithStatus(newContent);

            if (result.Success)
            {
                return(newContent.Id);
            }
            else
            {
                var exception = result.Exception;
            }

            return(-1);
        }
Ejemplo n.º 2
0
        public async Task <object> NewAnnouncement(NewAnnouncementRequest request)
        {
            var nodeId = CreateAnnouncementPage(request);
            var announcementPageUrl = UmbracoContext.ContentCache.GetById(nodeId).UrlWithDomain();

            foreach (var commType in request.Types)
            {
                switch (commType)
                {
                //add other announcement streams here
                case "Push":
                    await SendPushNotifications(request, announcementPageUrl);

                    break;
                }
            }

            WriteCommunicationLogEntry(request, nodeId, Security.CurrentUser.Name);

            return(new { url = announcementPageUrl });
        }
Ejemplo n.º 3
0
        private void WriteCommunicationLogEntry(NewAnnouncementRequest request, int nodeId, string user)
        {
            var newEntry = new CommunicationEntry
            {
                Title    = request.Heading,
                SentDate = DateTime.Now,
                NodeId   = nodeId,
                User     = user
            };

            var filePath    = Path.Combine(TempFolderPath, LogFileName);
            var existingLog = GetHistoryLog(filePath);

            existingLog.Add(newEntry);

            try
            {
                File.WriteAllText(filePath, JsonConvert.SerializeObject(existingLog.OrderByDescending(x => x.SentDate).ToList()));
            }
            catch (Exception e)
            {
                LogHelper.Error <Exception>("Error serialising communication log", e);
            }
        }
Ejemplo n.º 4
0
 private async Task SendPushNotifications(NewAnnouncementRequest request, string url)
 {
     await _pushService.SendNotificationsAsync("Push Notification Demo", $"{DateTime.Now.ToString("dd MMM")} {request.Heading}", url);
 }