Esempio n. 1
0
        public async Task <ActionResult> Back(ProjectBackBindingModel model)
        {
            var response = await _dataClient.GetProject(model.ProjectId);

            if (response.StatusIsSuccessful)
            {
                model.Project = response.Data;
                if (model.PackageId.HasValue)
                {
                    var packageResponse = await _dataClient.GetPackage(model.PackageId.Value);

                    if (packageResponse.Data != null)
                    {
                        model.Package = packageResponse.Data;
                    }
                }
            }
            if (!ModelState.IsValid)
            {
            }
            model.UserId = _tokenContainer.UserId.Value;

            var request           = Request;
            var urlBase           = string.Format("{0}://{1}", request.Url.Scheme, request.Url.Authority);
            var vivaOrderResponse = await _dataClient.VivaCreateOrder(new OrderOptions
            {
                Amount = Convert.ToInt64(model.Amount * 100)
                         // ReturnUrl= urlBase + "/BackResults"
            });

            if (vivaOrderResponse.StatusIsSuccessful)
            {
                model.VivaOrderId = vivaOrderResponse.Data.OrderCode;
                var responseCreate = await _dataClient.BackProject(model);

                return(new RedirectResult(vivaOrderResponse.Data.RedirectUrl, true));
            }

            //if (responseCreate.StatusIsSuccessful)
            //{
            //    TempData["Success"] = "Backed Project Successfully!";
            //}
            //else
            //    TempData["Error"] = "Did not back project";

            return(RedirectToAction("Back", "Projects", new { projectId = model.ProjectId }));
        }