Exemplo n.º 1
0
        public IActionResult Save(Wizard model)
        {
            try
            {
                if (model == null)
                {
                    throw new ArgumentException("Invalid data.");
                }
                if (!IsValidRecaptcha(model.Captcha))
                {
                    throw new InvalidOperationException("Invalid captcha.");
                }

                var pensionFundContract = PensionFundsServices.CreateCompleteEntry(model.Fund, model.Company, model.Employee);
                return(Json(pensionFundContract));
            }
            catch (Exception e)
            {
                Response.StatusCode = 400;
                if (e is ArgumentException)
                {
                    return(Json(e.Message));
                }
                return(Json("We’re sorry, we had an unexpected error! Please try again in a minute."));
            }
        }
Exemplo n.º 2
0
 public IActionResult ReadWithdrawal(string contractAddress)
 {
     if (!string.IsNullOrEmpty(ConnectionId))
     {
         Task.Factory.StartNew(() =>
         {
             var hubContext = HubConnectionManager.GetHubContext <AuctusDemoHub>();
             try
             {
                 Withdrawal withdrawal = PensionFundsServices.ReadWithdrawal(contractAddress);
                 if (withdrawal == null || withdrawal.Completed)
                 {
                     hubContext.Clients.Client(ConnectionId).withdrawalCompleted(Json(withdrawal).Value);
                 }
                 else
                 {
                     hubContext.Clients.Client(ConnectionId).withdrawalUncompleted(Json(withdrawal).Value);
                 }
             }
             catch (Exception ex)
             {
                 Logger.LogError(new EventId(3), ex, string.Format("Erro on ReadWithdrawal {0}.", contractAddress));
                 hubContext.Clients.Client(ConnectionId).readWithdrawalError();
             }
         });
         return(Json(new { success = true }));
     }
     else
     {
         return(Json(new { success = false }));
     }
 }
Exemplo n.º 3
0
 public IActionResult ReadPayments(string contractAddress)
 {
     if (!string.IsNullOrEmpty(ConnectionId))
     {
         Task.Factory.StartNew(() =>
         {
             var hubContext = HubConnectionManager.GetHubContext <AuctusDemoHub>();
             try
             {
                 if (CanTransactWith(contractAddress))
                 {
                     try
                     {
                         Progress progress = PensionFundsServices.ReadPayments(contractAddress);
                         if (progress.Completed)
                         {
                             hubContext.Clients.Client(ConnectionId).paymentsCompleted(Json(progress).Value);
                         }
                         else
                         {
                             hubContext.Clients.Client(ConnectionId).paymentsUncompleted(Json(progress).Value);
                         }
                     }
                     finally
                     {
                         ReleaseTransactionWith(contractAddress);
                     }
                 }
                 else
                 {
                     hubContext.Clients.Client(ConnectionId).readPaymentsError();
                 }
             }
             catch (Exception ex)
             {
                 Logger.LogError(new EventId(2), ex, string.Format("Erro on ReadPayments {0}.", contractAddress));
                 hubContext.Clients.Client(ConnectionId).readPaymentsError();
             }
         });
         return(Json(new { success = true }));
     }
     else
     {
         return(Json(new { success = false }));
     }
 }
Exemplo n.º 4
0
 public IActionResult GeneratePayment(string contractAddress, int monthsAmount)
 {
     if (CanTransactWith(contractAddress))
     {
         try
         {
             return(Json(PensionFundsServices.GeneratePayment(contractAddress, monthsAmount),
                         new JsonSerializerSettings {
                 ContractResolver = new DefaultContractResolver()
             }));
         }
         finally
         {
             ReleaseTransactionWith(contractAddress);
         }
     }
     else
     {
         return(new EmptyResult());
     }
 }
Exemplo n.º 5
0
 public IActionResult CheckContractCreationTransaction(String transactionHash)
 {
     if (!string.IsNullOrEmpty(ConnectionId))
     {
         Task.Factory.StartNew(() =>
         {
             var hubContext = HubConnectionManager.GetHubContext <AuctusDemoHub>();
             try
             {
                 var pensionFundContract = PensionFundsServices.CheckContractCreationTransaction(transactionHash);
                 if (pensionFundContract.BlockNumber.HasValue)
                 {
                     hubContext.Clients.Client(ConnectionId).deployCompleted(Json(
                                                                                 new
                     {
                         Address         = pensionFundContract.Address,
                         BlockNumber     = pensionFundContract.BlockNumber,
                         TransactionHash = pensionFundContract.TransactionHash
                     }));
                 }
                 else
                 {
                     hubContext.Clients.Client(ConnectionId).deployUncompleted(pensionFundContract.TransactionHash);
                 }
             }
             catch (Exception ex)
             {
                 Logger.LogError(new EventId(1), ex, string.Format("Erro on CheckContractCreationTransaction {0}.", transactionHash));
                 hubContext.Clients.Client(ConnectionId).deployError();
             }
         });
         return(Json(new { success = true }));
     }
     else
     {
         return(Json(new { success = false }));
     }
 }
Exemplo n.º 6
0
 public IActionResult GetWithdrawalInfo(string contractAddress)
 {
     return(Json(PensionFundsServices.GetWithdrawalInfo(contractAddress)));
 }
Exemplo n.º 7
0
 public IActionResult Index(string contractAddress)
 {
     return(View(PensionFundsServices.GetPensionFundInfo(contractAddress)));
 }