Example #1
0
        public Task AddClaimAsync(IdentityUser user, System.Security.Claims.Claim claim)
        {
            if (user == null)
            {
                throw new ArgumentNullException("user");
            }
            if (claim == null)
            {
                throw new ArgumentNullException("claim");
            }

            var u = _unitOfWork.UserRepository.FindById(user.Id);

            if (u == null)
            {
                throw new ArgumentException("IdentityUser does not correspond to a User entity.", "user");
            }

            var c = new Domain.Entities.Claim
            {
                ClaimType  = claim.Type,
                ClaimValue = claim.Value,
                User       = u
            };

            u.Claims.Add(c);

            _unitOfWork.UserRepository.Update(u);
            return(_unitOfWork.SaveChangesAsync());
        }
        public static Claim Load(Domain.Entities.Claim claim)
        {
            if (claim == null)
            {
                return(null);
            }

            return(new Claim
            {
                Type = claim.Type,
                Value = claim.Value,
            });
        }
        internal override HandleResponse HandleIt(CreateClaimCommand request, CancellationToken cancellationToken)
        {
            var claim = new Domain.Entities.Claim()
            {
                ClaimType  = request.ClaimType,
                ClaimValue = request.ClaimValue,
                Name       = request.Name
            };

            var id = _claimRepository.InsertAsync(claim).Result;

            claim.Id = id;

            return(new HandleResponse()
            {
                Content = claim, ContentIdentification = claim.Id
            });
        }