public void GetCouplesBothList_Should_Pull_Proper_HoHPeopleID() { /* Excel export should pull proper Head of Household PeopleID*/ var requestManager = FakeRequestManager.Create(); var db = requestManager.CurrentDatabase; var controller = new OnlineRegController(requestManager); var routeDataValues = new Dictionary <string, string> { { "controller", "OnlineReg" } }; controller.ControllerContext = ControllerTestUtils.FakeControllerContext(controller, routeDataValues); var m = OrganizationModel.Create(db, requestManager.CurrentUser); var FakeOrg = FakeOrganizationUtils.MakeFakeOrganization(requestManager); var oid = FakeOrg.org.OrganizationId; m.OrgId = oid; var wife = CreateUser(RandomString(), RandomString()); //Create family and then Execute GetCouplesBothList to see if the right HeadOfHouseHoldId is retrieved... var p = CreateFakeFamily(oid, m, controller); var mailingModel = new MailingController(requestManager); var ExcelCouplesBoth = mailingModel.GetCouplesBothList(m.QueryId, 500); FakeOrganizationUtils.DeleteOrg(FakeOrg.org.OrganizationId); RemoveFakePeopleFromDB(ToPeople(ExcelCouplesBoth), db); }
public ActionResult Csv(Guid id, string format, bool? sortzip, bool? titles, bool? useMailFlags) { var ctl = new MailingController {UseTitles = titles ?? false, UseMailFlags = useMailFlags ?? false}; var sort = "Name"; if (sortzip ?? false) sort = "Zip"; switch (format) { case "Individual": case "GroupAddress": return new CsvResult(ctl.FetchIndividualList(sort, id)); case "FamilyMembers": return new CsvResult(ctl.FetchFamilyMembers(sort, id)); case "Family": return new CsvResult(ctl.FetchFamilyList(sort, id)); case "ParentsOf": return new CsvResult(ctl.FetchParentsOfList(sort, id)); case "CouplesEither": return new CsvResult(ctl.FetchCouplesEitherList(sort, id), couples: true); case "CouplesBoth": return new CsvResult(ctl.FetchCouplesBothList(sort, id), couples: true); } return Content("no format"); }
public ActionResult Excel(Guid id, string format, bool?titles, bool?useMailFlags) { var ctl = new MailingController { UseTitles = titles ?? false, UseMailFlags = useMailFlags ?? false }; switch (format) { case "Individual": case "GroupAddress": return(ExportPeople.FetchExcelList(id, maxExcelRows, useMailFlags ?? false).ToExcel()); case "Library": return(ExportPeople.FetchExcelLibraryList(id)); case "AllFamily": return(ExportPeople.FetchExcelListFamily(id)); case "Family": return(ctl.FetchExcelFamily(id, maxExcelRows)); case "ParentsOf": return(ctl.FetchExcelParents(id, maxExcelRows)); case "CouplesEither": return(ctl.FetchExcelCouplesEither(id, maxExcelRows)); case "CouplesBoth": return(ctl.FetchExcelCouplesBoth(id, maxExcelRows)); case "Involvement": return(new ExcelResult(ExportInvolvements.InvolvementList(id), "Involvements.xls")); case "Children": return(ExportInvolvements.ChildrenList(id, maxExcelRows)); case "Church": return(ExportInvolvements.ChurchList(id, maxExcelRows)); case "Attend": return(ExportInvolvements.AttendList(id, maxExcelRows)); case "Promotion": return(ExportInvolvements.PromoList(id, maxExcelRows)); case "IndividualPicture": return(ExcelExportModel.Result(id)); case "FamilyMembers": return(ExportPeople.FetchExcelListFamilyMembers(id)); case "OrgMembers": return(OrgsMembersExcelModel.Export(Util2.CurrentOrgId ?? 0)); case "Groups": return(ExportInvolvements.OrgMemberListGroups()); } return(Content("no format")); }
public override void ExecuteResult(ControllerContext context) { var Response = context.HttpContext.Response; Response.ContentType = "application/pdf"; Response.AddHeader("content-disposition", "filename=foo.pdf"); var document = new Document(); document.SetPageSize(new Rectangle(72 * W, 72 * H)); document.SetMargins(14f, 0f, 3.6f, 1f); var w = PdfWriter.GetInstance(document, Response.OutputStream); document.Open(); dc = w.DirectContent; var ctl = new MailingController { UseTitles = titles, UseMailFlags = useMailFlags }; IEnumerable <MailingController.MailingInfo> q = null; switch (format) { case "Individual": case "GroupAddress": q = ctl.FetchIndividualList(sort, qid); break; case "FamilyMembers": case "Family": q = ctl.FetchFamilyList(sort, qid); break; case "ParentsOf": q = ctl.FetchParentsOfList(sort, qid); break; case "CouplesEither": q = ctl.FetchCouplesEitherList(sort, qid); break; case "CouplesBoth": q = ctl.FetchCouplesBothList(sort, qid); break; } AddLabel(document, "=========", Util.UserName, "{0} labels printed".Fmt(q.Count()), "{0:g}".Fmt(DateTime.Now), String.Empty); foreach (var m in q) { AddLabel(document, m.LabelName, m.Address, m.Address2, m.CityStateZip, Util.PickFirst(m.CellPhone.FmtFone("C "), m.HomePhone.FmtFone("H "))); } document.Close(); }
public async Task When_GetEmailStatusIsCalled_Then_EmailsRepositoryCallsGetEmailStatusOnce() { // Given var controller = new MailingController(_emailsRepositoryMock.Object, _emailSenderServiceMock.Object); // When await controller.GetEmailStatus(_emailId); // Then _emailsRepositoryMock.Verify(mock => mock.GetEmailStatus(_emailId), Times.Once); }
public async Task When_CreateEmailIsCalled_Then_EmailsRepositoryCallsCreateEmailOnce() { // Given var controller = new MailingController(_emailsRepositoryMock.Object, _emailSenderServiceMock.Object); // When await controller.CreateEmail(_emailDataInputStub); // Then _emailsRepositoryMock.Verify(mock => mock.CreateEmail(_emailDataInputStub), Times.Once); }
public async Task When_CreateEmailIsCalled_WithInvalidEmailInput_Then_ControllersCreateEmail_Returns_500() { // Given _emailsRepositoryMock .Setup(mock => mock.CreateEmail(null)) .ReturnsAsync(new ActionResponse <bool>(false, ErrorResponseMessage)); var controller = new MailingController(_emailsRepositoryMock.Object, _emailSenderServiceMock.Object); // When var result = await controller.CreateEmail(null); // Then var statusCodeResult = result as ObjectResult; Assert.Equal(500, statusCodeResult?.StatusCode); }
public async Task When_CreateEmailIsCalled_WithValidEmailInput_Then_ControllersCreateEmail_Returns_200() { // Given _emailsRepositoryMock .Setup(mock => mock.CreateEmail(_emailDataInputStub)) .ReturnsAsync(new ActionResponse <bool>(true, SuccessResponseMessage)); var controller = new MailingController(_emailsRepositoryMock.Object, _emailSenderServiceMock.Object); // When var result = await controller.CreateEmail(_emailDataInputStub); // Then var statusCodeResult = result as StatusCodeResult; Assert.Equal(200, statusCodeResult?.StatusCode); }
public async Task When_GetPendingEmailsIsCalled_ButThereAreNoEmailsInPendingState_Then_ControllersGetPendingEmails_Returns_404() { // Given _emailsRepositoryMock .Setup(mock => mock.GetPendingEmails()) .ReturnsAsync(new ActionResponse <IEnumerable <EmailDto> >(new List <EmailDto>(), ErrorResponseMessage)); var controller = new MailingController(_emailsRepositoryMock.Object, _emailSenderServiceMock.Object); // When var result = await controller.GetPendingEmails(); // Then var statusCodeResult = result as ObjectResult; Assert.Equal(404, statusCodeResult?.StatusCode); }
public async Task When_GetEmailStatusIsCalled_WithInvalidEmailId_Then_ControllersGetEmailStatus_Returns_404() { // Given _emailsRepositoryMock .Setup(mock => mock.GetEmailStatus(Guid.Empty)) .ReturnsAsync(new ActionResponse <string>(string.Empty, ErrorResponseMessage)); var controller = new MailingController(_emailsRepositoryMock.Object, _emailSenderServiceMock.Object); // When var result = await controller.GetEmailStatus(_emailId); // Then var statusCodeResult = result as ObjectResult; Assert.Equal(404, statusCodeResult?.StatusCode); }
public async Task When_SendPendingEmailsIsCalled_AndThereAreTwoPendingEmails_Then_EmailSenderServiceCallsGetPendingEmailsTwice() { // Given _emailsRepositoryMock .Setup(mock => mock.GetPendingEmails()) .ReturnsAsync(new ActionResponse <IEnumerable <EmailDto> >(new List <EmailDto> { _emailDtoStub, _emailDtoStub }, SuccessResponseMessage)); var controller = new MailingController(_emailsRepositoryMock.Object, _emailSenderServiceMock.Object); // When await controller.SendPendingEmails(); // Then _emailSenderServiceMock.Verify(mock => mock.Send( It.IsAny <string>(), It.IsAny <IEnumerable <string> >(), It.IsAny <string>(), It.IsAny <string>()), Times.Exactly(2)); }
public async Task When_GetEmailStatusIsCalled_WithValidEmailId_Then_ControllersGetEmailStatus_Returns_200() { const string pendingStatus = "Pending"; // Given _emailsRepositoryMock .Setup(mock => mock.GetEmailStatus(_emailId)) .ReturnsAsync(new ActionResponse <string>(pendingStatus, SuccessResponseMessage)); var controller = new MailingController(_emailsRepositoryMock.Object, _emailSenderServiceMock.Object); // When var result = await controller.GetEmailStatus(_emailId); // Then var statusCodeResult = result as ObjectResult; Assert.Equal(200, statusCodeResult?.StatusCode); }
public ActionResult Excel(Guid id, string format, bool? titles, bool? useMailFlags) { var ctl = new MailingController {UseTitles = titles ?? false, UseMailFlags = useMailFlags ?? false}; switch (format) { case "Individual": case "GroupAddress": return ExportPeople.FetchExcelList(id, maxExcelRows, useMailFlags ?? false).ToExcel(); case "Library": return ExportPeople.FetchExcelLibraryList(id); case "AllFamily": return ExportPeople.FetchExcelListFamily(id); case "Family": return ctl.FetchExcelFamily(id, maxExcelRows); case "ParentsOf": return ctl.FetchExcelParents(id, maxExcelRows); case "CouplesEither": return ctl.FetchExcelCouplesEither(id, maxExcelRows); case "CouplesBoth": return ctl.FetchExcelCouplesBoth(id, maxExcelRows); case "Involvement": return ExportInvolvements.InvolvementList(id); case "Involvement2": return ExportInvolvements.InvolvementList(id); case "Children": return ExportInvolvements.ChildrenList(id, maxExcelRows); case "Church": return ExportInvolvements.ChurchList(id, maxExcelRows); case "Attend": return ExportInvolvements.AttendList(id, maxExcelRows); case "Promotion": return ExportInvolvements.PromoList(id, maxExcelRows); case "IndividualPicture": return ExcelExportModel.Result(id); case "FamilyMembers": return ExportPeople.FetchExcelListFamilyMembers(id); case "OrgMembers": return OrgsMembersExcelModel.Export(); case "Groups": return ExportInvolvements.OrgMemberListGroups(); } return Content("no format"); }
public void Initialize() { mail = new Mail { Email = "*****@*****.**" }; mockMailingRepository = new Mock <IMailingRepository>(); mockMailingService = new Mock <IMailingService>(); sut = new MailingController(mockMailingRepository.Object, mockMailingService.Object); mockMailingRepository .Setup(m => m.Retrieve(existingMailingId)) .Returns(mail); mockMailingRepository .Setup(m => m.Retrieve(nonExistingMailingId)) .Returns <Mail>(null); patchedMail = new JsonPatchDocument(); patchedMail.Replace("Email", "*****@*****.**"); }
public ActionResult Csv(Guid id, string format, bool?sortzip, bool?titles, bool?useMailFlags) { var ctl = new MailingController(RequestManager) { UseTitles = titles ?? false, UseMailFlags = useMailFlags ?? false }; var sort = "Name"; if (sortzip ?? false) { sort = "Zip"; } switch (format) { case "Individual": case "GroupAddress": return(new CsvResult(ctl.FetchIndividualList(sort, id))); case "FamilyMembers": return(new CsvResult(ctl.FetchFamilyMembers(sort, id))); case "Family": return(new CsvResult(ctl.FetchFamilyList(sort, id))); case "ParentsOf": return(new CsvResult(ctl.FetchParentsOfList(sort, id))); case "CouplesEither": return(new CsvResult(ctl.FetchCouplesEitherList(sort, id), couples: true)); case "CouplesBoth": return(new CsvResult(ctl.FetchCouplesBothList(sort, id), couples: true)); } return(Content("no format")); }
public void Application_Export_Should_Pull_HoHPeopleID() { var requestManager = FakeRequestManager.Create(); var db = requestManager.CurrentDatabase; var controller = new OnlineRegController(requestManager); var routeDataValues = new Dictionary <string, string> { { "controller", "OnlineReg" } }; controller.ControllerContext = ControllerTestUtils.FakeControllerContext(controller, routeDataValues); var m = OrganizationModel.Create(db, requestManager.CurrentUser); var FakeOrg = FakeOrganizationUtils.MakeFakeOrganization(requestManager); var oid = FakeOrg.org.OrganizationId; m.OrgId = oid; var wife = CreateUser(RandomString(), RandomString()); username = RandomString(); password = RandomString(); string roleName = "role_" + RandomString(); var user = CreateUser(username, password, roles: new string[] { "Access", "Edit", "Admin", "Membership" }); Login(); //Create family and then Execute GetCouplesBothList to see if the right HeadOfHouseHoldId is retrieved... var p = CreateFakeFamily(oid, m, controller); var mailingModel = new MailingController(requestManager); var ExcelCouplesBoth = mailingModel.GetCouplesBothList(m.QueryId, 500); //assert //Finalize FakeOrganizationUtils.DeleteOrg(FakeOrg.org.OrganizationId); RemoveFakePeopleFromDB(ToPeople(ExcelCouplesBoth), db); Logout(); }
public override void ExecuteResult(ControllerContext context) { var ctl = new MailingController { UseTitles = titles ?? false, UseMailFlags = useMailFlags ?? false }; var Response = context.HttpContext.Response; IEnumerable <MailingController.MailingInfo> q = null; switch (format) { case "Individual": q = ctl.FetchIndividualList(sort, id); break; case "GroupAddress": q = ctl.GroupByAddress(sort, id); break; case "Family": case "FamilyMembers": q = ctl.FetchFamilyList(sort, id); break; case "ParentsOf": q = ctl.FetchParentsOfList(sort, id); break; case "CouplesEither": q = ctl.FetchCouplesEitherList(sort, id); break; case "CouplesBoth": q = ctl.FetchCouplesBothList(sort, id); break; default: Response.Write("unknown format"); return; } if (!q.Any()) { Response.Write("no data found"); return; } using (var ms = new MemoryStream()) { var dd = DocX.Create("ttt.docx"); dd.MarginLeft = 30; dd.MarginRight = 24; dd.MarginTop = 48; dd.MarginBottom = 30; dd.PageHeight = 1056; dd.PageWidth = 816; var col = 0; var row = 0; Table tt = null; foreach (var p in q) { if (tt == null || col == 0 && row == 0) { tt = dd.InsertTable(10, 5); foreach (var rr in tt.Rows) { for (var i = 0; i < 5; i++) { rr.Cells[i].VerticalAlignment = VerticalAlignment.Center; rr.Height = 96.0; rr.Cells[i].Width = i % 2 == 0 ? 252.4667 : 11.4; if (i % 2 == 0) { rr.Cells[i].MarginLeft = 30; } } } } if (skip > 0) { row = skip / 3; col = skip % 3; if (col > 0) { col++; } if (col > 2) { col++; } } var c = tt.Rows[row].Cells[col]; if (format == "GroupAddress") { c.Paragraphs[0].InsertText(p.LabelName + " " + p.LastName); } else if ((format == "CouplesEither" || format == "CouplesBoth") && p.CoupleName.HasValue()) { c.Paragraphs[0].InsertText(p.CoupleName); } else { c.Paragraphs[0].InsertText(p.LabelName); } if (p.MailingAddress.HasValue()) { c.InsertParagraph(p.MailingAddress.Trim()); } else { c.InsertParagraph(p.Address); if (p.Address2.HasValue()) { c.InsertParagraph(p.Address2); } c.InsertParagraph(p.CSZ); } col += 2; if (col == 6) { row++; col = 0; if (row == 10) { row = 0; } } } dd.SaveAs(ms); Response.ContentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"; Response.AddHeader("content-disposition", "filename=avery-labels.docx"); Response.AddHeader("content-length", ms.Length.ToString()); Response.BinaryWrite(ms.ToArray()); Response.End(); } }
protected void Page_Load(object sender, EventArgs e) { var context = HttpContext.Current; int?qid = context.Request.QueryString["id"].ToInt2(); var labelNameFormat = context.Request.QueryString["format"]; var ctl = new MailingController(); var sortZip = context.Request.QueryString["sortZip"]; var sort = "Name"; var useTitles = context.Request.QueryString["titles"]; ctl.UseTitles = useTitles == "true"; if (sortZip == "true") { sort = "Zip"; } IEnumerable <MailingController.MailingInfo> q = null; switch (labelNameFormat) { case "Individual": q = ctl.FetchIndividualList(sort, qid.Value); break; case "FamilyMembers": q = ctl.FetchFamilyMembers(sort, qid.Value); break; case "Family": q = ctl.FetchFamilyList(sort, qid.Value); break; case "ParentsOf": q = ctl.FetchParentsOfList(sort, qid.Value); break; case "CouplesEither": q = ctl.FetchCouplesEitherList(sort, qid.Value); break; case "CouplesBoth": q = ctl.FetchCouplesBothList(sort, qid.Value); break; } var r = context.Response; if (q == null) { r.Write("no format"); return; } r.Clear(); r.ContentType = "text/plain"; r.AddHeader("Content-Disposition", "attachment;filename=CMSPeople.csv"); r.Charset = ""; if (!qid.HasValue) { r.Write("no queryid"); r.Flush(); r.End(); } foreach (var mi in q) { r.Write(string.Format("{0},{1},{2},{3},{4},{5},{6}\r\n", mi.LabelName, mi.Address, mi.Address2, mi.City, mi.State, mi.Zip.FmtZip(), mi.PeopleId)); } }
public override void ExecuteResult(ControllerContext context) { var ctl = new MailingController { UseTitles = titles ?? false, UseMailFlags = useMailFlags ?? false }; var Response = context.HttpContext.Response; IEnumerable <MailingController.MailingInfo> q = null; switch (format) { case "Individual": q = ctl.FetchIndividualList(sort, id); break; case "GroupAddress": q = ctl.GroupByAddress(sort, id); break; case "Family": case "FamilyMembers": q = ctl.FetchFamilyList(sort, id); break; case "ParentsOf": q = ctl.FetchParentsOfList(sort, id); break; case "CouplesEither": q = ctl.FetchCouplesEitherList(sort, id); break; case "CouplesBoth": q = ctl.FetchCouplesBothList(sort, id); break; default: Response.Write("unknown format"); return; } if (!q.Any()) { Response.Write("no data found"); return; } Response.ContentType = "application/pdf"; Response.AddHeader("content-disposition", "filename=foo.pdf"); var document = new Document(PageSize.LETTER); document.SetMargins(50f, 36f, 32f, 36f); var w = PdfWriter.GetInstance(document, Response.OutputStream); document.Open(); dc = w.DirectContent; var cols = new float[] { W, W, W - 25f }; var t = new PdfPTable(cols); t.SetTotalWidth(cols); t.HorizontalAlignment = Element.ALIGN_CENTER; t.LockedWidth = true; t.DefaultCell.Border = PdfPCell.NO_BORDER; t.DefaultCell.FixedHeight = H; t.DefaultCell.VerticalAlignment = PdfPCell.ALIGN_MIDDLE; t.DefaultCell.PaddingLeft = 8f; t.DefaultCell.PaddingRight = 8f; t.DefaultCell.SetLeading(2.0f, 1f); if (skip > 0) { var blankCell = new PdfPCell(t.DefaultCell); for (int iX = 0; iX < skip; iX++) { t.AddCell(blankCell); } } foreach (var m in q) { var c = new PdfPCell(t.DefaultCell); var ph = new Paragraph(); if (format == "GroupAddress") { ph.AddLine(m.LabelName + " " + m.LastName, font); } else if ((format == "CouplesEither" || format == "CouplesBoth") && m.CoupleName.HasValue()) { ph.AddLine(m.CoupleName, font); } else { ph.AddLine(m.LabelName, font); } if (m.MailingAddress.HasValue()) { ph.AddLine(m.MailingAddress.Trim(), font); } else { ph.AddLine(m.Address, font); ph.AddLine(m.Address2, font); ph.AddLine(m.CSZ, font); } c.AddElement(ph); if (usephone) { var phone = Util.PickFirst(m.CellPhone.FmtFone("C "), m.HomePhone.FmtFone("H ")); var p = new Paragraph(); c.PaddingRight = 7f; p.Alignment = Element.ALIGN_RIGHT; p.Add(new Chunk(phone, smfont)); p.ExtraParagraphSpace = 0f; c.AddElement(p); } t.AddCell(c); } t.CompleteRow(); document.Add(t); document.Close(); }
protected void Page_Load(object sender, EventArgs e) { var labelNameFormat = Request.QueryString["format"]; int?qid = Request.QueryString["id"].ToInt2(); var r = Response; r.Clear(); var useweb = Request.QueryString["web"]; string header = @"<html xmlns:x=""urn:schemas-microsoft-com:office:excel""> <head> <meta http-equiv=Content-Type content=""text/html; charset=utf-8""> <style> <!--table br {mso-data-placement:same-cell;} tr {vertical-align:top;} td.Text {mso-number-format:\@} --> </style> </head> <body>"; r.Charset = ""; if (!qid.HasValue && labelNameFormat != "Groups") { r.Write("no queryid"); r.Flush(); r.End(); } if (useweb != "true") { r.ContentType = "application/vnd.ms-excel"; r.AddHeader("Content-Disposition", "attachment;filename=CMSPeople.xls"); } r.Write(header); var ctl = new MailingController(); var useTitles = Request.QueryString["titles"]; ctl.UseTitles = useTitles == "true"; var dg = new DataGrid(); dg.EnableViewState = false; switch (labelNameFormat) { case "Individual": dg.DataSource = ExportPeople.FetchExcelList(qid.Value, maxExcelRows); dg.DataBind(); dg.RenderControl(new HtmlTextWriter(r.Output)); break; case "IndividualPicture": GridView1.EnableViewState = false; GridView1.AllowPaging = false; GridView1.DataSource = ExportPeople.FetchExcelListPics(qid.Value, maxExcelRows); GridView1.DataBind(); GridView1.RenderControl(new HtmlTextWriter(r.Output)); break; case "Library": dg.DataSource = ExportPeople.FetchExcelLibraryList(qid.Value); dg.DataBind(); dg.RenderControl(new HtmlTextWriter(r.Output)); break; case "Family": dg.DataSource = ctl.FetchExcelFamily(qid.Value, maxExcelRows); dg.DataBind(); dg.RenderControl(new HtmlTextWriter(r.Output)); break; case "FamilyMembers": FamilyMembers.EnableViewState = false; FamilyMembers.AllowPaging = false; FamilyMembers.DataSource = ExportPeople.FetchExcelListFamilyMembers(qid.Value); FamilyMembers.DataBind(); FamilyMembers.RenderControl(new HtmlTextWriter(r.Output)); break; case "AllFamily": dg.DataSource = ExportPeople.FetchExcelListFamily(qid.Value); dg.DataBind(); dg.RenderControl(new HtmlTextWriter(r.Output)); break; case "ParentsOf": dg.DataSource = ctl.FetchExcelParents(qid.Value, maxExcelRows); dg.DataBind(); dg.RenderControl(new HtmlTextWriter(r.Output)); break; case "CouplesEither": dg.DataSource = ctl.FetchExcelCouplesEither(qid.Value, maxExcelRows); dg.DataBind(); dg.RenderControl(new HtmlTextWriter(r.Output)); break; case "CouplesBoth": dg.DataSource = ctl.FetchExcelCouplesBoth(qid.Value, maxExcelRows); dg.DataBind(); dg.RenderControl(new HtmlTextWriter(r.Output)); break; case "Involvement": dg.DataSource = ExportInvolvements.InvolvementList(qid.Value); dg.DataBind(); dg.RenderControl(new HtmlTextWriter(r.Output)); break; case "Children": dg.DataSource = ExportInvolvements.ChildrenList(qid.Value, maxExcelRows); dg.DataBind(); dg.RenderControl(new HtmlTextWriter(r.Output)); break; case "Church": dg.DataSource = ExportInvolvements.ChurchList(qid.Value, maxExcelRows); dg.DataBind(); dg.RenderControl(new HtmlTextWriter(r.Output)); break; case "Attend": dg.DataSource = ExportInvolvements.AttendList(qid.Value, maxExcelRows); dg.DataBind(); dg.RenderControl(new HtmlTextWriter(r.Output)); break; case "Organization": dg.DataSource = ExportInvolvements.OrgMemberList(qid.Value); dg.DataBind(); dg.RenderControl(new HtmlTextWriter(r.Output)); break; case "Groups": dg.DataSource = ExportInvolvements.OrgMemberListGroups(); dg.DataBind(); dg.RenderControl(new HtmlTextWriter(r.Output)); break; case "Promotion": dg.DataSource = ExportInvolvements.PromoList(qid.Value, maxExcelRows); dg.DataBind(); dg.RenderControl(new HtmlTextWriter(r.Output)); break; } r.Write("</body></HTML>"); r.Flush(); r.End(); }
public override void ExecuteResult(ControllerContext context) { var Response = context.HttpContext.Response; Response.ContentType = "application/pdf"; Response.AddHeader("content-disposition", "filename=foo.pdf"); var document = new Document(); document.SetPageSize(new Rectangle(72 * W, 72 * H)); document.SetMargins(14f, 0f, 3.6f, 1f); var w = PdfWriter.GetInstance(document, Response.OutputStream); document.Open(); dc = w.DirectContent; var ctl = new MailingController { UseTitles = titles, UseMailFlags = useMailFlags }; IEnumerable <MailingController.MailingInfo> q = null; switch (format) { case "Individual": case "GroupAddress": q = ctl.FetchIndividualList(sort, qid); break; case "FamilyMembers": case "Family": q = ctl.FetchFamilyList(sort, qid); break; case "ParentsOf": q = ctl.FetchParentsOfList(sort, qid); break; case "CouplesEither": q = ctl.FetchCouplesEitherList(sort, qid); break; case "CouplesBoth": q = ctl.FetchCouplesBothList(sort, qid); break; } AddLabel(document, "=========", "{0}\n{1},{2:g}".Fmt(Util.UserName, q.Count(), DateTime.Now), String.Empty); foreach (var m in q) { var label = m.LabelName; if (m.CoupleName.HasValue() && format.StartsWith("Couples")) { label = m.CoupleName; } var address = ""; if (m.MailingAddress.HasValue()) { address = m.MailingAddress; } else { var sb = new StringBuilder(m.Address); if (m.Address2.HasValue()) { sb.AppendFormat("\n{0}", m.Address2); } sb.AppendFormat("\n{0}", m.CSZ); address = sb.ToString(); } AddLabel(document, label, address, Util.PickFirst(m.CellPhone.FmtFone("C "), m.HomePhone.FmtFone("H "))); } document.Close(); }