Created
September 24, 2018 15:27
-
-
Save rbaty-barr/1cbbef97002c14666e1769e3a411c9a7 to your computer and use it in GitHub Desktop.
update an umbraco node with a class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Text; | |
using System.Text.RegularExpressions; | |
using System.Web; | |
using System.Web.Mvc; | |
using System.Collections.Generic; | |
using System.IO; | |
using System.Linq; | |
using System.Net; | |
using System.Net.Http; | |
using Umbraco.Core; | |
using Umbraco.Core.Logging; | |
using Umbraco.Core.Models; | |
using Umbraco.Core.Services; | |
using Umbraco.Web; | |
using Umbraco.Web.Mvc; | |
namespace bbatybarr.App_Code | |
{ | |
public class votenowSurfaceController : SurfaceController | |
{ | |
[HttpPost] | |
public ActionResult castVote() | |
{ | |
var contentService = ApplicationContext.Current.Services.ContentService; | |
var homeNode = contentService.GetRootContent().FirstOrDefault(); | |
var upDoc = contentService.GetById(Convert.ToInt32(homeNode.Id)); | |
var getInfo = Umbraco.TypedContent(Convert.ToInt32(homeNode.Id)); | |
int curVotes = getInfo.HasValue("votes") ? getInfo.GetPropertyValue<int>("votes") : 0 ; | |
int newVote = curVotes + 1; | |
upDoc.SetValue("votes", newVote); | |
contentService.SaveAndPublish(upDoc); | |
return Content(newVote.ToString()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment