Exemplo n.º 1
0
 public async Task <int> AddClient(string password)
 {
     try
     {
         return(await _adminManager.AddClient(password));
     }
     catch (Exception ex)
     {
         Logger.Error("Error in AddClient method", ex);
         WebFaultThrower.Throw(ex.Message, HttpStatusCode.InternalServerError);
         throw;
     }
 }
Exemplo n.º 2
0
 public async Task <string> AddAccount(string clientId)
 {
     try
     {
         var id = int.Parse(clientId);
         return(await _adminManager.AddAccount(id));
     }
     catch (Exception ex)
     {
         Logger.Error("Error in AddAccount method", ex);
         WebFaultThrower.Throw(ex.Message, HttpStatusCode.InternalServerError);
         throw;
     }
 }
Exemplo n.º 3
0
        public async Task TransferReceive(TransferRestModel transferRestModel)
        {
            try
            {
                var transferReceiver = new TransferReceiveOperationCommand(transferRestModel);
                await _accountManager.ExecuteOperation(transferReceiver);

                WebOperationContext.Current.OutgoingResponse.StatusCode = HttpStatusCode.Created;
            }
            catch (FaultException ex)
            {
                WebFaultThrower.Throw(ex.Message, HttpStatusCode.NotFound);
            }
            catch (Exception ex)
            {
                log.Error("Error in TransferReceive", ex);
                WebFaultThrower.Throw("An error occurred, please try again later.", HttpStatusCode.InternalServerError);
            }
        }
Exemplo n.º 4
0
        public object BeforeCall(string operationName, object[] inputs)
        {
            try
            {
                var user     = ConfigurationManager.AppSettings["User"];
                var password = ConfigurationManager.AppSettings["Password"];

                var auth = WebOperationContext.Current.IncomingRequest.Headers[HttpRequestHeader.Authorization];
                if (auth != null)
                {
                    if (auth.StartsWith("Basic "))
                    {
                        var cred  = Encoding.UTF8.GetString(Convert.FromBase64String(auth.Substring("Basic ".Length)));
                        var parts = cred.Split(':');
                        if (user == parts[0] && password == parts[1])
                        {
                            return(null);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                log.Error("Error in validation authentication", e);
                WebFaultThrower.Throw("An error occurred, please try again later.",
                                      HttpStatusCode.ServiceUnavailable);
            }

            WebOperationContext.Current.OutgoingResponse.ContentType = "application/json";
            var wfc = new WebFaultException <ErrorDetailWeb>
                          (new ErrorDetailWeb
            {
                Error = "No authorized bank"
            }, HttpStatusCode.Unauthorized);

            throw wfc;
        }
Exemplo n.º 5
0
        public async Task AddBankCharges(string amount)
        {
            try
            {
                var value = int.Parse(amount);
                var bankChargeOperation = new BankChargeOperationCommand(value);
                await _adminManager.AddBankCharges(bankChargeOperation);
            }
            catch (DbUpdateException ex)
            {
                var updateException = (UpdateException)ex.InnerException;
                var sqlException    = (SqlException)updateException.InnerException;

                foreach (SqlError error in sqlException.Errors)
                {
                    // TODO: Do something with your errors
                }
            }
            catch (Exception ex)
            {
                Logger.Error("Error in AddBankCharge method", ex);
                WebFaultThrower.Throw(ex.Message, HttpStatusCode.InternalServerError);
            }
        }