public async Task <IHttpActionResult> AddPopcorn(PopCornViewModel model) { //add popcorn points int userId; var userIdString = User.Identity.GetUserId(); Int32.TryParse(userIdString, out userId); var claims = _applicationUserManager.GetClaimsAsync(userId); var popcorn = claims.Result.FirstOrDefault(x => x.Type == "popcorn"); var popcornPoint = popcorn?.Value; _applicationUserManager.RemoveClaim(userId, popcorn); await _applicationUserManager.AddClaimAsync(userId, new Claim("popcorn", popcornPoint + model.PopcornPoint)); var popcornInfo = GetPopcornInfoClaims(); return(Ok(popcornInfo)); }
public async Task <PopCornViewModel> GetPopcornInfoClaims() { //add popcorn points int userId; var userIdString = User.Identity.GetUserId(); Int32.TryParse(userIdString, out userId); var claims = await _applicationUserManager.GetClaimsAsync(userId); var popcorn = claims.FirstOrDefault(x => x.Type == "popcorn"); var level = claims.FirstOrDefault(x => x.Type == "level"); int popcornPoint; Int32.TryParse(popcorn?.Value, out popcornPoint); int popcornLevel; Int32.TryParse(level?.Value, out popcornLevel); var popcornInfo = new PopCornViewModel(popcornPoint, popcornLevel); return(popcornInfo); }