public virtual Task RedeemAsync(TInvitation invitation, CrmUser <TKey> user, string userHostAddress) { ThrowIfDisposed(); if (invitation == null) { throw new ArgumentNullException("invitation"); } if (user == null) { throw new ArgumentNullException("user"); } Execute(ToRedeemRequests(invitation, user, userHostAddress)); return(Task.FromResult(0)); }
public virtual async Task <IdentityResult> RedeemAsync(TInvitation invitation, CrmUser <TKey> user, string userHostAddress) { ThrowIfDisposed(); if (invitation == null) { throw new ArgumentNullException("invitation"); } if (user == null) { throw new ArgumentNullException("user"); } // validate the invitation if (invitation.MaximumRedemptions > 0 && invitation.Redemptions >= invitation.MaximumRedemptions) { var message = IdentityErrors.InvalidInvitationCode(); return(IdentityResult.Failed(message.Description)); } await Store.RedeemAsync(invitation, user, userHostAddress).WithCurrentCulture(); return(IdentityResult.Success); }
protected virtual IEnumerable <OrganizationRequest> ToRedeemRequests(TInvitation invitation, CrmUser <TKey> user, string userHostAddress) { // updating the invitation var entity = new Entity("adx_invitation") { Id = ToGuid(invitation.InvitationId), EntityState = EntityState.Changed }; // update the redemption counter var redemptions = invitation.Redemptions + 1; entity.SetAttributeValue("adx_redemptions", redemptions); // associate a new redemption entity to the invitation var redemption = new Entity("adx_inviteredemption") { EntityState = EntityState.Created }; redemption.SetAttributeValue("subject", user.UserName); redemption.SetAttributeValue("adx_ipaddress", userHostAddress); redemption.SetAttributeValue("regardingobjectid", entity.ToEntityReference()); redemption.RelatedEntities[new Relationship("adx_invitation_adx_inviteredemptions")] = new EntityCollection(new[] { entity }); if (user.ContactId != null) { // associate the invited contact to the invitation if (invitation.Type == InvitationType.Single) { entity.SetAttributeValue("adx_redeemedcontact", user.ContactId); } else if (invitation.Type == InvitationType.Group) { var contact = new Entity(user.ContactId.LogicalName) { Id = user.ContactId.Id, EntityState = EntityState.Unchanged }; entity.RelatedEntities[new Relationship("adx_invitation_redeemedcontacts")] = new EntityCollection(new[] { contact }); } var activityparty = new Entity("activityparty"); activityparty["partyid"] = user.ContactId; redemption.SetAttributeValue("customers", new EntityCollection(new[] { activityparty })); } yield return(new CreateRequest { Target = redemption }); if (redemptions >= invitation.MaximumRedemptions) { // set invitation to redeemed state yield return(new SetStateRequest { EntityMoniker = entity.ToEntityReference(), State = new OptionSetValue(0), Status = new OptionSetValue(756150001) //Redeemed }); } }