Advertisement
Guest User

Untitled

a guest
Aug 13th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. int theId = 33;
  2.  
  3. // Check if the new exists
  4. var theNew =
  5. await this.context
  6. .News
  7. .FirstAsync(x => x.Id == theId);
  8.  
  9. // The new doesn't exist
  10. if (theNew == null)
  11. {
  12. return NotFound();
  13. }
  14.  
  15. // Check if the user has voted the new
  16. var voted =
  17. await this.context
  18. .UserVoteNews
  19. .FirstAsync(x => x.UserId == this.UserId && x.NewId == theId);
  20.  
  21. if (voted == null)
  22. {
  23. return BadRequest(@"User didn't vote");
  24. }
  25. else
  26. {
  27. return Ok("User voted");
  28. }
  29.  
  30. using (var dbContextTransaction = this.context.Database.BeginTransaction())
  31.  
  32. await this.context.SaveChangesAsync();
  33. dbContextTransaction.Commit();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement