/// <summary> /// Create an invite and send it to the user. /// </summary> /// <param name="invite"> The invite. </param> /// <param name="userId"> The user id of the person doing the inviting. </param> /// <param name="inviteIndexUri"> The invite Index Uri. </param> /// <returns> The <see cref="InviteViewModel"/>. </returns> public InviteViewModel CreateInvite(InviteViewModel invite, int userId, Uri inviteIndexUri) { // Check if the invite already exists var foundInvite = this.repo.GetInvite(invite.InviteeEmailAddress); if (foundInvite != null) { return(this.ResendInvite(foundInvite, inviteIndexUri) ? this.conversions.ConvertDatabaseModelToViewModel(foundInvite) : null); } var inviteToCreate = this.conversions.ConvertViewModelToDatabaseModel(invite); inviteToCreate.CreatorID = userId; inviteToCreate.CreatedAt = DateTime.Now; inviteToCreate.Token = Guid.NewGuid().ToString(); var createdInvite = this.repo.CreateInvite(inviteToCreate); if (createdInvite == null) { return(null); } var email = new InviteEmail(createdInvite); email.Send(inviteIndexUri); return(this.conversions.ConvertDatabaseModelToViewModel(createdInvite)); }
//public void UpdateInviteSerialEmailAndStatus(int userID, InviteSerialCollection serials) //{ // InviteDao.Instance.UpdateInviteSerialEmailAndStatus(userID, serials); //} public bool SendInviteByEmail(AuthUser operatorUser, Guid serial, string email) { if (AllSettings.Current.EmailSettings.EnableSendEmail == false) { ThrowError(new EmailDisabledError()); return(false); } if (string.IsNullOrEmpty(email)) { ThrowError(new EmptyEmailError("email")); } else if (!ValidateUtil.IsEmail(email) == false) { ThrowError(new EmailFormatError("email", email)); } InviteSerial inviteSerial = this.GetInviteSerial(serial); if (inviteSerial == null || inviteSerial.Status == InviteSerialStatus.Expires || inviteSerial.Status == InviteSerialStatus.Used || inviteSerial.UserID != operatorUser.UserID ) { ThrowError(new InviteSerialError("serial", serial.ToString())); } if (HasUnCatchedError) { return(false); } InviteEmail emailSender = new InviteEmail( email , inviteSerial.Serial , operatorUser.Username , operatorUser.UserID); emailSender.Send(); if (!HasUnCatchedError) { inviteSerial.ToEmail = email; inviteSerial.Status = InviteSerialStatus.Unused; InviteSerialCollection serials = new InviteSerialCollection(); serials.Add(inviteSerial); InviteDao.Instance.UpdateInviteSerialEmailAndStatus(operatorUser.UserID, serials); return(true); } return(false); }
/// <summary> /// The resend invite. /// </summary> /// <param name="invite"> The invite. </param> /// <param name="inviteIndexUri"> The invite index uri. </param> /// <returns> The <see cref="bool"/>. </returns> public bool ResendInvite(Invite invite, Uri inviteIndexUri) { invite.CreatedAt = DateTime.Now; this.repo.UpdateInvite(invite); var email = new InviteEmail(invite); return(email.Send(inviteIndexUri) != null); }
public void SendProviderTest() { using (ShimsContext.Create()) { this.inviteToSend.RoleTypeID = (int)UserRoleType.Provider; var url = "http://localhost/DataEntry/Account/Create"; var email = new InviteEmail(this.inviteToSend); var result = email.Send(new Uri(url)); Assert.IsTrue(result.Contains("Provider")); } }
public void SendAdminTest() { using (ShimsContext.Create()) { var url = "http://localhost/DataEntry/Account/Create"; var builtUrl = "http://localhost/DataEntry/Account/Create?inviteId=4&token=" + this.inviteToSend.Token; var email = new InviteEmail(this.inviteToSend); var result = email.Send(new Uri(url)); Assert.IsTrue(result.Contains(builtUrl)); Assert.IsTrue(result.Contains("Family Services Admin")); } }