public ActionResult MemberView(int ministryID, string Requestor = "") { GetData(); ViewBag.MinistryID = ministryID; ViewBag.Requestor = Requestor; DateTime aDate = DateTime.Now; ViewBag.aDate = aDate.ToShortDateString(); int id = 0; Dictionary <int, string> MemberRoster; MemberRoster = MinistryMemberRepository.GetMinistryMemberList(ministryID); ViewBag.MemberRoster = new SelectList(MemberRoster, "Key", "Value", id); ViewBag.MinistryName = MinistryRepository.GetMinistryByID(ministryID).MinistryName; IEnumerable <ministrymember> MinistryMembers = MinistryMemberRepository.GetMemintryMemberByMinistry(ministryID).OrderByDescending(e => e.SortOrder); foreach (ministrymember mm in MinistryMembers) { mm.member = MemberRepository.GetMemberByID(mm.memberID); } ViewBag.Members = MinistryMembers; return(PartialView()); }
// public async Task SendMinistryEmail(EmailModel model, string returnURL) public bool SendMinistryEmail(EmailModel model, string returnURL) { try { //string ReturnUrl = Request.UrlReferrer.ToString(); int ContactType1 = ConstantRepository.GetConstantByName("Email & Text").constantID; int ContactType2 = ConstantRepository.GetConstantByName("Email Only").constantID; // var body = "<p>Email From: {0} ({1})</p><p>Message:</p><p>{2}</p>"; var message = new MailMessage(); string[] EmailGroup; int i = 0; int k = 0; int[] VisitorIDGroup; VisitorIDGroup = new int[500]; member m; if ((model.To == "Ministry") && (model.MinistryID > 0)) { k = MinistryMemberRepository.GetMemintryMemberByMinistry(model.MinistryID).Count(); EmailGroup = new string[k]; foreach (ministrymember mm in MinistryMemberRepository.GetMemintryMemberByMinistry(model.MinistryID)) { m = MemberRepository.GetMemberByID(mm.memberID); if ((m != null) && (m.Status == "Active") && (m.EmailAddress != null) && (m.EmailAddress != "") && ((m.ContactTypeID == ContactType1) || ((m.ContactTypeID == ContactType2)))) { EmailGroup[i++] = m.EmailAddress; } } } else if (model.To == "Visitor") { visitor v; int ContactTypeID = ConstantRepository.GetConstantByCategoryName("Best Contact", "Email").constantID; k = VisitorRepository.GetVisitorByBestContact(ContactTypeID).Count(); EmailGroup = new string[k]; VisitorIDGroup = new int[k]; foreach (visitor vv in VisitorRepository.GetVisitorByBestContact(ContactTypeID)) { v = VisitorRepository.GetVisitorByID(vv.visitorID); if ((v != null) && (v.Status == "Active") && (v.Email != null) && (v.Email != "")) { EmailGroup[i] = v.Email; VisitorIDGroup[i++] = v.visitorID; } } } else if (model.To == "ChildrenParents") { k = MemberRepository.GetMemberListCategory("Children").Count(); EmailGroup = new string[k]; foreach (member c in MemberRepository.GetMemberListCategory("Children")) { IEnumerable <member> cp = ChildParentRepository.GetParents(c.memberID); foreach (member mm in cp) { if ((mm != null) && (mm.Status == "Active") && (mm.EmailAddress != null) && (mm.EmailAddress != "") && ((mm.ContactTypeID == ContactType1) || ((mm.ContactTypeID == ContactType2)))) { EmailGroup[i++] = mm.EmailAddress; } } } } else if (model.To == "YouthParents") { k = MemberRepository.GetMemberListCategory("Youth").Count(); EmailGroup = new string[k]; foreach (member c in MemberRepository.GetMemberListCategory("Youth")) { IEnumerable <member> cp = ChildParentRepository.GetParents(c.memberID); foreach (member mm in cp) { if ((mm != null) && (mm.Status == "Active") && (mm.EmailAddress != null) && (mm.EmailAddress != "") && ((mm.ContactTypeID == ContactType1) || ((mm.ContactTypeID == ContactType2)))) { EmailGroup[i++] = mm.EmailAddress; } } } } else { EmailGroup = new string[1]; m = MemberRepository.GetMemberByID(model.MemberID); if ((m.Status == "Active") && (m.EmailAddress != null) && (m.EmailAddress != "") && ((m.ContactTypeID == ContactType1) || ((m.ContactTypeID == ContactType2)))) { EmailGroup[i++] = m.EmailAddress; } } if (model.To == "Visitor") { visitor v; foreach (int x in VisitorIDGroup) { v = VisitorRepository.GetVisitorByID(x); if (v.Title != null) { v.Title2 = ConstantRepository.GetConstantID((int)v.Title).Value1; } model.MemberID = x; model.MemberName = string.Format("{0} {1}", v.Title2, v.FullName); model.MemberEmail = v.Email; //Get senior pastor name string SeniorPastor = ConstantRepository.GetConstantByCategoryName("Misc Category", "Senior Pastor").Value1; if ((SeniorPastor != null) && (SeniorPastor != "")) { model.FromName = SeniorPastor; } Mailer.VisitorEmailOrText(model, ChurchName, ChurchURL, "Text").Send(); } } else { model.EmailString = EmailGroup; model.MinistryName = MinistryRepository.GetMinistryByID(model.MinistryID).MinistryName; Mailer.EmailOrText(model, "Email").Send(); } } catch (Exception ex) { return(false); } //return Redirect(returnURL); return(true); }