public async Task <IActionResult> AddAsync([FromBody] PointsModification modification) { User user = await _userManager.GetUserAsync(HttpContext.User).ConfigureAwait(false); if (user == null) { return(NotFound("No user with that email exists")); } user.Points += modification.Points; if (user.Points / 1000 > 0 && user.Rank != UserRank.King) { if (user.Rank == UserRank.Squire) { user.Rank = UserRank.Knight; } else { user.Rank = UserRank.King; } } _context.SaveChanges(); return(Ok(new { points = user.Points })); }
public async Task <IActionResult> RemoveAsync([FromBody] PointsModification modification) { User user = await _userManager.GetUserAsync(HttpContext.User).ConfigureAwait(false); if (user == null) { return(NotFound("No user with that email exists")); } user.Points -= modification.Points; _context.SaveChanges(); return(Ok(new { points = user.Points })); }