public async Task <IActionResult> BankExpenditureNoteGet([FromQuery] string supplierCode, [FromQuery] string code, [FromQuery] string invoiceNo) { try { CreditorAccountBankExpenditureNotePostedViewModel vm = await Service.GetByBankExpenditureNote(supplierCode, code, invoiceNo); if (vm == null) { Dictionary <string, object> Result = new ResultFormatter(ApiVersion, General.NOT_FOUND_STATUS_CODE, General.NOT_FOUND_MESSAGE) .Fail(); return(NotFound(Result)); } else { Dictionary <string, object> Result = new ResultFormatter(ApiVersion, General.OK_STATUS_CODE, General.OK_MESSAGE) .Ok(Mapper, vm); return(Ok(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 <IActionResult> BankExpenditureNotePut([FromBody] CreditorAccountBankExpenditureNotePostedViewModel viewModel) { try { VerifyUser(); ValidateService.Validate(viewModel); await Service.UpdateFromBankExpenditureNoteAsync(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 <int> UpdateFromBankExpenditureNoteAsync(CreditorAccountBankExpenditureNotePostedViewModel viewModel) { CreditorAccountModel data = await DbSet.FirstOrDefaultAsync(x => x.SupplierCode == viewModel.SupplierCode && x.BankExpenditureNoteNo == viewModel.Code && x.InvoiceNo == viewModel.InvoiceNo); if (data == null) { throw new NotFoundException(); } data.BankExpenditureNoteNo = viewModel.Code; data.BankExpenditureNoteDate = viewModel.Date; data.BankExpenditureNoteMutation = viewModel.Mutation; data.FinalBalance = data.UnitReceiptMutation + (data.BankExpenditureNoteMutation * -1) + data.MemoMutation; UpdateModel(data.Id, data); return(await DbContext.SaveChangesAsync()); }
//public async Task<CreditorAccountMemoPostedViewModel> GetByMemo(string supplierCode, string memoNo, string invoiceNo) //{ // CreditorAccountModel data= await DbSet.FirstOrDefaultAsync(x => x.SupplierCode == supplierCode && x.MemoNo == memoNo && x.InvoiceNo == invoiceNo); // if (data == null) // return null; // return new CreditorAccountMemoPostedViewModel() // { // CreditorAccountId = data.Id, // Code = data.MemoNo, // Date = data.MemoDate.Value, // DPP = data.MemoDPP, // PPN = data.MemoPPN, // InvoiceNo = data.InvoiceNo, // SupplierCode = data.SupplierCode, // SupplierName = data.SupplierName // }; //} public async Task <int> CreateFromBankExpenditureNoteAsync(CreditorAccountBankExpenditureNotePostedViewModel viewModel) { CreditorAccountModel model = await DbSet.FirstOrDefaultAsync(x => x.BankExpenditureNoteNo == null && x.SupplierCode == viewModel.SupplierCode && x.InvoiceNo == viewModel.InvoiceNo); if (model == null) { //do nothing return(1); } model.BankExpenditureNoteDate = viewModel.Date; model.BankExpenditureNoteId = viewModel.Id; model.BankExpenditureNoteMutation = viewModel.Mutation; model.BankExpenditureNoteNo = viewModel.Code; model.FinalBalance = model.UnitReceiptMutation + (model.BankExpenditureNoteMutation * -1) + model.MemoMutation; UpdateModel(model.Id, model); return(await DbContext.SaveChangesAsync()); }
public async Task Should_Fail_Put_BankExpenditureNote() { CreditorAccountService service = new CreditorAccountService(GetServiceProvider().Object, _dbContext(GetCurrentMethod())); CreditorAccountBankExpenditureNotePostedViewModel newData = new CreditorAccountBankExpenditureNotePostedViewModel(); await Assert.ThrowsAnyAsync <NotFoundException>(() => service.UpdateFromBankExpenditureNoteAsync(newData)); }