Ejemplo n.º 1
0
        /// <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);
        }
Ejemplo n.º 2
0
        /// <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();
 }
Ejemplo n.º 4
0
 public InvoiceGridController(IInvoiceData db)
 {
     this.invoiceDb = db;
 }
Ejemplo n.º 5
0
 public InvoiceChartController(IInvoiceData db)
 {
     this.invoiceDb = db;
 }
Ejemplo n.º 6
0
 public InvoiceDetailsVM(IInvoiceData _invoiceData)
 {
     invoiceData = _invoiceData;
 }
 public Invoice CreateInvoice(IInvoiceData invoiceData)
 {
     return new InvloiceDescriptionsContents();
 }
Ejemplo n.º 8
0
 public ImportInvoiceController(IInvoiceData db)
 {
     this.invoiceDb = db;
 }