protected ActionResult GenerateExcel(PublishAllViewModel model, List <Payment> payments) { var grid = new GridView(); string donorName, beneficiaryName, optOutStatus; var source = from data in payments where data.Beneficiary.Name == model.SelectedBeneficiary select new { data.PaymentID, donorName = data.Name, data.Email, data.Amount, beneficiaryName = data.Beneficiary.Name, data.Currency.CurrencyCode, data.Type.Type, data.Source.Source, data.PaymentDate, optOutStatus = data.OptOut.ToString() }; grid.DataSource = source; grid.DataBind(); SetHeader(grid.HeaderRow.Cells, new string[] { "ID", "Donor Name", "Email", "Amount", "Beneficiary", "Currency", "Type", "Source", "Date", "Opt Out" }); WriteExcel(model, grid); return(RedirectToAction("NewPayment", "Payments")); }
public ActionResult Export(PublishAllViewModel model) { var response = CallAPI <Payment>("http://localhost:4000/api/paymentslistall/GetPaymentsList"); var payments = Deserialize <List <Payment> >(response); if (response.StatusCode == System.Net.HttpStatusCode.OK) { return(GenerateExcel(model, payments)); } return(HttpNotFound()); }
public ActionResult ViewPaymentListAll() { string token = HttpContext.Session["token"].ToString(); var clientT = new RestClient("http://localhost:4000/api/accounts/Validate"); var requestT = new RestRequest(Method.GET); requestT.AddParameter("encrypted", token); var responseT = clientT.Execute <Token>(requestT); JsonDeserializer deserialize = new JsonDeserializer(); Token deserialized = deserialize.Deserialize <Token>(responseT); var client = new RestClient("http://localhost:4000/api/paymentslistall"); var request = new RestRequest(Method.GET); var response = client.Execute <List <Payment> >(request); List <Payment> payments = deserialize.Deserialize <List <Payment> >(response); PublishAllViewModel model = new PublishAllViewModel(payments); return(View("ViewPaymentList", model)); }
public ActionResult ViewPaymentListByBeneficiary(string beneficiarySelected) { string token = HttpContext.Session["token"].ToString(); var clientT = new RestClient("http://localhost:4000/api/accounts/Validate"); var requestT = new RestRequest(Method.GET); requestT.AddParameter("encrypted", token); var responseT = clientT.Execute <Token>(requestT); JsonDeserializer deserialize = new JsonDeserializer(); Token deserialized = deserialize.Deserialize <Token>(responseT); var clientp = new RestClient("http://localhost:4000/api/paymentslistall"); var requestp = new RestRequest(Method.GET); var responsep = clientp.Execute <List <Payment> >(requestp); List <Payment> paymentsp = deserialize.Deserialize <List <Payment> >(responsep); PublishAllViewModel modelp = new PublishAllViewModel(paymentsp); var clientb = new RestClient("http://localhost:4000/api/beneficiariesall"); var requestb = new RestRequest(Method.GET); var responseb = clientb.Execute <List <Beneficiary> >(requestb); List <Beneficiary> beneficiaries = deserialize.Deserialize <List <Beneficiary> >(responseb); BeneficiaryListViewModel modelb = new BeneficiaryListViewModel(beneficiaries); //var client = new RestClient("http://localhost:4000/api/PaymentsListByBeneficiary"); var request = new RestRequest(Method.GET); if (beneficiarySelected != null) { request.AddParameter("beneficiarySelected", beneficiarySelected); } else { beneficiarySelected = modelp.Payments.Select(a => a.Beneficiary.Name).FirstOrDefault(); request.AddParameter("beneficiarySelected", beneficiarySelected); } //var response = client.Execute<List<Payment>>(request); //List<Payment> payments = deserialize.Deserialize<List<Payment>>(response); //PublishAllViewModel model = new PublishAllViewModel(/*payments,*/ beneficiarySelected, paymentsp); PublishAllViewModel model = new PublishAllViewModel(paymentsp); return(View("ViewPaymentList", model)); }
protected virtual void WriteExcel(PublishAllViewModel model, GridView grid) { // error: the file format and extension of don't match excel StringWriter sw = new StringWriter(); HtmlTextWriter htmlTextWriter = new HtmlTextWriter(sw); Response.ClearContent(); Response.Clear(); Response.Buffer = true; Response.AddHeader("Content-Disposition", "attachment;filename=" + GetFileName(model.SelectedBeneficiary)); Response.Charset = ""; Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; grid.RenderControl(htmlTextWriter); Response.Output.Write(sw.ToString()); Response.Flush(); Response.End(); }
public ActionResult ViewPaymentListByBeneficiary3(string beneficiarySelected) { JsonDeserializer deserialize = new JsonDeserializer(); var clientp = new RestClient("http://localhost:4000/api/paymentslistall"); var requestp = new RestRequest(Method.GET); var responsep = clientp.Execute <List <Payment> >(requestp); List <Payment> paymentsp = deserialize.Deserialize <List <Payment> >(responsep); PublishAllViewModel modelp = new PublishAllViewModel(paymentsp); var clientb = new RestClient("http://localhost:4000/api/beneficiariesall"); var requestb = new RestRequest(Method.GET); var responseb = clientb.Execute <List <Beneficiary> >(requestb); List <Beneficiary> beneficiaries = deserialize.Deserialize <List <Beneficiary> >(responseb); BeneficiaryListViewModel modelb = new BeneficiaryListViewModel(beneficiaries); //var client = new RestClient("http://localhost:4000/api/PaymentsListByBeneficiary"); var request = new RestRequest(Method.GET); PublishAllViewModel model; if (beneficiarySelected == "0") { model = new PublishAllViewModel(paymentsp); } else { //beneficiarySelected = modelp.Payments.Select(a => a.Beneficiary.Name).FirstOrDefault(); model = new PublishAllViewModel(/*payments,*/ beneficiarySelected, paymentsp); //request.AddParameter("beneficiarySelected", beneficiarySelected); } //var response = client.Execute<List<Payment>>(request); //List<Payment> payments = deserialize.Deserialize<List<Payment>>(response); model.SelectedBeneficiary = beneficiarySelected; //ViewBag.PaymentList = model; return(PartialView("ViewPaymentList", model)); }