zio zio
zio zio

Reputation: 3

The name 'content' does not exist in the current context

I get this error, what am i doing wrong?

` using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using Umbraco.Web.WebApi;

namespace Umbraco.Course.Controllers
{
[MemberAuthorize(AllowType = "IntranetUser")]
public class LikesController : UmbracoApiController
{
    [System.Web.Http.HttpGet]
    public int LikeStatus(int id)
    {
        var contentService = Services.ContentService;
        var memberService = Services.MemberService;
        var relationService = Services.RelationService;

        var member = memberService.GetById(Members.GetCurrentMemberId());

        var post = contentService.GetById(id);

        if (!relationService.AreRelated(content, member, "likes"))
            relationService.Relate(post, member, "likes");

        var likes = relationService.GetByParent(post, "likes").Count();

            post.SetValue("likes", likes);

            contentService.PublishWithStatus(post);
            return likes;

        }
    }
  }`

Upvotes: 0

Views: 529

Answers (2)

Gurunadh
Gurunadh

Reputation: 463

With reference to your code replace

if (!relationService.AreRelated(content, member, "likes"))

with

if (!relationService.AreRelated(post, member, "likes"))

and try it out,

Upvotes: 0

Bryan Hadlock
Bryan Hadlock

Reputation: 2716

if (!relationService.AreRelated(content, member, "likes"))

The variable content is not defined.

Upvotes: 3

Related Questions