public async Task <IActionResult> Edit(int id, [Bind("Id,UserId,InvId,UpvotesCounter")] Upvotes upvotes) { if (id != upvotes.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(upvotes); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!UpvotesExists(upvotes.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(upvotes)); }
public override int GetHashCode() { var hashCode = 505786036; hashCode = hashCode * -1521134295 + EqualityComparer <string> .Default.GetHashCode(Key); hashCode = hashCode * -1521134295 + EqualityComparer <string> .Default.GetHashCode(Hash); hashCode = hashCode * -1521134295 + EqualityComparer <string> .Default.GetHashCode(SongName); hashCode = hashCode * -1521134295 + EqualityComparer <string> .Default.GetHashCode(SongSubName); hashCode = hashCode * -1521134295 + EqualityComparer <string> .Default.GetHashCode(LevelAuthorName); hashCode = hashCode * -1521134295 + EqualityComparer <string> .Default.GetHashCode(SongAuthorName); hashCode = hashCode * -1521134295 + EqualityComparer <List <DifficultyStats> > .Default.GetHashCode(Diffs); hashCode = hashCode * -1521134295 + Bpm.GetHashCode(); hashCode = hashCode * -1521134295 + PlayedCount.GetHashCode(); hashCode = hashCode * -1521134295 + Upvotes.GetHashCode(); hashCode = hashCode * -1521134295 + Downvotes.GetHashCode(); hashCode = hashCode * -1521134295 + Heat.GetHashCode(); hashCode = hashCode * -1521134295 + Rating.GetHashCode(); return(hashCode); }
public async Task <IActionResult> Create([Bind("Id,UserId,InvId,UpvotesCounter")] Upvotes upvotes) { if (ModelState.IsValid) { _context.Add(upvotes); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(upvotes)); }
public void Downvote(ulong id) { if (Downvotes.Contains(id)) { return; } if (Upvotes.Contains(id)) { Upvotes.Remove(id); } Downvotes.Add(id); }
private int UpvoteExists(int EventId, int UserId) { try { Upvotes Upvote = new Upvotes(); Upvote = _dbcontext.Upvote.Single(x => x.EventId == EventId && x.UserId == UserId); return(Upvote.Value); // 1 || -1 } catch (System.Exception) { return(0); // brak wpisu } }
public JsonResult Minus([FromBody] Upvotes Upvotes) { string header = HttpContext.Request.Headers["VerySecureHeader"]; if (header == "" || !LoggedIn.Contains(header)) { var Error = new { Code = 3, Type = "Upvote", Desc = "User not logged in" }; Response.StatusCode = 403; //Forbidden return(Json(Error)); } return(Json(new Upvote(_dbcontext).Negative(Upvotes.UserId, Upvotes.EventId))); }
public void DownvotePost(User user) { var isDownvoted = Downvotes.Contains(user); if (!isDownvoted) { Downvotes.Add(user); if (Upvotes.Contains(user)) { var index = Upvotes.IndexOf(user); Upvotes.RemoveAt(index); } } else { var index = Downvotes.IndexOf(user); Downvotes.RemoveAt(index); } }
public async Task <IActionResult> Upvotes(int id) { Report report = _reportRepository.GetReportsById(id); Upvotes temp = _upvotesRepository.UpvoteExists(report, await _userManager.GetUserAsync(User)); // if upvote doesn't exist already if (temp == null) { Upvotes newUpvote = new Upvotes() { Reporter = await _userManager.GetUserAsync(User), Report = report }; _upvotesRepository.AddUpvote(newUpvote); _reportRepository.IncrementUpvote(id); } else // upvote already exists, therefore remove the upvote { _upvotesRepository.UndoUpvote(report, await _userManager.GetUserAsync(User)); _reportRepository.DecrementUpvote(id); } return(RedirectToAction("ReportDetails", new { id })); }
public JsonResult Points([FromBody] Upvotes Upvotes) { return(Json(new Upvote(_dbcontext).Points(Upvotes.EventId))); }
public dynamic Negative(int UserId, int EventId) { if (!UserExists(UserId)) { var Error = new { Code = 1, Type = "Upvote", Desc = "User does not exist" }; return(Error); } // sprawdzanie czy istnieje użyszkodnik if (!EventExists(EventId)) { var Error = new { Code = 2, Type = "Upvote", Desc = "Event does not exist" }; return(Error); } //sprawdzanie czy istnieje event o danym id int UpvoteValue = UpvoteExists(EventId, UserId); Upvotes Upvote = new Upvotes(); if (UpvoteValue == 0) { //brak wpisu dla kombinacji UxE --> dodanie informacji do bazy Upvote.EventId = EventId; Upvote.UserId = UserId; Upvote.Value = -1; _dbcontext.Upvote.Add(Upvote); _dbcontext.SaveChanges(); } else { if (UpvoteValue == -1) //usuwanie wpisu { Upvote = _dbcontext.Upvote.Single(x => x.UserId == UserId && x.EventId == EventId); _dbcontext.Remove(Upvote); _dbcontext.SaveChanges(); } else if (UpvoteValue == 1) // modyfikowanie wpisu { Upvote = _dbcontext.Upvote.Single(x => x.UserId == UserId && x.EventId == EventId); Upvote.Value = -1; _dbcontext.SaveChanges(); } } var Message = new { Code = 0, Type = "Upvote", Desc = "Success" }; return(Message); }