Exemplo n.º 1
0
		public PostAccountDto AddAccount(AccountDto accountDto)
		{
			var response = new PostAccountDto { Success = false };
			try
			{
				AccountDto account = new AccountDto();
				account.AccountId = accountDto.AccountId;
				account.AccountName = accountDto.AccountName;
				account.AccountPhone = accountDto.AccountPhone;
				account.DateCreated = System.DateTime.Now;
				account.DateModified = System.DateTime.Now;

				var fileName = "/Users/richdalfonso/Projects/SpeakWriteProject/SpeakWriteProject/test.txt";
				string lines = accountDto.AccountId + "\t" + accountDto.AccountName + "\t" + accountDto.AccountPhone + "\t\r\n";
				File.AppendAllText(fileName, lines);

				//logic to add investment
				response.Account = accountDto;
				response.Success = true;
			}
			catch(System.Exception ex)
			{
				response.Message = ex.ToString(); 
				response.Account = accountDto;
				response.Success = false;
			}
				
			return response;
		}
Exemplo n.º 2
0
		public ServiceResult UpdateAccount(AccountDto accountDto)
		{
			var response = new ServiceResult { Success = false };
			try
			{
				//Update to file system

				response.Message = "Account was updated successfully.";
				response.Success = true;
			}
			catch (System.Exception ex)
			{
				response.Message = ex.ToString();
				response.Success = false;
			}
			return response;
		}
Exemplo n.º 3
0
		public AccountDto FindAccount(string accountNum)
		{
			try
			{
				string line;
				AccountDto account = new AccountDto ();
				account.DateCreated = System.DateTime.Now;
				account.DateModified = System.DateTime.Now;

				var fileName = "/Users/richdalfonso/Projects/SpeakWriteProject/SpeakWriteProject/test.txt";

				using(StreamReader file =  new StreamReader(fileName))
				{
					while((line = file.ReadLine()) != null)
					{
						if (line.Contains (accountNum)) 
						{
							string[] split = line.Split('\t');
							if(split[0] != null )
								account.AccountId = Convert.ToInt32 (split[0]);

							if(split[1] != null )
								account.AccountName = split[1];

							if(split[2] != null )
								account.AccountPhone = split[2];
						} 
					}
				}

				return account;
			}
			catch (System.Exception ex)
			{
				return null;
			}

		}
Exemplo n.º 4
0
		public static void Main (string[] args)
		{
			AccountService _investmentService = new AccountService ();

			Console.WriteLine ("What do you want to do:");
			Console.WriteLine ("1. Enter new account:");
			Console.WriteLine ("2. Edit existing account:");
			Console.WriteLine ("3. Delete existing account:");

			string option = Console.ReadLine();
			if (option == "1") {

				AccountDto account = new AccountDto ();
				account.DateCreated = System.DateTime.Now;
				account.DateModified = System.DateTime.Now;

				String accountNum = null;
				String accountName = null;
				String accountPhone = null;

				//id
				while (String.IsNullOrEmpty(accountNum)) {
					Console.WriteLine("Enter Account number:");
					accountNum = Console.ReadLine ();
				}
				account.AccountId = Convert.ToInt32 (accountNum);

				//name
				while (String.IsNullOrEmpty(accountName) ) {
					Console.WriteLine("Enter Account name:");
					accountName = Console.ReadLine ();
				}
				account.AccountName = accountName;

				//phone
				while (String.IsNullOrEmpty(accountPhone) ) {
					Console.WriteLine("Enter Phone number:");
					accountPhone = Console.ReadLine ();
				}
				account.AccountPhone = accountPhone;

				var response = _investmentService.AddAccount (account);
				if (response.Success) {
					Console.WriteLine ("Account has been added."); 
				}

			} else if (option == "2") {
				Console.WriteLine ("Enter Account number:");
				string accountNum = Console.ReadLine ();
				var response = _investmentService.FindAccount (accountNum);

				if (response != null) {
					Console.WriteLine ("Account found");
					Console.WriteLine ("AccountId: " + response.AccountId);
					Console.WriteLine ("AccountName: " + response.AccountName);
					Console.WriteLine ("AccountPhone: " + response.AccountPhone);
				} else {
					Console.WriteLine ("No Account found for ID: " + accountNum);
				}
				// Suspend the screen.
				//Console.ReadLine();

			} else {
				Console.WriteLine ("Your input is not valid:");
			}

		}