public async Task <BalanceSheetDto> UpdateCurrency([FromBody] UpdateCurrencyRequest currency) { // Validate the contents of the request object before proceeding. var parsedCurrency = IsValidCurrency(currency.TargetCurrency); try { // Main business logic var updatedBalanceSheet = await this.BalanceSheetManager.UpdateCurrencyAsync(parsedCurrency); // Convert to the DTO // Ideally would use something like Automapper here var assetDtos = new List <AssetDto>(); foreach (var asset in updatedBalanceSheet.Assets) { assetDtos.Add(new AssetDto() { Id = asset.Id, Amount = asset.Amount, Description = asset.Description, Group = asset.Group, Order = asset.Order, }); } var liabilityDtos = new List <LiabilityDto>(); foreach (var liabilities in updatedBalanceSheet.Liabilities) { liabilityDtos.Add(new LiabilityDto() { Id = liabilities.Id, Amount = liabilities.Amount, Description = liabilities.Description, Group = liabilities.Group, IntervalAmount = liabilities.IntervalAmount, Order = liabilities.Order, PaymentInterval = liabilities.PaymentInterval, }); } return(new BalanceSheetDto() { Id = updatedBalanceSheet.Id, Currency = updatedBalanceSheet.Currency, NetWorth = updatedBalanceSheet.NetWorth, TotalAssets = updatedBalanceSheet.TotalAssets, TotalLiabilities = updatedBalanceSheet.TotalLiabilities, Assets = assetDtos, Liabilities = liabilityDtos, }); } catch (Exception e) { throw new HttpResponseException() { Status = HttpStatusCode.InternalServerError, Value = e.Message }; } }
public async Task <IActionResult> PutAsync(UpdateCurrencyRequest request, CancellationToken cancellationToken) { _logger.LogInformation("Currencies/PutAsync was requested."); var response = await _currencyService.UpdateAsync(_mapper.Map <CurrencyDto>(request)); return(Ok(_mapper.Map <CurrencyResponse>(response))); }
public async Task <UpdateCurrencyResponse> UpdateAsync(UpdateCurrencyRequest request) { var command = request.ProjectedAs <UpdateCurrencyCommand>(); var response = await mediator.Send(command); if (response.IsSuccess) { unitOfWork.Commit(); } return(response.ProjectedAs <UpdateCurrencyResponse>()); }
public async void UpdateCurrency_ValidInputs_ReturnsBalanceSheetDto() { // Arrange var mockRequest = new UpdateCurrencyRequest() { TargetCurrency = "CAD" }; var mockBalanceSheet = CreateMockBalanceSheet(); var mockBalanceSheetManager = Substitute.For <IBalanceSheetManager>(); mockBalanceSheetManager.UpdateCurrencyAsync(default).ReturnsForAnyArgs(mockBalanceSheet);
public async Task <ErrorCodeResponse <CurrenciesErrorCodesContract> > UpdateAsync( [FromRoute][Required] string id, [FromBody] UpdateCurrencyRequest request) { var currency = _convertService.Convert <UpdateCurrencyRequest, Currency>(request); currency.Id = id; var correlationId = this.TryGetCorrelationId(); var result = await _currenciesService.UpdateAsync(currency, request.UserName, correlationId); var response = new ErrorCodeResponse <CurrenciesErrorCodesContract>(); if (result.IsFailed) { response.ErrorCode = _convertService.Convert <CurrenciesErrorCodes, CurrenciesErrorCodesContract>(result.Error.Value); } return(response); }