private void MoveFromMailTemplate() { if (UserContext.isAnonymous) { View.DisplaySessionTimeout(); } else { Boolean sendMail = View.SendMailToUsers; lm.Comol.Core.Mail.dtoMailContent mailContent = View.MailContent; if (!sendMail || (sendMail && View.MailContent != null && !string.IsNullOrEmpty(mailContent.Body))) { View.GotoStep(ProfileImportStep.Summary, true); } } }
private void SendMailToProfiles(List <ProfileImportAction> actions, List <dtoImportedProfile> profiles, lm.Comol.Core.Mail.dtoMailContent mailContent, List <ProfileAttributeType> attributes, List <dtoImportedProfile> notSentMail) { Int32 index = 1; Boolean mailSent = false; Int32 actionIndex = actions.Count() - ((actions.Contains(ProfileImportAction.AddToOtherOrganizations) || actions.Contains(ProfileImportAction.AddToCommunities)) ? 1 : 0); Person currentUser = CurrentManager.GetPerson(UserContext.CurrentUserID); lm.Comol.Core.Mail.MailService mailService = new lm.Comol.Core.Mail.MailService(View.CurrentSmtpConfig, mailContent.Settings); Language dLanguage = CurrentManager.GetDefaultLanguage(); foreach (dtoImportedProfile profile in profiles) { if (currentUser != null) { lm.Comol.Core.Mail.dtoMailMessage message = new lm.Comol.Core.Mail.dtoMailMessage(mailContent.Subject, AnalyzeBody(mailContent.Body, profile, attributes)); message.FromUser = new System.Net.Mail.MailAddress(currentUser.Mail, currentUser.SurnameAndName); message.To.Add(new System.Net.Mail.MailAddress(profile.Profile.Mail, profile.Profile.DisplayName)); //'dtoMessage.To.Add() mailSent = (mailService.SendMail(currentUser.LanguageID, dLanguage, message) == Mail.MailException.MailSent); } else { View.UpdateSendMailToProfile(actionIndex, profiles.Count, index, mailSent, profile.Profile.DisplayName); } if (!mailSent) { notSentMail.Add(profile); } index++; } }
public void ImportProfiles( dtoImportSettings settings, Int32 defaultIdOrganization, List <Int32> allOrganizationsId, ProfileExternalResource selectedItems, List <dtoNewProfileSubscription> subscriptions, Boolean sendMailToUsers, lm.Comol.Core.Mail.dtoMailContent mailContent) { List <ProfileImportAction> actions = new List <ProfileImportAction>(); View.PreviousStep = ProfileImportStep.None; actions.Add(ProfileImportAction.Create); if (allOrganizationsId.Where(id => id != defaultIdOrganization).Any()) { actions.Add(ProfileImportAction.AddToOtherOrganizations); } actions.Add(ProfileImportAction.AddToCommunities); if (sendMailToUsers) { actions.Add(ProfileImportAction.SendMail); } View.SetupProgressInfo(actions.Count, selectedItems.Rows.Count); // Create profiles List <dtoBaseProfile> notCreatedProfiles = new List <dtoBaseProfile>(); List <dtoImportedProfile> createdProfiles = new List <dtoImportedProfile>(); List <Person> profiles = CreateProfiles(settings, defaultIdOrganization, selectedItems, createdProfiles, notCreatedProfiles); Dictionary <Int32, String> notaddedToOrganizations = new Dictionary <Int32, String>(); Dictionary <Int32, String> notSubscribedCommunities = new Dictionary <Int32, String>(); List <dtoImportedProfile> notSentMail = new List <dtoImportedProfile>(); if (profiles != null && profiles.Count > 0) { AddProfilesToOrganizations(defaultIdOrganization, allOrganizationsId, profiles, subscriptions.Where(s => s.IdCommunityType == 0).ToList(), notaddedToOrganizations); AddProfilesToCommunities(actions, profiles, subscriptions.Where(s => s.IdCommunityType != 0).ToList(), notSubscribedCommunities); if (sendMailToUsers) { SendMailToProfiles(actions, createdProfiles, mailContent, Service.GetProfileTypeMailTemplateAttributes(settings), notSentMail); } } View.UpdateSourceItems(View.CurrentSource); Int32 itemsToSelect = View.ItemsToSelect; View.PreviousStep = (itemsToSelect > 0) ? ProfileImportStep.ItemsSelctor : ProfileImportStep.None; if (notCreatedProfiles.Count == 0 && notaddedToOrganizations.Count == 0 && notSubscribedCommunities.Count == 0 && notSentMail.Count == 0) { View.isCompleted = (itemsToSelect == 0); View.DisplayImportedProfiles(profiles.Count, itemsToSelect); } else { View.DisplayImportError(profiles.Count, notCreatedProfiles, notaddedToOrganizations, notSubscribedCommunities, notSentMail); } }