Example #1
0
        public StatusWithMessage PurgeCacheForContentNode([FromBody] PurgeCacheForIdParams args)
        {
            if (args.nodeId <= 0)
            {
                return(new StatusWithMessage(false, "You must provide a node id."));
            }

            if (!_cloudflareManager.Configuration.PurgeCacheOn)
            {
                return(new StatusWithMessage(false, CloudflareMessages.CLOULDFLARE_DISABLED));
            }

            IPublishedContent content = Umbraco.Content(args.nodeId);

            var urls = BuildUrlsToPurge(content, args.purgeChildren);

            StatusWithMessage resultFromPurge = PurgeCacheForUrls(new PurgeCacheForUrlsRequestModel()
            {
                Urls = urls, Domains = null
            });

            if (resultFromPurge.Success)
            {
                return(new StatusWithMessage(true, String.Format("{0}", resultFromPurge.Message)));
            }

            return(resultFromPurge);
        }
Example #2
0
        private string getAssignedTo(IPublishedContent inventoryContent)
        {
            string assignedTo   = "Unassigned";
            object assignedToId = inventoryContent.GetPropertyValue("assignedTo");

            if (assignedToId.ToString() != "0" && assignedToId.ToString() != "")
            {
                IPublishedContent assignedToContent = Umbraco.Content(assignedToId);

                switch (assignedToContent.DocumentTypeAlias)
                {
                case "employee":
                    assignedTo = "Employee-" + assignedToContent.GetPropertyValue("employeeName").ToString() + ' ' + assignedToContent.GetPropertyValue("employeeSurname").ToString();
                    break;

                case "inventory":
                    assignedTo = "Inventory-" + assignedToContent.GetPropertyValue("inventoryName").ToString() + assignedToContent.Id;
                    break;

                case "entity":
                    assignedTo = "Entity-" + assignedToContent.GetPropertyValue("entityName").ToString();
                    break;

                default:
                    assignedTo = "Unassigned";
                    break;
                }
            }
            return(assignedTo);
        }
        public ActionResult Index(int id)
        {
            var node = Umbraco.Content(id);

            if (node == null)
            {
                return(new HttpNotFoundResult());
            }

            var ns = XNamespace.Get("http://schemas.microsoft.com/wlw/manifest/weblog");

            var rsd = new XElement(ns + "manifest",
                                   new XElement(ns + "options",
                                                new XElement(ns + "clientType", "Metaweblog"),
                                                new XElement(ns + "supportsNewCategories", "Yes"),
                                                new XElement(ns + "supportsPostAsDraft", "Yes"),
                                                new XElement(ns + "supportsCustomDate", "Yes"),
                                                new XElement(ns + "supportsCategories", "Yes"),
                                                new XElement(ns + "supportsCategoriesInline", "Yes"),
                                                new XElement(ns + "supportsMultipleCategories", "Yes"),
                                                new XElement(ns + "supportsNewCategoriesInline", "Yes"),
                                                new XElement(ns + "supportsKeywords", "Yes"),
                                                //NOTE: This setting is undocumented for whatever reason!
                                                new XElement(ns + "supportsGetTags", "Yes"),
                                                new XElement(ns + "supportsCommentPolicy", "Yes"),
                                                new XElement(ns + "supportsSlug", "Yes"),
                                                new XElement(ns + "supportsExcerpt", "Yes"),
                                                new XElement(ns + "requiresHtmlTitles", "No")));

            return(new XmlResult(new XDocument(rsd)));
        }
        //for filling the dropdown in the object that related position
        public List <SelectListItem> GetAllPositions(int entityId)
        {
            try
            {
                entityId = ((IPublishedContent)Umbraco.Content(entityId)).Ancestor().Id;
            }
            catch (Exception ex)
            {
                return(new List <SelectListItem>());
            }
            List <IPublishedContent> contents = ContentServiceController.Instance.GetContentListByTypeAndParentId("position", -1, -1);

            List <SelectListItem> positionList = new List <SelectListItem>();

            foreach (var content in contents)
            {
                if (Convert.ToInt32(content.GetPropertyValue("entityId")) == entityId)
                {
                    positionList.Add(new SelectListItem {
                        Text = content.GetPropertyValue("positionName").ToString(), Value = content.Id.ToString()
                    });
                }
            }

            return(positionList);
        }
Example #5
0
        public ActionResult ProcessAndSaveOrder([Bind(Prefix = "orderInfo")] CheckoutOrderDTO orderInfo)
        {
            if (orderInfo.PaymentMethod.ToLower() == "paypal")
            {
                //Remove the Credit Card form the modelstate, as we don't need it.
                foreach (var key in ModelState.Keys.Where(m => m.StartsWith("orderInfo.Card")).ToList())
                {
                    ModelState.Remove(key);
                }

                if (ModelState.IsValid)
                {
                    var checkoutPage = Umbraco.Content(1199);
                    TempData.Add("orderInfoTemp", orderInfo);
                    return(Redirect(checkoutPage.Url + "/processpayment"));
                }
            }
            if (orderInfo.PaymentMethod.ToLower() == "card")
            {
                if (ModelState.IsValid)
                {
                    if (orderInfo.Card != null)
                    {
                        return(cartContentController.PayWithCard(orderInfo));
                    }
                }
            }
            return(null);
        }
Example #6
0
        public JsonResult <IEnumerable <CarViewModel> > CarBrandModels(int id)
        {
            var carModels     = Umbraco.Content(id).Children.Select(child => child as CarModel);
            var carViewModels = _mapper.Map <IEnumerable <CarViewModel> >(carModels);

            return(Json <IEnumerable <CarViewModel> >(carViewModels));
        }
Example #7
0
        public JsonResult <CarViewModel> CarModels(int id)
        {
            var carModel     = Umbraco.Content(id) as CarModel;
            var carViewModel = _mapper.Map <CarViewModel>(carModel);

            return(Json <CarViewModel>(carViewModel));
        }
Example #8
0
        private bool CreateContentNode(string name, string contentType, IContent parent, string title, string body, string UrlAlias = "")
        {
            var content      = Umbraco.Content(parent.Id);
            var exsitingNode = content.Children(x => x.Name == name);

            if (exsitingNode.Any())
            {
                return(false);
            }

            var node = _contentService.Create(name, parent, contentType);

            if (node != null)
            {
                node.SetValue("title", title);
                node.SetValue("bodyText", body);
                if (!String.IsNullOrWhiteSpace(UrlAlias) && node.HasProperty("umbracoUrlAlias"))
                {
                    node.SetValue("umbracoUrlAlias", UrlAlias);
                }

                _contentService.SaveAndPublish(node);

                return(true);
            }
            return(false);
        }
Example #9
0
        public JsonResult getAllPosts()
        {
            List <string> result      = new List <string>();
            var           contentNode = Umbraco.Content(1067);

            foreach (var obj in contentNode.Descendants().Where("NodeTypeAlias == \"newsevents_post\""))
            {
                var post = new Dictionary <string, string>();
                post.Add("title", obj.pageTitle);

                /*string raw_content = obj.postContent.ToString();
                 * string content_text = HBTUmbracoHelper.TrimHtml(raw_content);
                 * string exerpt_text = HBTUmbracoHelper.TruncateString(content_text, 150);*/
                string exerpt_text = obj.exerpt;
                post.Add("subtitle", exerpt_text);
                post.Add("url", obj.Url);
                post.Add("featuredImage", Umbraco.Media(obj.featuredImage).umbracoFile);
                post.Add("categoryName", obj.Parent().pageTitle);
                post.Add("categoryID", Convert.ToString(obj.Parent().Id));

                string dealjsonString = HBTUmbracoHelper.FromDictionaryToJson(post);
                result.Add(dealjsonString);
            }
            return(Json(HBTUmbracoHelper.FromListOfJsonToJson(result), JsonRequestBehavior.AllowGet));
        }
Example #10
0
        private void CreatingContent(int parent, IEnumerable <PressRelease> pages)
        {
            // Get the Umbraco Content Service
            var contentService                       = Services.ContentService;
            IPublishedContent parentNode             = Umbraco.Content(parent);
            IEnumerable <IPublishedContent> children = parentNode.Children;

            foreach (PressRelease item in pages)
            {
                IContent newPageContent;

                bool containsItem = children.Any(x => x.GetPropertyValue <string>("pressReleaseId") == item.Id.ToString());

                if (!containsItem)
                {
                    newPageContent = contentService.CreateContent(item.Title, parent, "NewsPage");

                    newPageContent.SetValue("Heading", item.Title);
                    newPageContent.SetValue("Preamble", item.LeadText);
                    newPageContent.SetValue("MainBody", item.Body);
                    newPageContent.SetValue("pressReleaseId", item.Id);
                    newPageContent.SetValue("prImageUrl", item.ListOfImages?.FirstOrDefault()?.Url);
                    newPageContent.SetValue("pRDate", item.Published);
                    newPageContent.SetValue("PublishDate", DateTime.Now);

                    // Save and publish it.
                    contentService.SaveAndPublishWithStatus(newPageContent, 1, false);
                }
            }
        }
Example #11
0
        public ActionResult Search(string query)
        {
            var searchResPage = CurrentPage.AncestorOrSelf(1).FirstChild <SearchResults>();

            if (ExamineManager.Instance.TryGetIndex("ArticleIndex", out var index))
            {
                var searcher      = index.GetSearcher();
                var searchTerms   = SplitSearchTerms(query);
                var querySearcher = searcher.CreateQuery("content", BooleanOperation.Or).NodeTypeAlias("article");
                foreach (var examineValue in searchTerms)
                {
                    querySearcher.And().Field("nodeName", examineValue);
                }
                var results = querySearcher.Not().Field("umbracoNaviHide", "1").Execute();
                if (results.Any())
                {
                    var total = results.TotalItemCount;
                    var res   = Umbraco.Content(results.Select(x => x.Id)).ToList();
                    TempData["Result"] = res;
                    return(RedirectToUmbracoPage(searchResPage));
                }
            }

            return(CurrentUmbracoPage());
        }
        public IEnumerable <string> find()
        {
            var page    = Umbraco.Content(1063);
            var theName = page.title;

            return(new string[] { theName, "value2" });
        }
Example #13
0
        public async Task <HttpResponseMessage> PurgeURLByIDAsync()
        {
            string contentId = await Request.Content.ReadAsStringAsync();

            HttpResponseMessage response = null;

            if (string.IsNullOrWhiteSpace(contentId) == false)
            {
                string domain = WebConfigurationManager.AppSettings["Fastly:DomainName"];

                if (string.IsNullOrWhiteSpace(domain))
                {
                    response = this.Request.CreateResponse(HttpStatusCode.InternalServerError);
                }
                else
                {
                    string url = domain + Umbraco.Content(contentId).Url();
                    response = await FastlyUmbraco.SendAsync(new Uri(url));
                }
            }
            else
            {
                response = this.Request.CreateResponse(HttpStatusCode.BadRequest);
            }

            return(response);
        }
        public IHttpActionResult Get(Guid id)
        {
            IPublishedContent content = Umbraco.Content(id);
            var model = _contentResolver.Value.ResolveContent(content);

            return(Ok(model));
        }
        public HttpResponseMessage Get()
        {
            JsonResponse Response = new JsonResponse(true, new SecureContext());

            Response.Create();

            if (Response.IsAuthentic == true)
            {
                List <Post> Output = new List <Post>();

                var Source = Umbraco.Content(1125).Children().Where("Visible");

                if (Source.Count() > 0)
                {
                    foreach (var Node in Source)
                    {
                        Output.Add(new Post
                        {
                            ID          = Node.Id,
                            Title       = (string)Node.GetPropertyValue("title"),
                            Body        = (string)Node.GetPropertyValue("body"),
                            PublishedOn = Node.CreateDate,
                            PublishedBy = (string)Node.CreatorName,
                            Image       = "https://www.jirikralovec.cz/dev/givskud/images/demo-animalimage.jpg"
                                          // Image = "https://" + HttpContext.Current.Request.Url.Host + Node.GetPropertyValue("image").Url,
                        });
                    }
                }

                Response.Set(new StringContent(JsonConvert.SerializeObject(Output), ApiContext.GetEncoding(), ApiContext.GetOutputType()));
            }

            return(Response.Get());
        }
        public TeamViewModel GetTeamById(int nodeId)
        {
            //int nodeID=2072; //ManCity content
            //int nodeID = 2068; //Barcelona content
            if (!IsNodeIdCorrect(nodeId))
            {
                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }

            var teamContent = Umbraco.Content(nodeId);

            if (!IsContentNotNull(teamContent))
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }

            TeamViewModel teamModel = new TeamViewModel()
            {
                Id          = nodeId,
                Name        = teamContent.Value(UmbracoAliasConfiguration.Team.TeamName).ToString(),
                StadiumName = teamContent.Value(UmbracoAliasConfiguration.Team.TeamStadium).ToString(),
                Players     = GetTeamPlayers(nodeId).ToList()
            };

            return(teamModel);
        }
        public PlayerViewModel GetPlayerById(int nodeId)
        {
            //int nodeId = 2084; //Varan
            if (!IsNodeIdCorrect(nodeId))
            {
                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }

            var playerContent = Umbraco.Content(nodeId);
            var isP           = playerContent.IsPublished();

            // var parentInfo = playerContent.Parent;
            if (!IsContentNotNull(playerContent))
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }

            var player = new PlayerViewModel()
            {
                Id   = playerContent.Id,
                Name = playerContent.Value(UmbracoAliasConfiguration.Player.PlayerName).ToString(),
                Age  = Int32.Parse(playerContent.Value(UmbracoAliasConfiguration.Player.PlayerAge).ToString())
            };

            return(player);
        }
        public IEnumerable <ClientView> GetAllActiveClients()
        {
            var clients        = Services.ContentService.GetChildren(1091).Where(c => c.Published == true);
            var clientViewList = new List <ClientView>();

            foreach (IContent client in clients)
            {
                var cv             = new ClientView();
                var currentContent = Umbraco.Content(client.Id);

                cv.Id         = client.Id.ToString();
                cv.ClientCode = client.GetValue("clientCode").ToString();
                cv.ClientName = client.Name;
                if (client.GetValue("clientLogo") != null)
                {
                    var logoURL = currentContent.GetCropUrl("clientLogo", "square");
                    cv.LogoURL = logoURL;
                }

                cv.ContactName  = Utilities.GetString(client.GetValue("contactName"));
                cv.ContactEmail = Utilities.GetString(client.GetValue("contactEmailAddress"));
                cv.ContactPhone = Utilities.GetString(client.GetValue("contactPhoneNumber"));

                clientViewList.Add(cv);
            }
            return(clientViewList);
        }
        public PlayerViewModel AddNewPlayerToReal(PlayerViewModel newPlayer)
        {
            int nodeID = 2080;

            //get node info to add in
            var     playersNodeName = Umbraco.Content(nodeID).Name;
            var     playersNodeGuid = Umbraco.Content(nodeID).Key;
            GuidUdi currentPageUdi  = new GuidUdi(playersNodeName, playersNodeGuid);

            //create content node
            var data = _contentService.CreateContent(playersNodeName, currentPageUdi, UmbracoAliasConfiguration.Player.Alias, 0);

            //define properties
            data.Name = newPlayer.Name;
            data.SetValue(UmbracoAliasConfiguration.Player.PlayerName, newPlayer.Name);
            data.SetValue(UmbracoAliasConfiguration.Player.PlayerAge, newPlayer.Age);


            _contentService.SaveAndPublish(data);

            var playersToSort   = Umbraco.Content(nodeID).Children().ToList();
            var playersIDToSort = playersToSort.OrderByDescending(x => x.CreateDate).Select(y => y.Id).ToList();

            _contentService.Sort(playersIDToSort);

            return(newPlayer);
        }
Example #20
0
        public HttpResponseMessage Get()
        {
            JsonResponse Response = new JsonResponse(true, new SecureContext());

            Response.Create();

            if (Response.IsAuthentic == true)
            {
                List <Area> Output = new List <Area>();

                var Source = Umbraco.Content(1122).Children().Where("Visible");

                if (Source.Count() > 0)
                {
                    foreach (var Node in Source)
                    {
                        Output.Add(new Area {
                            ID    = Node.Id,
                            Title = Node.GetPropertyValue("title")
                        });
                    }
                }

                Response.Set(new StringContent(JsonConvert.SerializeObject(Output), ApiContext.GetEncoding(), ApiContext.GetOutputType()));
            }

            return(Response.Get());
        }
        public ActionResult CreateComment([Bind(Include = "description,parentComment")] Comment commentModel)
        {
            IPublishedContent parentContent = Umbraco.Content(commentModel.ParentComment);

            commentModel.CreationTime  = DateTime.Now;
            commentModel.ParentComment = parentContent.Id;
            if (ModelState.IsValid)
            {
                MemberHelper      memberHelper  = new MemberHelper();
                IPublishedContent currentMember = memberHelper.GetCurrentMember();
                var content = Services.ContentService.CreateContent(currentMember.Name + commentModel.CreationTime, parentContent.Id, "comment");
                content.SetValue("commentDescription", commentModel.Description);
                content.SetValue("commentWrittenBy", currentMember.Id);
                if (Services.ContentService.SaveAndPublishWithStatus(content).Success)
                {
                    TempData["Msg"] = "Comment successfully added";
                    return(PartialView("~/Views/Partials/FormSuccess.cshtml"));
                }
                else
                {
                    TempData["Msg"] = "Comment couldn't be added";
                    return(PartialView("~/Views/Partials/FormError.cshtml"));
                }
            }
            TempData["Msg"] = "Wait... This is not a comment";
            return(PartialView("~/Views/Partials/FormError.cshtml"));
        }
Example #22
0
        public ActionResult List(int?maxAthletesToDisplay)
        {
            var logginPhysioNodeId = GetLoggedInPhysioNodeId();

            var physioAthletesViewModel = PhysioAthletesViewModel.Create(Umbraco, logginPhysioNodeId ?? 0, maxAthletesToDisplay);

            if (logginPhysioNodeId == null)
            {
                return(View("~/Views/BusinessPages/Athletes/List.cshtml", physioAthletesViewModel));
            }

            var results = _examineService.Query?.ParentId(logginPhysioNodeId.Value).Execute();

            if (results.HasValues())
            {
                foreach (var item in results)
                {
                    if (!item.Id.IsNull())
                    {
                        physioAthletesViewModel.AddAthlete(new AthleteViewModel(Umbraco.Content(item.Id)));
                    }
                }
            }

            return(View("~/Views/BusinessPages/Athletes/List.cshtml", physioAthletesViewModel));
        }
Example #23
0
        public JsonResult <CarBrandViewModel> CarBrands(int id)
        {
            var carBrand          = Umbraco.Content(id) as CarBrand;
            var carBrandViewModel = _mapper.Map <CarBrandViewModel>(carBrand);

            return(Json <CarBrandViewModel>(carBrandViewModel));
        }
        public ActionResult Author(ContentModel model, int authorId, int?maxItems)
        {
            var author = Umbraco.Content(authorId);

            if (author == null)
            {
                throw new ArgumentNullException(nameof(author));
            }

            if (!maxItems.HasValue)
            {
                maxItems = 25;
            }

            //create a master model
            var masterModel = new MasterModel(author);

            var listNodes = masterModel.RootBlogNode.ChildrenOfType(ArticulateConstants.ArticulateArchiveContentTypeAlias).ToArray();

            var authorContenet = Umbraco.GetContentByAuthor(listNodes, author.Name, new PagerModel(maxItems.Value, 0, 1));

            var feed = FeedGenerator.GetFeed(masterModel, authorContenet.Select(x => new PostModel(x)));

            return(new RssResult(feed, masterModel));
        }
Example #25
0
        public void SyncDataVnexpress()
        {
            IContentService contentService = Services.ContentService;
            var             parent         = contentService.GetById(1166);
            var             news           = CrawlerHtml();

            var pageNewsInDb = Umbraco.Content(1166).Children.ToList();

            try
            {
                foreach (var item in news)
                {
                    var anyNew = pageNewsInDb.Where(x => x.GetProperty("title").Value().Equals(item.Title))?.ToList();
                    if (anyNew.Count <= 0)
                    {
                        var message = contentService.CreateContent($"{item.Title}-{DateTime.Now}", parent.GetUdi(), "new");

                        message.SetValue("title", item.Title);
                        message.SetValue("description", item.Description);
                        message.SetValue("content", item.Content);
                        message.SetValue("image", item.LinkImage);

                        Services.ContentService.SaveAndPublish(message);
                    }
                }
            }
            catch (Exception ex)
            {
            }
        }
Example #26
0
 /// <summary>
 /// Get scheduled job data
 /// </summary>
 /// <param name="JobId"></param>
 /// <returns>Scheduled job data in JSON string</returns>
 public string GetScheduledJob(int JobId)
 {
     try
     {
         logger.Log("Getting scheduled job with ID: " + JobId);
         IPublishedContent job         = Umbraco.Content(JobId);
         ScheduleJob       scheduleJob = new ScheduleJob
         {
             Attachments    = job.GetProperty("attachments").Value.ToString(),
             BCC            = job.GetProperty("bCC").Value.ToString(),
             CC             = job.GetProperty("cC").Value.ToString(),
             Body           = job.GetProperty("body").Value.ToString(),
             CronExpression = job.GetProperty("cronExpression").Value.ToString(),
             SenderName     = job.GetProperty("sendername").Value.ToString(),
             Subject        = job.GetProperty("subject").Value.ToString(),
             TemplateFile   = job.GetProperty("templateFile").Value.ToString(),
             To             = job.GetProperty("to").Value.ToString(),
             WorkUntil      = Convert.ToDateTime(job.GetProperty("workUntil").Value)
         };
         return(JsonConvert.SerializeObject(scheduleJob));
     }catch (Exception ex)
     {
         logger.Log(ex.ToString().Replace("\r\n", ""));
         return(null);
     }
 }
Example #27
0
        /// <summary>
        /// Generic get chart.
        /// Based on the Id it searches for the alias and then forwards the request to the applicable controllers
        /// </summary>
        /// <param name="id">Id of the content that we're in</param>
        /// <returns>Action result that comes from the different controllers</returns>
        public List <String> GetChart(int id)
        {
            String        contentAlias    = ((IPublishedContent)Umbraco.Content(id)).DocumentTypeAlias;
            MethodInfo    mi              = this.GetType().GetMethod("Get" + contentAlias + "Chart");
            List <String> partialViewUrls = (List <String>)mi.Invoke(this, null);

            return(partialViewUrls);
        }
        public string GetApplication([FromBody] UserInfo userinfo)
        {
            var uid           = userinfo.UID;
            var userinfoItems = Umbraco.Content(1083).Children.Where("UID==userinfo.UID");
            var info          = userinfoItems == null ? "" : userinfoItems[0];

            return(Json(info));
        }
 /// <summary>
 /// Parses the IContent to a IPublishedContent
 /// </summary>
 /// <param name="content">Content as IContent</param>
 /// <returns>IPublishedContent of the given IContent</returns>
 public IPublishedContent ToIPublishedContent(IContent content)
 {
     try {
         return(Umbraco.Content(content.Id));
     } catch (Exception ex) {
         CustomLogHelper.logHelper.Log("Cannot convert to IPublishedContent the given " + content.Id + "Error message :" + ex.Message);
         return(null);
     }
 }
Example #30
0
        public ActionResult RedirectToCheckout(int id, string paymentId)
        {
            IPublishedContent content = Umbraco.Content(id);

            return(View(new RedirectToCheckoutModel(content)
            {
                PaymentId = paymentId
            }));
        }