public Agency AgencyGetById(string agencyId) { var agencyIdAsInt = 0; try { agencyIdAsInt = Int32.Parse(agencyId); } catch { } return(DashBoardBLL.AgencyGetById(agencyIdAsInt)); }
protected void btnExport_Click(object sender, EventArgs e) { var document = new Document(); var builder = new DocumentBuilder(document); var activities = GetRecentMeetings().OrderByDescending(a => a.DateMeeting).ToList(); var sales = activities.Select(x => x.User).Distinct().ToList(); for (int i = 0; i < sales.Count(); i++) { var needInsertSalesHeader = true; for (int j = 0; j < activities.Count(); j++) { var activity = activities[j] as Activity; var uniqueSales = sales[i]; var salesInActivity = activity.User; if (uniqueSales.Id != salesInActivity.Id) { continue; } var contact = DashBoardBLL.AgencyContactGetById(activity.ObjectId); var contactName = contact != null ? contact.Name : ""; var contactPosition = contact != null ? contact.Position : ""; var dateMeeting = activity.DateMeeting.ToString("dd/MM/yyyy"); var agencyId = 0; try { agencyId = Int32.Parse(activity.Params); } catch { } var agency = DashBoardBLL.AgencyGetById(agencyId); var agencyName = agency != null ? agency.Name : ""; var note = activity.Note; var salesName = uniqueSales.FullName; InsertTableActivityToDocument(builder, needInsertSalesHeader, dateMeeting, salesName, contactName, contactPosition, agencyName, note); needInsertSalesHeader = false; } } Response.Clear(); Response.Buffer = true; Response.ContentType = "application/ms-word"; Response.AppendHeader("content-disposition", "attachment; filename=" + string.Format("Meetings.doc")); MemoryStream m = new MemoryStream(); document.Save(m, SaveFormat.Doc); Response.OutputStream.Write(m.GetBuffer(), 0, m.GetBuffer().Length); Response.OutputStream.Flush(); Response.OutputStream.Close(); m.Close(); Response.End(); }