// POST /api/{userId}/paymentaccounts public HttpResponseMessage <AccountModels.SubmitAccountResponse> Post(string userId, AccountModels.SubmitAccountRequest request) { var user = GetUser(userId); if (user == null) { var message = new HttpResponseMessage <AccountModels.SubmitAccountResponse>(HttpStatusCode.NotFound); message.ReasonPhrase = String.Format("The user id {0} specified in the request is not valid", userId); return(message); } //TODO: validate routing number PaymentAccountType accountType = PaymentAccountType.Checking; if (request.AccountType.ToUpper() == "CHECKING") { accountType = PaymentAccountType.Checking; } else if (request.AccountType.ToUpper() == "SAVINGS") { accountType = PaymentAccountType.Savings; } else { var message = new HttpResponseMessage <AccountModels.SubmitAccountResponse>(HttpStatusCode.BadRequest); message.ReasonPhrase = String.Format("Account Type specified in the request is invalid. Valid account types are {0} or {1}", "Savings", "Checking"); return(message); } PaymentAccount account; try { account = _ctx.PaymentAccounts.Add(new Domain.PaymentAccount() { Id = Guid.NewGuid(), AccountNumber = _securityService.Encrypt(request.AccountNumber), RoutingNumber = _securityService.Encrypt(request.RoutingNumber), NameOnAccount = _securityService.Encrypt(request.NameOnAccount), AccountType = accountType, UserId = user.UserId, IsActive = true, CreateDate = System.DateTime.Now }); _ctx.SaveChanges(); } catch (Exception ex) { var message = new HttpResponseMessage <AccountModels.SubmitAccountResponse>(HttpStatusCode.InternalServerError); message.ReasonPhrase = String.Format("Internal Service Error. {0}", ex.Message); return(message); } _amazonNotificationService.PushSNSNotification(ConfigurationManager.AppSettings["PaymentAccountPostedTopicARN"], "New ACH Account Submitted", account.Id.ToString()); var response = new AccountModels.SubmitAccountResponse() { paymentAccountId = account.Id.ToString() }; var responseMessage = new HttpResponseMessage <AccountModels.SubmitAccountResponse>(response, HttpStatusCode.Created); //TODO: add uri for created account to response header return(responseMessage); }
// PUT /api/users/1/accounts/5 public HttpResponseMessage Put(string id, string accountId, AccountModels.UpdateAccountRequest request) { var user = GetUser(id); if (user == null) { var message = new HttpResponseMessage(HttpStatusCode.NotFound); message.ReasonPhrase = String.Format("The user {0} specified in the request is not valid", id); return(message); } var account = GetAccount(accountId); if (account == null) { var message = new HttpResponseMessage(HttpStatusCode.NotFound); message.ReasonPhrase = String.Format("The account {0} specified in the request is not valid", accountId); return(message); } //TODO: validate routing number PaymentAccountType accountType = PaymentAccountType.Checking; if (request.AccountType.ToUpper() == "CHECKING") { accountType = PaymentAccountType.Checking; } else if (request.AccountType.ToUpper() == "SAVINGS") { accountType = PaymentAccountType.Savings; } else { var message = new HttpResponseMessage(HttpStatusCode.BadRequest); message.ReasonPhrase = String.Format("Account Type specified in the request is invalid. Valid account types are {0} or {1}", "Savings", "Checking"); return(message); } try { account.AccountNumber = _securityService.Encrypt(request.AccountNumber); account.AccountType = accountType; //account.IsActive = true; account.LastUpdatedDate = System.DateTime.Now; account.NameOnAccount = _securityService.Encrypt(request.NameOnAccount); account.RoutingNumber = _securityService.Encrypt(request.RoutingNumber); _ctx.SaveChanges(); } catch (Exception ex) { var message = new HttpResponseMessage(HttpStatusCode.InternalServerError); message.ReasonPhrase = String.Format("Internal Server Error. {0}", ex.Message); return(message); } return(new HttpResponseMessage(HttpStatusCode.OK)); }