Exemplo n.º 1
0
 public Result Deposit(float amount, AbstractAccount account)
 {
     Result result = new Result() { Success = false, Information = "Deposit was not successful" };
     try
     {
         if (account.CanDeposit(amount))
         {
             AccountEntry entry = new AccountEntry()
             {
                 Id = account.NextId,
                 Date = DateTime.Now.Date,
                 Descirption = "Counter withdrawal",
                 Credit = amount
             };
             account.Add(entry.Id, entry);
             result.Information = "Deposit was successful.";
             result.Success = account.ContainsValue(entry);
         } else
         {
             result.Information = "Cannot process deposit.";
             result.Success = false;
         }
     }
     catch (ApplicationException exception)
     {
         result.Success = false;
         result.Information = exception.Message;
         result.Exception = exception;
     }
     return result;
 }
Exemplo n.º 2
0
        public Result Close(AbstractAccount account)
        {
            Result result = new Result() { Success = false, Information = "Attemt to close the account was unsuccessful." };
            try
            {
                if (account.CanClose())
                {
                    account.IsClosed = true;
                    result.Success = true;
                    result.Information = "Account is closed.";
                }
                else
                {
                    result.Information = "Account has a balance.";            
                }
            }
            catch (ApplicationException exception)
            {
                result.Success = false;
                result.Information = exception.Message;
                result.Exception = exception;
            }

            return result;

        }
Exemplo n.º 3
0
 public Result Withdraw(float amount, AbstractAccount account)
 {
     Result result = new Result() { Success = false, Information = "Withrdraw was not successful" };
     try
     {
         if (account.CanWithdraw(amount))
         {
             AccountEntry entry = new AccountEntry()
             {
                 Id = account.NextId,
                 Date = DateTime.Now.Date,
                 Descirption = "Counter withdrawal",
                 Debit = amount
             };
             account.Add(entry.Id, entry);
             result.Information = "Withdwaw was successful.";
             result.Success = account.ContainsValue(entry);
         }
         else
         {
             result.Information = "Insufficient funds.";
             result.Success = false;
         }
     }
     catch (ApplicationException exception)
     {
         result.Success = false;
         result.Information = exception.Message;
         result.Exception = exception;
     }
     return result;
 }
Exemplo n.º 4
0
 public void execute(AbstractAccount acc, int amount)
 {
     if (amount <= 0)
     {
         throw new System.ArgumentException("Invalid amount.");
     }
     acc.Deposit(amount);
 }
Exemplo n.º 5
0
 internal static void CreateNewAccount(AbstractAccount data)
 {
     if (!data.ExistCreditLine)
     {
         data.Balance = 5000;
     }
     AccountRepository.CreateNewAccount(data);
 }
Exemplo n.º 6
0
 internal static void CreateNewAccount(AbstractAccount data)
 {
     //AbstractAccountList accountItems = dblayer.ME.GetItems<AbstractAccountList>("accounts");
     //if(accountItems == null)
     //{
     //    accountItems = new AbstractAccountList();
     //    accountItems.Items = new List<AbstractAccount>();
     //}
     //accountItems.Items.Add(data);
     dblayer.ME.InsertNewItem(data, data.AccountNumber);
 }
Exemplo n.º 7
0
        private static AbstractAccountList GetAllAccounts()
        {
            string              dbdatafolder  = ConfigurationManager.AppSettings["dbdatafolder"];
            DirectoryInfo       directoryInfo = new DirectoryInfo(dbdatafolder);
            AbstractAccountList resultt       = new AbstractAccountList();

            resultt.Items = new List <AbstractAccount>();
            foreach (var filename in directoryInfo.GetFiles())
            {
                AbstractAccount accountItem = dblayer.ME.GetItems <AbstractAccount>(filename.Name);
                resultt.Items.Add(accountItem);
            }
            return(resultt);
        }
Exemplo n.º 8
0
        internal static bool IsValidDataForCreation(AbstractAccount data, JsonFEResult jsonResult)
        {
            bool result = true;

            if (!IsValidAccountNumber(data.AccountNumber, jsonResult) || !NotExistAccountNumber(data.AccountNumber, jsonResult))
            {
                result = false;
            }

            if (string.IsNullOrEmpty(data.OwnerName))
            {
                jsonResult.Success = false;
                jsonResult.ErrorMessage.Add("Missing Owner name");
                return(false);
            }
            return(result);
        }
Exemplo n.º 9
0
 internal static void UpdateAccount(AbstractAccount data)
 {
     dblayer.ME.UpdateItem(data);
 }
Exemplo n.º 10
0
        internal void UpdateItem(AbstractAccount data)
        {
            string dataJson = Newtonsoft.Json.JsonConvert.SerializeObject(data);

            WriteJSONDataFile(dataJson, data.AccountNumber);
        }