public async Task <IActionResult> Update( [FromRoute] Guid statementId, [FromBody] UpdateStatementRequest model) { model.Id = statementId; var result = await _statementService.Update(model); if (result.Successful) { return(SuccessResponse(result)); } else { return(FailureResponse(result)); } }
public async Task Put_FailureResponse_DuplicateStatement() { //arrange var invoice = await CreateInvoiceAsync(); CreateStatementRequest createModelFirst = new CreateStatementRequest() { Date = DateTime.UtcNow, Notes = "NOTES", Amount = 1, InvoiceId = invoice.Id }; var createViewModelFirst = await CreateStatementAsync(createModelFirst); CreateStatementRequest createModelSecond = new CreateStatementRequest() { Date = DateTime.UtcNow.AddDays(1), Notes = "NOTES", Amount = 1, InvoiceId = invoice.Id }; var createViewModelSecond = await CreateStatementAsync(createModelSecond); var updateModel = new UpdateStatementRequest() { Id = createViewModelSecond.Id, Date = createViewModelFirst.Date, Notes = createViewModelSecond.Notes, Amount = createViewModelSecond.Amount, InvoiceId = createViewModelSecond.InvoiceId }; //act var response = await _client.PutAsync($"/statement/{updateModel.Id}", new StringContent(JsonConvert.SerializeObject(updateModel), Encoding.UTF8, "application/json")); var content = await response.Content.ReadAsStringAsync(); var responseViewModel = JsonConvert.DeserializeObject <FailureResponse>(content); //assert Assert.Equal(HttpStatusCode.Conflict, response.StatusCode); Assert.NotNull(responseViewModel.Message); }
public async Task Put_SuccessResponse() { //arrange var invoice = await CreateInvoiceAsync(); CreateStatementRequest createModel = new CreateStatementRequest() { Date = DateTime.UtcNow, Notes = "NOTES", Amount = 1, InvoiceId = invoice.Id }; var createViewModel = await CreateStatementAsync(createModel); var updateModel = new UpdateStatementRequest() { Id = createViewModel.Id, Date = DateTime.UtcNow.AddDays(1).AddMonths(1).AddYears(1), Notes = "NOTES2", Amount = 2, InvoiceId = invoice.Id }; //act var response = await _client.PutAsync($"/statement/{updateModel.Id}", new StringContent(JsonConvert.SerializeObject(updateModel), Encoding.UTF8, "application/json")); var content = await response.Content.ReadAsStringAsync(); var responseViewModel = JsonConvert.DeserializeObject <SuccessfulResponse <StatementResponse> >(content); //assert Assert.Equal(HttpStatusCode.OK, response.StatusCode); Assert.Equal(updateModel.Date.Day, responseViewModel.Data.Date.Day); Assert.Equal(updateModel.Date.Month, responseViewModel.Data.Date.Month); Assert.Equal(updateModel.Date.Year, responseViewModel.Data.Date.Year); Assert.Equal(0, responseViewModel.Data.Date.Hour); Assert.Equal(0, responseViewModel.Data.Date.Minute); Assert.Equal(0, responseViewModel.Data.Date.Second); Assert.Equal(updateModel.Notes, responseViewModel.Data.Notes); Assert.Equal(updateModel.Amount, responseViewModel.Data.Amount); Assert.Equal(updateModel.InvoiceId, responseViewModel.Data.InvoiceId); Assert.NotEmpty(responseViewModel.Data.Id.ToString()); }
public async Task <Response <StatementResponse> > Update(UpdateStatementRequest viewModel) { var command = _mapper.Map <UpdateStatementCommand>(viewModel); var result = await _mediatorHandler.SendCommand(command); if (result) { var updateEvent = _eventStore.GetEvent <StatementUpdatedEvent>(); var data = _mapper.Map <Expenses.Domain.Models.Statement, StatementResponse>(updateEvent.New); return(SuccessfulResponse(data, updateEvent)); } else { var validationEvent = _eventStore.GetEvent <DomainValidationEvent>(); return(FailureResponse <StatementResponse>(validationEvent)); } }
public void RecordStatement(UpdateStatementRequest request) { var date = DateTime.ParseExact(request.YearMonth, "yyyy-MM", null); if (request.Name != "PayPal" && request.Name != "Landmark Checking" && request.Name != "Landmark Savings") { throw new Exception("Account Name is Invalid"); } var statement = new bank_statement { account_name = request.Name, time = date, starting_balance = request.StartingBalance, ending_balance = request.EndingBalance, income = request.Income, spending = request.Spending, transfers = request.Transfers, fees = request.Fees, }; using var db = new AreaFundingDatabase(); db.Insert(statement); }