Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int theId = 33;
- // Check if the new exists
- var theNew =
- await this.context
- .News
- .FirstAsync(x => x.Id == theId);
- // The new doesn't exist
- if (theNew == null)
- {
- return NotFound();
- }
- // Check if the user has voted the new
- var voted =
- await this.context
- .UserVoteNews
- .FirstAsync(x => x.UserId == this.UserId && x.NewId == theId);
- if (voted == null)
- {
- return BadRequest(@"User didn't vote");
- }
- else
- {
- return Ok("User voted");
- }
- using (var dbContextTransaction = this.context.Database.BeginTransaction())
- await this.context.SaveChangesAsync();
- dbContextTransaction.Commit();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement