public async Task <JsonResult> UpVoteItem(string itemType, string itemId, string userId) { await Task.Run(() => { UpVote upVote = null; string originalQuestionUserId = ""; if (itemType == "question") { var question = qaLogic.HandleGetQuestion(Convert.ToInt32(itemId)); if (question != null) { upVote = new UpVote { questionId = Convert.ToInt32(itemId), userId = userId }; originalQuestionUserId = question.OwnerId; } } else { var answer = qaLogic.HandleGetAnswer(Convert.ToInt32(itemId)); if (answer != null) { upVote = new UpVote { answerId = Convert.ToInt32(itemId), userId = userId }; originalQuestionUserId = answer.OwnerId; } } qaLogic.HandleSaveUpVote(upVote); qaLogic.HandleUpdateReputation(originalQuestionUserId, 5); }); return(Json("UpVote", JsonRequestBehavior.AllowGet)); }
public ActionResult PlusUpvote(string commentId, string userId) { try { int commentIdInt = Int32.Parse(commentId); int clientId = Int32.Parse(userId); int serverUserId = WebSecurity.CurrentUserId; if (clientId == serverUserId) { UpVote upVote = new UpVote { CommentId = commentIdInt, UserId = clientId }; _echoDb.UpVotes.Add(upVote); _echoDb.SaveChanges(); int upvoteNumber = _echoDb.UpVotes.Count(p => p.CommentId == commentIdInt); return(Json(upvoteNumber)); } return(Json("error")); } catch (Exception) { return(Json("error")); } }
public ActionResult DownVote(int AId) { var userId = User.Identity.GetUserId(); var userInstance = db.Users.Where(i => i.Id == userId).FirstOrDefault(); var aInstance = db.Answers.Where(i => i.Id == AId).FirstOrDefault(); var upvote = new UpVote(); bool notOwnerCk = new bool(); if (aInstance.AOwnerId == userId) { notOwnerCk = false; } else { notOwnerCk = true; } var upVoterTwiceCk = db.UpVotes.Where(i => i.Answer.Id == AId && i.VoterId == userId).Any(); if (notOwnerCk && !upVoterTwiceCk) { aInstance.AOwner.UScore -= 5; aInstance.AScore--; userInstance.UScore--; upvote.AnswerId = AId; upvote.VoterId = User.Identity.GetUserId(); db.UpVotes.Add(upvote); db.SaveChanges(); } return(RedirectToAction("Details", "Question", new { QId = aInstance.QuestionId })); }
public ActionResult UpVote(int linkId) { Manager m = new Manager(); var name = User.Identity.Name; var user = m.GetUserId(name); UpVote uv = new UpVote(); uv.UserId = user.Id; uv.LinkId = linkId; var Upvotes = m.GetUpvotes(); bool notUnique = Upvotes.Any(i => i.UserId == uv.UserId && i.LinkId == uv.LinkId); if (!notUnique) { m.AddUpVote(uv); } int upvoteAmount = m.GetUpvoteAmount(linkId); UpvoteUnique u = new UpvoteUnique(); u.UpvoteAmount = upvoteAmount; u.NotUnique = notUnique; return(Json(u)); }
public async Task <string> Upvote(string postId) { try { var currentuser = Feature.CurrentUser(httpContextAccessor, userRepository); var currentPost = await postRepository.GetByIdAsync(ObjectId.Parse(postId)); var builderUpvote = Builders <UpVote> .Filter; var filterExistUpvote = builderUpvote.Eq(ObjectVoteId, postId) & builderUpvote.Eq(UpVoteBy, currentuser.OId) & builderUpvote.Eq(IsDeleted, false); var existUpvote = await upVoteRepository.FindAsync(filterExistUpvote); if (existUpvote != null) { return(UserUpvoteAlready); } else if (existUpvote == null) { var builderDownVote = Builders <DownVote> .Filter; var filterExistDownVote = builderDownVote.Eq(ObjectVoteId, postId) & builderDownVote.Eq(DownVoteBy, currentuser.OId) & builderDownVote.Eq(IsDeleted, false); var existDownVote = await downVoteRepository.FindAsync(filterExistDownVote); if (existDownVote != null) { existDownVote.IsDeleted = true; await downVoteRepository.DeleteAsync(existDownVote.Id); } var upvote = new UpVote() { ObjectVoteId = postId, UpVoteBy = currentuser.OId }; await upVoteRepository.AddAsync(upvote); } var notificationDetail = new Noftication() { AuthorId = currentuser.OId, OwnerId = currentPost.AuthorId, ObjectId = currentPost.OId, ObjectThumbnail = currentPost.Title }; await fcmRepository.PushNotify(currentPost.AuthorId, notificationDetail, NotificationContent.UpvotePostNotification); await userService.AddPoint(currentPost.AuthorId, currentPost.OId, PointAdded.Upvote); return(UpvoteSuccess); } catch (Exception) { return("Có lỗi xảy ra. "); } }
public void AddUpVote(UpVote Upvote) { using (var context = new HackerNewsDatabaseDataContext(@"Data Source=.\sqlexpress;Initial Catalog=HackerNews;Integrated Security=True")) { context.UpVotes.InsertOnSubmit(Upvote); context.SubmitChanges(); } }
protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e) { DataList1.SelectedIndex = e.Item.ItemIndex; int qid = Convert.ToInt32(e.CommandArgument); if (e.CommandName == "Answer") { Response.Redirect("Answer.aspx?QId=" + qid); } if (e.CommandName == "ViewAnswer") { Response.Redirect("ViewAnswer.aspx?QId=" + qid); } if (e.CommandName == "UpVote") { var vote = (from x in db.UpVotes where x.QId.Equals(qid) && x.VId == Convert.ToInt32(Session["UId"]) select x); if (vote.Count() > 0) { vote.FirstOrDefault().UpVote1 = 1; } else { UpVote up = new UpVote { VId = Convert.ToInt32(Session["VId"]), QId = qid, UpVote1 = 1 }; db.UpVotes.InsertOnSubmit(up); } db.SubmitChanges(); DataList1.DataBind(); } if (e.CommandName == "DownVote") { var vote = (from x in db.UpVotes where x.QId.Equals(qid) && x.VId == Convert.ToInt32(Session["UId"]) select x).FirstOrDefault(); if (vote.UpVote1 == 1) { vote.UpVote1 = 0; } else { vote.UpVote1 = 0; } db.SubmitChanges(); DataList1.DataBind(); } }
public async Task <IActionResult> DoUpvote(int id) { if (UpVote.TryAdd(DbContext, id, Request.HttpContext.Connection.RemoteIpAddress.ToString())) { int upvotes = await DbContext.UpVotes.CountAsync(x => x.SuggestionId == id); return(Ok(new { upvotes })); } else { return(BadRequest()); } }
private IActionResult FailSubmit(SuggestionValidationState sugState, SuggestNameModel model) { if (sugState == SuggestionValidationState.SUGGESTIONEXISTS) { if (UpVote.TryAdd(DbContext, model.Proposition, Request.HttpContext.Connection.RemoteIpAddress.ToString())) { sugState = SuggestionValidationState.SUGGESTIONUPVOTED; } } ErrorSuggestModel errorSuggestModel = new ErrorSuggestModel(sugState); return(View("ErrorSubmit", errorSuggestModel)); }
private void detach_UpVotes(UpVote entity) { this.SendPropertyChanging(); entity.Question = null; }
private void attach_UpVotes(UpVote entity) { this.SendPropertyChanging(); entity.Question = this; }
partial void DeleteUpVote(UpVote instance);
partial void UpdateUpVote(UpVote instance);
partial void InsertUpVote(UpVote instance);