public VotedQuestion addVote(VotedQuestion votedQuestion) { var entity = DbContext.VotedQuestions.Add(votedQuestion); DbContext.SaveChanges(); return(entity); }
public ActionResult Index(VotedQuestion votedQuestion) { TempData["check"] = false; if (ModelState.IsValid) { var _votedQuestion = new UserBL().addVote(votedQuestion); TempData["check"] = true; #region setCookies for Voted Questions HttpCookie cookie = Request.Cookies["QuestionIds"]; string QuestionId = Convert.ToString(votedQuestion.QuestionId); cookie.Values[QuestionId] = QuestionId; Response.Cookies.Add(cookie); #endregion #region setCookis for Voted Answers HttpCookie cookieAnswers = Request.Cookies["VoteId"];//Get the existing cookie by cookie name. if (cookieAnswers == null) { cookieAnswers = new HttpCookie("VoteId"); cookieAnswers.Expires = DateTime.Now.AddHours(3000); } string VoteId = Convert.ToString(_votedQuestion.Id); cookieAnswers.Values[VoteId] = VoteId; Response.Cookies.Add(cookieAnswers); #endregion } return(RedirectToAction("Index")); }