public async Task <ActionResult> Rate(NewsRating newsRating) { var user = await _userManager.FindByEmailAsync(HttpContext.User.Identity.Name); var userId = user.Id; var currentRating = await _context.NewsRatings .FirstOrDefaultAsync(x => x.NewsId == newsRating.NewsId && x.UserId == userId); if (currentRating == null) { newsRating.UserId = userId; newsRating.RatingDate = DateTime.Today; _context.Add(newsRating); await _context.SaveChangesAsync(); } else { currentRating.Rate = newsRating.Rate; await _context.SaveChangesAsync(); } return(NoContent()); }
public async Task Vote(NewsRating newsRating) { var httpResponse = await httpService.Post(urlBase, newsRating); if (!httpResponse.Success) { throw new ApplicationException(await httpResponse.GetBody()); } }