public ReportModel GetReport(string key) { Report report = new Report(); var reportData = reportRepository.GetReport(key, out report); var fileName = ExcelGenerator.GenerateExcel(reportData, key); return(new ReportModel() { Key = key, Name = report.Name, Id = report.Id, Description = report.Description, Procedure = report.Procedure, FileName = fileName, Type = "Excel" }); }
public ActionResult Payment(string planId) { planId = Convert.ToString(Session["PLAN_ID"]); APIContext apiContext = Configuration.GetAPIContext(); UserExercisePlanSelection userExercisePlanSelection = new UserExercisePlanSelection(); if (!string.IsNullOrEmpty(planId)) { userExercisePlanSelection = DataService.GetUserExercisePlanSelection(Convert.ToInt32(planId), User.Identity.Name); } else { throw new Exception("Exercise Plan Selection is empty."); } try { string payerId = Request.Params["PayerID"]; if (string.IsNullOrEmpty(payerId)) { string baseURI = Request.Url.Scheme + "://" + Request.Url.Authority + "/User/Payment?planId=" + planId + "&"; var guid = Convert.ToString((new Random()).Next(100000)); var createdPayment = this.CreatePayment(apiContext, baseURI + "guid=" + guid, userExercisePlanSelection.ExercisePlanId); var links = createdPayment.links.GetEnumerator(); string paypalRedirectUrl = null; while (links.MoveNext()) { Links lnk = links.Current; if (lnk.rel.ToLower().Trim().Equals("approval_url")) { paypalRedirectUrl = lnk.href; } } Session.Add(guid, createdPayment.id); return(Redirect(paypalRedirectUrl)); } else { var guid = Request.Params["guid"]; var paymentId = Request.Params["paymentId"]; var executedPayment = ExecutePayment(apiContext, payerId, paymentId); if (executedPayment.state.ToLower() != "approved") { return(View("FailureView")); } else { string finalExcel = ExcelGenerator.GenerateExcel(User.Identity.Name, Convert.ToInt32(planId)); DataService.InsertPurchases(new Purchase { Id = executedPayment.id, UserId = User.Identity.Name, UserExercisePlanSelectionId = userExercisePlanSelection.Id, ExercisePlanId = userExercisePlanSelection.ExercisePlanId, CartId = executedPayment.cart, CreateTime = DateTime.Parse(executedPayment.create_time), Intent = executedPayment.intent, State = executedPayment.state, Currency = executedPayment.transactions[0].amount.currency, Amount = Convert.ToDouble(executedPayment.transactions[0].amount.total), GenerateExcel = @"~/UserExcels/" + finalExcel }); return(View(viewName: "~/Views/User/PurchaseSuccess.cshtml", model: finalExcel)); } } } catch (Exception ex) { } string fileName = Services.ExcelGenerator.GenerateExcel(User.Identity.Name, 104); return(View(viewName: "~/Views/User/PurchaseSuccess.cshtml", model: fileName)); }