Skip to content

Instantly share code, notes, and snippets.

@rbaty-barr
Created September 24, 2018 15:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rbaty-barr/1cbbef97002c14666e1769e3a411c9a7 to your computer and use it in GitHub Desktop.
Save rbaty-barr/1cbbef97002c14666e1769e3a411c9a7 to your computer and use it in GitHub Desktop.
update an umbraco node with a class
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