public async Task<ActionResult> DirectCapture(OrdersViewModel model) { var selected = from m in model.Orders where m.Selected select m; var orders = await ApiHelpers.LoadAsync<Order>("api/orders"); foreach (var orderVm in selected) { var order = orders.FirstOrDefault(o => o.OrderId == orderVm.OrderId); if (order == null) { ModelState.AddModelError("feedback", string.Format("Error while getting order: {0}", orderVm.OrderId)); return View("Orders"); } var request = new MaintenanceDirectRequest { Operation = "SAS", PayId = order.PayId, PspId = ConfigurationUtil.PspId, UserId = ConfigurationUtil.DirectUserName, Pswd = ConfigurationUtil.DirectPassword }; var response = await ApiHelpers.PostMaintenanceDirectAsync(ConfigurationUtil.DirectMaintenance, request); if (!response.Status.StartsWith("9")) { ModelState.AddModelError("feedback", string.Format("Error while processing order: {0}", OrderStatus.Instance[response.Status])); return View("Orders", model); } } return RedirectToAction("Orders"); }
public async Task<JsonResult> CaptureAsync(OrdersViewModel model) { var selected = from m in model.Orders where m.Selected select m; var orders = await ApiHelpers.LoadAsync<Order>("api/orders"); foreach (var orderVm in selected) { var order = orders.FirstOrDefault(o => o.OrderId == orderVm.OrderId); if (order == null) { return Json(new { ok = false, message = string.Format("Error while getting order: {0}", orderVm.OrderId) }); } var request = new MaintenanceDirectRequest { Operation = "SAS", PayId = order.PayId, PspId = ConfigurationUtil.PspId, UserId = ConfigurationUtil.DirectUserName, Pswd = ConfigurationUtil.DirectPassword }; var response = await ApiHelpers.PostMaintenanceDirectAsync(ConfigurationUtil.DirectMaintenance, request); if (!response.Status.StartsWith("9")) { return Json(new { ok = false, message = OrderStatus.Instance[response.Status] }); } } return Json(new { ok = true }); }