// PUT /api/{userId}/paymentaccounts/{id} public void Put(string userId, string id, AccountModels.UpdateAccountRequest request) { }
// 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)); }