public static EmailRequest UpdateFrom(this EmailRequest thisObject, NewEntityRequest request) { if (thisObject == null) { thisObject = new EmailRequest(); } thisObject.Recipients.Add(new MailAddress(Constants.MicrosoftEmail)); thisObject.IsHtml = true; IUserRepository userRepository = DependencyResolver.Current.GetService(typeof(IUserRepository)) as IUserRepository; switch (request.EntityType) { case EntityType.Community: case EntityType.Folder: case EntityType.Content: { User user = userRepository.GetItem(u => u.UserID == request.UserID); // Update the body and the subject. thisObject.Subject = string.Format(CultureInfo.CurrentUICulture, "New {0} \"{1}\" added to Layerscape", request.EntityType.ToString().ToLower(), request.EntityName); var replacements = new Dictionary<string, string> { { "@@EntityType@@", HttpUtility.UrlDecode(request.EntityType.ToString().ToLower()) }, { "@@EntityName@@", HttpUtility.UrlDecode(request.EntityName) }, { "@@EntityLink@@", HttpUtility.UrlDecode(request.EntityLink) }, { "@@UserName@@", HttpUtility.UrlDecode(user.GetFullName()) }, { "@@UserLink@@", HttpUtility.UrlDecode(request.UserLink) } }; thisObject.MessageBody = FormatMailBodyUsingTemplate("newentityrequest.html", replacements); break; } case EntityType.User: { User user = userRepository.GetItem(u => u.UserID == request.EntityID); // Update the body and the subject. thisObject.Subject = string.Format(CultureInfo.CurrentUICulture, "New {0} \"{1}\" added to Layerscape", request.EntityType.ToString().ToLower(), user.GetFullName()); var replacements = new Dictionary<string, string> { { "@@UserName@@", HttpUtility.UrlDecode(user.GetFullName()) }, { "@@UserLink@@", HttpUtility.UrlDecode(request.EntityLink) } }; thisObject.MessageBody = FormatMailBodyUsingTemplate("newuserrequest.html", replacements); break; } } return thisObject; }
private void SendNewUserMail(ProfileDetails profileDetails, string server) { try { // Send Mail. var request = new NewEntityRequest(); request.EntityType = EntityType.User; request.EntityID = profileDetails.ID; request.EntityName = profileDetails.FirstName + " " + profileDetails.LastName; request.EntityLink = string.Format(CultureInfo.InvariantCulture, "{0}Profile/Index/{1}", server, profileDetails.ID); SendMail(request); } catch (Exception) { // Ignore all exceptions. } }
private void SendNewContentMail(ContentDetails contentDetails, string server) { try { // Send Mail. var request = new NewEntityRequest { EntityType = EntityType.Content, EntityID = contentDetails.ID, EntityName = contentDetails.Name, EntityLink = string.Format(CultureInfo.InvariantCulture, "{0}Content/Index/{1}", server, contentDetails.ID), UserID = contentDetails.CreatedByID, UserLink = string.Format(CultureInfo.InvariantCulture, "{0}Profile/Index/{1}", server, contentDetails.CreatedByID) }; SendMail(request); } catch (Exception) { // Ignore all exceptions. } }
private void SendNewCommunityMail(CommunityDetails communityDetails, string server) { try { // Send Mail. var request = new NewEntityRequest(); request.EntityType = communityDetails.CommunityType == CommunityTypes.Community ? EntityType.Community : EntityType.Folder; request.EntityID = communityDetails.ID; request.EntityName = communityDetails.Name; request.EntityLink = string.Format(CultureInfo.InvariantCulture, "{0}Community/Index/{1}", server, communityDetails.ID); request.UserID = communityDetails.CreatedByID; request.UserLink = string.Format(CultureInfo.InvariantCulture, "{0}Profile/Index/{1}", server, communityDetails.CreatedByID); SendMail(request); } catch (Exception) { // Ignore all exceptions. } }
/// <summary> /// Notify the user about the new entity. /// </summary> /// <param name="notification">New Entity Request details</param> public void NotifyNewEntityRequest(NewEntityRequest notification) { if (Constants.CanSendNewEntityMail) { SendMail(notification); } }