public async Task UpdateArInvoiceEntryDocumentUnit(ArInvoiceEntryDocumentInputUnit input) { var arInvoiceTransactionsInput = await _arInvoiceEntryDocumentUnitRepository.GetAsync(input.AccountingDocumentId); Mapper.Map(input, arInvoiceTransactionsInput); await _arInvoiceEntryDocumentUnitManager.UpdateAsync(arInvoiceTransactionsInput); if (!ReferenceEquals(input.InvoiceEntryDocumentDetailList, null)) { //Bulk CRUD operations of InvoiceEntryDocumentDetails foreach (var invoiceEntryDocumentDetail in input.InvoiceEntryDocumentDetailList) { if (invoiceEntryDocumentDetail.AccountingItemId == 0) { invoiceEntryDocumentDetail.AccountingDocumentId = input.AccountingDocumentId; var invoiceEntryDocumentDetailUnit = invoiceEntryDocumentDetail.MapTo <ArInvoiceEntryDocumentDetailUnit>(); await _arInvoiceEntryDocumentDetailUnitManager.CreateAsync(invoiceEntryDocumentDetailUnit); } else if (invoiceEntryDocumentDetail.AccountingItemId > 0) { var invoiceEntryDocumentDetailUnit = await _arInvoiceEntryDocumentDetailUnitRepository.GetAsync( invoiceEntryDocumentDetail.AccountingItemId); Mapper.Map(invoiceEntryDocumentDetail, invoiceEntryDocumentDetailUnit); await _arInvoiceEntryDocumentDetailUnitManager.UpdateAsync(invoiceEntryDocumentDetailUnit); } else { IdInput <long> idInput = new IdInput <long>() { Id = (invoiceEntryDocumentDetail.AccountingItemId * (-1)) }; await _arInvoiceEntryDocumentDetailUnitManager.DeleteAsync(idInput); } } } await CurrentUnitOfWork.SaveChangesAsync(); }
public async Task <IdOutputDto <long> > CreateArInvoiceEntryDocumentUnit(ArInvoiceEntryDocumentInputUnit input) { var arInvoiceTransactions = input.MapTo <ArInvoiceEntryDocumentUnit>(); IdOutputDto <long> response = new IdOutputDto <long> { Id = await _arInvoiceEntryDocumentUnitManager.CreateAsync(arInvoiceTransactions) }; //Null Checking of InvoiceEntryDocumentDetailList if (!ReferenceEquals(input.InvoiceEntryDocumentDetailList, null)) { //Bulk Insertion of InvoiceEntryDocumentDetails foreach (var invoiceEntryDocumentDetail in input.InvoiceEntryDocumentDetailList) { invoiceEntryDocumentDetail.AccountingDocumentId = response.Id; var invoiceEntryDocumentDetailUnit = invoiceEntryDocumentDetail.MapTo <ArInvoiceEntryDocumentDetailUnit>(); await _arInvoiceEntryDocumentDetailUnitManager.CreateAsync(invoiceEntryDocumentDetailUnit); } } await CurrentUnitOfWork.SaveChangesAsync(); return(response); }