public IActionResult CreateCustomer([Required] string firstName, [Required] string lastName) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var initialCustomerInfo = new InitialCustomerInfo { FirstName = firstName, LastName = lastName }; try { var customerId = _customerService.CreateCustomerWithOneAccount(initialCustomerInfo); var dto = new CustomerIdDto { Id = customerId.Id }; return(Ok(dto)); } catch (Exception e) { return(Conflict(e)); } }
public async Task <IActionResult> AddAccount([FromBody] CustomerIdDto customer) { Account account = new Account() { AccountNo = 1001 + _accountService.GetAccountCount(customer.CustomerId), AccountNumber = _accountService.GetAccountNumber(), Balance = 0, CustomerId = customer.CustomerId, RegistrationTime = DateTime.Now, isActive = true }; _accountService.Add(account); return(Ok(account)); }
public IActionResult ApplyCashWithdrawal([Required] CustomerIdDto customerId, [Required] decimal amount) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var cid = new CustomerId(customerId.Id); var customerInfo = _customerService.GetCustomerInfoFromId(cid); var operation = new OperationCashWithdrawal(customerInfo.MasterAccountId, amount); var operationResult = _accountService.ApplyOperation(operation); var dto = Map(operationResult); return(Ok(dto)); }
public IActionResult GetCustomerId([Required] string firstName, [Required] string lastName) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var customerId = _customerService.GetCustomerIdFromName(firstName, lastName); if (customerId == null) { return(NoContent()); } var dto = new CustomerIdDto { Id = customerId.Id }; return(Ok(dto)); }
public IActionResult OperationHistory([Required] CustomerIdDto customerId) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var cid = new CustomerId(customerId.Id); var customerInfo = _customerService.GetCustomerInfoFromId(cid); if (customerInfo == null) { return(NoContent()); } var account = _accountService.GetAccountFromId(customerInfo.MasterAccountId); var history = account.OperationHistory.Select(op => op.ToString()).ToList(); return(Ok(history)); }