public bool IsVolunteerOrgAdmin(int volunteerId, int organisationId) { var volunteer = _volunteerRepository.GetOrgAdmin(volunteerId, organisationId); return(volunteer != null); }
public async Task <bool> SendVolunteerInviteEmail(Volunteer vol, string token, int orgID, string currentUserEmail, List <KeyValuePair <string, Stream> > Attachments = null) { var sendEmailToAddress = vol.Email_VC; var organisation = vol.Organisation ?? _organisationRepository.GetOrganisation(vol.Organisation_ID); var organisationName = organisation.Name_VC; // get the admin for this organisation var orgadmin = _volunteerRepository.GetOrgAdmin(vol.Organisation_ID); var orgadminname = orgadmin?.FullName_VC ?? ""; var orgAdminEmail = orgadmin.Email_VC; // send email to registrar to complete the process var mail = new MailMessage(); mail.From = new MailAddress("*****@*****.**"); // to and from var adminMail = new MailAddress(sendEmailToAddress); mail.To.Add(adminMail); // set to html mail.IsBodyHtml = true; // import the template to get the subject line and body var subject = ""; // get the communication template string templateName = "InviteVolunteer.html"; string templateEntityType = "Volunteer"; var template = GetTemplate(templateName, orgID, templateEntityType); // If temaplate not exist doesn't send email if (template != null) { // Get Documents to attachments from tamplate ****** var templateAttachments = await _documentDownload.GetAttachmentsByTemplateId(template.Template_ID, orgID); // import the template from blob storage _blobStorage.SetBlobStorage(template.Container_VC); var importedTemplate = _blobStorage.GetBlobHtml(template.BlobName_VC); // substitute the beginning of the URL with test or live account domain var domainName = ConfigurationManager.AppSettings["DomainName"]; var linktocompleteregistration = "<a href=" + domainName + "/Volunteers/VolunteerRegistration?Token=" + token + ">Click here to start the application process now</a>"; var linkToSiteSales = "<a href=\"http://www.test.com\">test</a>"; var privacyLink = "<a href=\"https://\">Privacy</a>"; var legalLink = "<a href=\"https://\">Legal</a>"; // subject subject = template.SubjectLine_VC; subject = subject.Replace("[OrgName]", organisationName); subject = subject.Replace("[FirstName]", vol.FirstName_VC); // and body var tempBody = importedTemplate; tempBody = tempBody.Replace("[OrgName]", organisationName); tempBody = tempBody.Replace("[FirstName]", vol.FirstName_VC); tempBody = tempBody.Replace("[LinkToCompleteRegistration]", linktocompleteregistration); tempBody = tempBody.Replace("[linkToSiteSales]", linkToSiteSales); tempBody = tempBody.Replace("[OrgAdminName]", orgadminname); tempBody = tempBody.Replace("[OrgAdminEmail]", orgAdminEmail); // Footer of body tempBody = tempBody.Replace("[LinkToPrivacy]", privacyLink); tempBody = tempBody.Replace("[LinkToLegal]", legalLink); mail.Body = tempBody; mail.Subject = subject; // If have attachments include in the email if (Attachments != null) { foreach (KeyValuePair <string, Stream> attachment in Attachments) { var mailAttachment = new Attachment(attachment.Value, attachment.Key); mail.Attachments.Add(mailAttachment); } } if (templateAttachments != null) { foreach (KeyValuePair <string, Stream> attachment in templateAttachments) { var mailAttachment = new Attachment(attachment.Value, attachment.Key); mail.Attachments.Add(mailAttachment); } } var entitytype = "Volunteer"; var emailModel = new EmailModel { MandrillEmailMessage = LoadMandrillMessageFromMailMessage(mail), OrganisationId = orgID, EntityId = vol.Volunteer_ID, TemplateId = template.Template_ID, EntityType = entitytype, CurrentUserEmail = currentUserEmail }; SendEmail(emailModel); return(true); } return(false); }