public Invitation InviteUser(User user, string invitationLink, DateTime expiration, string personalMessage, bool signEmail) { var invitation = this.context.Invitations.FirstOrDefault(i => i.User.UserId == user.UserId && i.ActivationDateTime == null); if (invitation == null) { invitation = new Invitation { InvitationId = Guid.NewGuid(), User = user, Email = user.Email, ExpirationDateTime = expiration, CreationDateTime = DateTime.UtcNow, SentDateTime = DateTime.UtcNow }; this.context.Invitations.AddObject(invitation); } invitation.ExpirationDateTime = expiration; if (user.Email != invitation.Email) { invitation.Email = user.Email; } this.context.SaveChanges(); // Send invitation link invitationLink += "/" + invitation.InvitationId; this.SendNotification(invitation, invitationLink, personalMessage, signEmail); return invitation; }
public void ActivateUserInvitation(Invitation invitation, User user) { invitation.ActivationDateTime = DateTime.UtcNow; this.context.SaveChanges(); }
/// <summary> /// Deprecated Method for adding a new object to the Invitations EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToInvitations(Invitation invitation) { base.AddObject("Invitations", invitation); }
private void SendNotification(Invitation invitation, string invitationLink, string personalMessage, bool signEmail) { if (personalMessage == null) { personalMessage = string.Empty; } personalMessage = personalMessage.Replace("\n", "\n<br/>"); var notificationSubject = string.Format(CultureInfo.InvariantCulture, "{0} wants to invite you to Blob Share", GetCurrentUserName()); string signature = string.Empty; if (signEmail) { signature = string.Format("Thanks, {0}", GetCurrentUserIdentityName()); } var notificationTemplate = new StringBuilder() .Append("<html>") .Append("<body link=\"#ff6600\" vlink=\"#ff6600\">") .Append("<div>") .Append("<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" style=\"border-collapse:collapse;border:none\">") .Append("<tr>") .Append("<td valign=\"top\" style=\"height:18pt; width:13.8pt;background:#e6e6e6;padding:0cm 5.4pt 0cm 5.4pt\"></td>") .Append("<td colspan=\"2\" valign=\"top\" style=\"width:424.0pt;background:#e6e6e6;padding:0cm 5.4pt 0cm 5.4pt\"></td>") .Append("<td valign=\"top\" style=\"width:13.8pt;background:#e6e6e6;padding:0cm 5.4pt 0cm 5.4pt\"></td>") .Append("</tr>") .Append("<tr>") .Append("<td valign=\"top\" style=\"width:13.8pt;background:#e6e6e6;padding:0cm 5.4pt 0cm 5.4pt\"></td>") .Append("<td valign=\"top\" style=\"width:70.85pt;padding:5.4pt 0cm 0cm 0cm\"><img src=\"cid:logo\"/></td>") .Append("<td valign=\"top\" style=\"width:353.15pt;padding:0cm 5.4pt 0cm 5.4pt\">") .Append("<p><span style='font-size:11.0pt;font-family:\"Calibri\",\"sans-serif\";color:#7b8185'><br>Hi! You've been invited to Blob Share. </span></p>") .Append("<p></p><p><span style='font-size:11.0pt;font-family:\"Calibri\",\"sans-serif\";color:#7b8185'>Blob Share is a Windows Azure based application that allows you to upload, view, download and share your blobs on the cloud. Start using Blob Share now.</span></p><p></p>") .Append("<p><span style='font-size:11.0pt;font-family:\"Calibri\",\"sans-serif\";color:#7b8185'>In order to accept this invitation, please visit the following URL: <a style='font-size:11.0pt;font-family:\"Calibri\",\"sans-serif\";color:#ff6600' href=\"{activationUri}\">{activationUri}</a></span></p><p><span style='font-size:11.0pt;font-family:\"Calibri\",\"sans-serif\";color:#7b8185'>{personalMessage}</span></p><p><span style='font-size:11.0pt;font-family:\"Calibri\",\"sans-serif\";color:#7b8185'>{signature}</span></p><br>") .Append("<td valign=\"top\" style=\"width:13.8pt;background:#e6e6e6;padding:0cm 5.4pt 0cm 5.4pt\"></p></td>") .Append("</tr>") .Append("<tr>") .Append("<td valign=\"top\" style=\"height:18pt; width:13.8pt;background:#e6e6e6;padding:0cm 5.4pt 0cm 5.4pt\"></td>") .Append("<td colspan=\"2\" valign=\"top\" style=\"width:424.0pt;background:#e6e6e6;padding:0cm 5.4pt 0cm 5.4pt\"></td>") .Append("<td valign=\"top\" style=\"width:13.8pt;background:#e6e6e6;padding:0cm 5.4pt 0cm 5.4pt\"></td>") .Append("</tr>") .Append("</table>") .Append("</div>") .Append("</body>") .Append("</html>"); var messageParameters = new Dictionary<string, string> { { "{signature}", signature }, { "{activationUri}", invitationLink }, { "{personalMessage}", personalMessage } }; using (LinkedResource logo = new LinkedResource(HttpContext.Current.Server.MapPath("~/Content/Images/home_bg_mail.jpg"), MediaTypeNames.Image.Jpeg)) { logo.ContentId = "logo"; logo.TransferEncoding = TransferEncoding.Base64; this.notificationService.SendNotification(new string[] { invitation.Email }, notificationSubject, notificationTemplate.ToString(), logo, messageParameters); } }
/// <summary> /// Create a new Invitation object. /// </summary> /// <param name="invitationId">Initial value of the InvitationId property.</param> /// <param name="email">Initial value of the Email property.</param> /// <param name="privilege">Initial value of the Privilege property.</param> /// <param name="creationDateTime">Initial value of the CreationDateTime property.</param> /// <param name="expirationDateTime">Initial value of the ExpirationDateTime property.</param> public static Invitation CreateInvitation(global::System.Guid invitationId, global::System.String email, global::System.Int32 privilege, global::System.DateTime creationDateTime, global::System.DateTime expirationDateTime) { Invitation invitation = new Invitation(); invitation.InvitationId = invitationId; invitation.Email = email; invitation.Privilege = privilege; invitation.CreationDateTime = creationDateTime; invitation.ExpirationDateTime = expirationDateTime; return invitation; }