public async Task Should_Success_Put_UnitPaymentOrder() { CreditorAccountService service = new CreditorAccountService(GetServiceProvider().Object, _dbContext(GetCurrentMethod())); var data = _dataUtil(service).GetNewData_UnitReceiptNotePostedViewModel(); data.SupplierCode = "UPOputTest"; data.Code = "UPOcodePutTest"; data.InvoiceNo = null; var Response = await service.CreateFromUnitReceiptNoteAsync(data); var newData = await service.GetByUnitReceiptNote(data.SupplierCode, data.Code, data.InvoiceNo); Assert.Null(newData.InvoiceNo); CreditorAccountUnitPaymentOrderPostedViewModel postedData = new CreditorAccountUnitPaymentOrderPostedViewModel() { InvoiceNo = "InvoiceNo", CreditorAccounts = new List <CreditorAccountPostedViewModel>() { newData } }; var updateResponse = await service.UpdateFromUnitPaymentOrderAsync(postedData); var updateData = await service.GetByUnitReceiptNote(data.SupplierCode, data.Code, data.InvoiceNo); Assert.NotNull(updateData); }
public async Task <IActionResult> UnitPaymentOrderPut([FromBody] CreditorAccountUnitPaymentOrderPostedViewModel viewModel) { try { VerifyUser(); ValidateService.Validate(viewModel.CreditorAccounts); await Service.UpdateFromUnitPaymentOrderAsync(viewModel); return(NoContent()); } catch (NotFoundException) { Dictionary <string, object> Result = new ResultFormatter(ApiVersion, General.BAD_REQUEST_STATUS_CODE, General.BAD_REQUEST_MESSAGE) .Fail(); return(BadRequest(Result)); } catch (ServiceValidationException e) { Dictionary <string, object> Result = new ResultFormatter(ApiVersion, General.BAD_REQUEST_STATUS_CODE, General.BAD_REQUEST_MESSAGE) .Fail(e); return(BadRequest(Result)); } catch (Exception e) { Dictionary <string, object> Result = new ResultFormatter(ApiVersion, General.INTERNAL_ERROR_STATUS_CODE, e.Message) .Fail(); return(StatusCode(General.INTERNAL_ERROR_STATUS_CODE, Result)); } }
public async Task Should_Success_Put_UnitPaymentOrder_Return_0() { CreditorAccountService service = new CreditorAccountService(GetServiceProvider().Object, _dbContext(GetCurrentMethod())); CreditorAccountUnitPaymentOrderPostedViewModel postedData = new CreditorAccountUnitPaymentOrderPostedViewModel() { InvoiceNo = "InvoiceNo", CreditorAccounts = null }; var updateResponse = await service.UpdateFromUnitPaymentOrderAsync(postedData); Assert.Equal(0, updateResponse); }
public async Task <int> UpdateFromUnitPaymentOrderAsync(CreditorAccountUnitPaymentOrderPostedViewModel viewModel) { if (viewModel.CreditorAccounts != null) { foreach (var item in viewModel.CreditorAccounts) { var creditorAccount = await DbContext.CreditorAccounts.FirstOrDefaultAsync(x => x.SupplierCode == item.SupplierCode && x.UnitReceiptNoteNo == item.Code); if (creditorAccount != null) { creditorAccount.InvoiceNo = viewModel.InvoiceNo; creditorAccount.MemoNo = viewModel.MemoNo; creditorAccount.MemoDate = viewModel.MemoDate; creditorAccount.MemoDPP = item.MemoDPP; //creditorAccount.MemoDPPCurrency = item.MemoDPPCurrency; creditorAccount.MemoMutation = item.MemoMutation; creditorAccount.MemoPPN = item.MemoPPN; //creditorAccount.PaymentDuration = viewModel.PaymentDuration; } //creditorAccount.InvoiceNo = viewModel.InvoiceNo; //creditorAccount.MemoNo = viewModel.MemoNo; //creditorAccount.MemoDate = viewModel.MemoDate; //creditorAccount.MemoDPP = item.MemoDPP; ////creditorAccount.MemoDPPCurrency = item.MemoDPPCurrency; //creditorAccount.MemoMutation = item.MemoMutation; //creditorAccount.MemoPPN = item.MemoPPN; ////creditorAccount.PaymentDuration = viewModel.PaymentDuration; } return(await DbContext.SaveChangesAsync()); } else { return(0); } }