public Invitation CreateInvitationEntityFromModel(OwnerInvitationModel model, DateTime expirationTime, ApplicationUser creatorPrincipal) { var email = model.SentTo; var userInvited = userBusinessLogic.GetByEmail(email); if (userInvited == null) { userInvited = new Lok.Unik.ModelCommon.Client.User { AppUser = new ApplicationUser { Tenancy = model.Tenancy, ContactEmail = model.SentTo, Status = UserStatus.Invited, DateCreated = DateTime.UtcNow, PrincipalId = string.Format("formsauthentication/{0}", Guid.NewGuid()) } }; userBusinessLogic.CreateNewUser(userInvited, creatorPrincipal); } var list = ContextRegistry.ContextsOf("Principal"); var principalId = list.Single().LocalPath.TrimStart('/'); var invitation = this.ModelToEntity(model); invitation.AcceptingUser = userInvited.AppUser; if (invitation.AuthorizationCode != null) { invitation.AuthorizationCode.ExpirationTime = expirationTime; } invitation.InvitingUserId = principalId; return(invitation); }