/// <inheritdoc /> /// <summary> /// Save an inovice. /// </summary> /// <param name="currentInvoice">Inovice </param> /// <returns>Return true or false</returns> public async Task <bool> SaveAsync(IInvoiceData currentInvoice) { var item = currentInvoice.Value; var retValue = false; using (var dbConnection = SqlExecutor.OpenNewDbConnection()) { if (dbConnection == null) { throw new DataLayerException("Cannot open the database during save"); } // we are sure that the database is open here. var invoice = _mapper.Map <InvoiceViewObject, FACTURAS>(item); try { using (var scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled)) { if (dbConnection.IsPresent <FACTURAS>(invoice)) { // update case. retValue = await dbConnection.UpdateAsync(invoice).ConfigureAwait(false); if ((item.InvoiceItems != null) && (item.InvoiceItems.Any())) { retValue = retValue && await SaveLines(dbConnection, item.InvoiceItems); } } else { // insert case retValue = await dbConnection.InsertAsync(invoice).ConfigureAwait(false) > 0; if ((item.InvoiceItems != null) && (item.InvoiceItems.Any())) { retValue = retValue && await SaveLines(dbConnection, item.InvoiceItems); } } if (retValue) { scope.Complete(); } else { scope.Dispose(); } } } catch (System.Exception e) { throw new DataLayerException("Saving invoices exception. Reason: " + e.Message, e); } } return(retValue); }
/// <inheritdoc /> /// <summary> /// Delete an asynchronous value. /// </summary> /// <param name="invoice"></param> /// <returns></returns> public async Task <bool> DeleteAsync(IInvoiceData invoice) { var retValue = false; if (invoice is NullInvoice) { return(false); } using (var dbConnection = SqlExecutor.OpenNewDbConnection()) { try { using (var scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled)) { var facturas = _mapper.Map <InvoiceViewObject, FACTURAS>(invoice.Value); retValue = await dbConnection.DeleteAsync(facturas); if ((invoice.Value.InvoiceItems == null) || (!invoice.Value.InvoiceItems.Any())) { return(retValue); } var lineas = _mapper.Map <IEnumerable <InvoiceSummaryViewObject>, IEnumerable <LIFAC> >(invoice.Value.InvoiceItems); var entityToDelete = lineas.ToArray(); retValue = retValue && await dbConnection.DeleteCollectionAsync(entityToDelete); scope.Complete(); } } catch (System.Exception ex) { throw new DataAccessLayerException(ex.Message, ex); } } return(retValue); }
public Invoice CreateInvoice(IInvoiceData invoiceData) { return new InvloiceContentsOnly(); }
public InvoiceGridController(IInvoiceData db) { this.invoiceDb = db; }
public InvoiceChartController(IInvoiceData db) { this.invoiceDb = db; }
public InvoiceDetailsVM(IInvoiceData _invoiceData) { invoiceData = _invoiceData; }
public Invoice CreateInvoice(IInvoiceData invoiceData) { return new InvloiceDescriptionsContents(); }
public ImportInvoiceController(IInvoiceData db) { this.invoiceDb = db; }