/// <summary> /// Votes for answers /// </summary> /// <param name="answerid">Answer Id</param> /// <param name="vote">Vote</param> /// <returns></returns> public ActionResult VoteForAnswer(int answerid, int vote) { if (!Request.IsAuthenticated) { //Check if the user logged in return Json(Resources.Global.YouHaveToLoginBeforeVote); } else { var vman = new VoteManager(); //Check if the user already voted for this answer bool isVoted = vman.IsVotedForAnswer(answerid, WebSecurity.GetUserId(User.Identity.Name)); if (isVoted) { return Json(Resources.Global.YouAlreadyVotedForThisAnswer); } //Check if the user want to vote for his own question var aman = new AnswerManager(); if (aman.GetAnswer(answerid).UserId == WebSecurity.GetUserId(User.Identity.Name)) { return Json(Resources.Global.YouCantVoteForYourOwnAnswer); } //Store the vote vman.VoteAnswer(answerid, WebSecurity.GetUserId(User.Identity.Name), vote); return Json(aman.GetVote(answerid)); } }
public ActionResult EditAnswer(string actId) { int actualId = Int32.Parse(actId); var manager = new AnswerManager(); var model = manager.GetAnswer(actualId); //If the user is authorized to edit this answer, it returns the edit page if (model.UserId == WebSecurity.CurrentUserId) { return View(model); } else { return RedirectToAction("Index", "Home"); } }