public async Task <IActionResult> CreateCustodianAccount(string storeId, CreateCustodianAccountRequest request, CancellationToken cancellationToken) { request ??= new CreateCustodianAccountRequest(); var custodian = GetCustodianByCode(request.CustodianCode); // Use the name provided or if none provided use the name of the custodian. string name = string.IsNullOrEmpty(request.Name) ? custodian.Name : request.Name; var custodianAccount = new CustodianAccountData() { CustodianCode = custodian.Code, Name = name, StoreId = storeId, }; custodianAccount.SetBlob(request.Config); await _custodianAccountRepository.CreateOrUpdate(custodianAccount); return(Ok(await ToModel(custodianAccount, false, cancellationToken))); }
public async Task <IActionResult> UpdateCustodianAccount(string storeId, string accountId, CreateCustodianAccountRequest request, CancellationToken cancellationToken = default) { request ??= new CreateCustodianAccountRequest(); var custodianAccount = await GetCustodianAccount(storeId, accountId); var custodian = GetCustodianByCode(request.CustodianCode); // TODO If storeId is not valid, we get a foreign key SQL error. Is this okay or do we want to check the storeId first? custodianAccount.CustodianCode = custodian.Code; custodianAccount.StoreId = storeId; custodianAccount.Name = request.Name; custodianAccount.SetBlob(request.Config); await _custodianAccountRepository.CreateOrUpdate(custodianAccount); return(Ok(await ToModel(custodianAccount, false, cancellationToken))); }
public virtual async Task <CustodianAccountData> UpdateCustodianAccount(string storeId, string accountId, CreateCustodianAccountRequest request, CancellationToken token = default) { var response = await _httpClient.SendAsync(CreateHttpRequest($"api/v1/stores/{storeId}/custodian-accounts/{accountId}", bodyPayload : request, method : HttpMethod.Put), token); return(await HandleResponse <CustodianAccountData>(response)); }