public Task <Common.Entity.Result <int> > Update(Common.Entity.Client client)
        {
            Common.Entity.Result <int> result = new Common.Entity.Result <int> {
            };
            try
            {
                using (var context = new BillingContext())
                {
                    ////truncate table
                    context.Client.RemoveRange(context.Client);
                    Log.Info($"Commercial transactions have been deleted in the database....");

                    ////insert new values
                    context.Client.Add(client);
                    context.SaveChanges();
                    Log.Info($"new transactions were inserted....");
                }
            }
            catch (Exception ex)
            {
                result.StatusCode = System.Net.HttpStatusCode.InternalServerError;
                Log.Exception(ex, $"{GetType().FullName}.Update");
            }
            return(Task.FromResult(result));
        }
Example #2
0
        /// <summary>
        /// Save commercial transactions to repository
        /// </summary>
        /// <param name="commercialTransactions"><see cref="Common.Entity.Invoice"/></param>
        /// <returns>bool confirmation</returns>
        /// <history>
        ///    Version      Author              Date         Description
        ///    1.0.0.0      David Vanegas     27/11/2021  Creation
        /// </history>
        public Task <Common.Entity.Result <bool> > Insert(IEnumerable <Common.Entity.InvoiceDetail> invoiceDetail)
        {
            Common.Entity.Result <bool> result = new Common.Entity.Result <bool> {
            };
            try
            {
                invoiceDetail.ToList().ForEach(detail =>
                {
                    using (var context = new BillingContext())
                    {
                        //var IdInvoice = new System.Data.SqlClient.SqlParameter("@IdInvoice", 1);
                        //var RegistrationDate = new System.Data.SqlClient.SqlParameter("@RegistrationDate", DateTime.Now);
                        //var Unit = new System.Data.SqlClient.SqlParameter("@Unit", 1);
                        //var IdProduct = new System.Data.SqlClient.SqlParameter("@IdProduct",1);
                        var res = context.Database.SqlQuery <int>("exec sp_InsertInvoiceDetail @IdInvoice , @RegistrationDate , @Unit , @IdProduct",
                                                                  new System.Data.SqlClient.SqlParameter("@IdInvoice", detail.IdInvoice),
                                                                  new System.Data.SqlClient.SqlParameter("@RegistrationDate", detail.RegistrationDate),
                                                                  new System.Data.SqlClient.SqlParameter("@Unit", detail.Unit),
                                                                  new System.Data.SqlClient.SqlParameter("@IdProduct", detail.Product.IdProduct)
                                                                  ).SingleOrDefault();
                    }
                });

                result.StatusCode = System.Net.HttpStatusCode.OK;
                result.Data       = true;;
                Log.Info($"new transactions were inserted....");
            }
            catch (Exception ex)
            {
                result.StatusCode = System.Net.HttpStatusCode.InternalServerError;
                Log.Exception(ex, $"{GetType().FullName}.Insert");
            }
            return(Task.FromResult(result));
        }
 public Task <Common.Entity.Result <IEnumerable <Common.Entity.Product> > > Get()
 {
     Common.Entity.Result <IEnumerable <Common.Entity.Product> > result = new Common.Entity.Result <IEnumerable <Common.Entity.Product> > {
     };
     using (var context = new BillingContext())
     {
         result.Data = context.Product.ToList();
     }
     return(Task.FromResult(result));
 }
Example #4
0
 /// <summary>
 /// Save commercial transactions to repository
 /// </summary>
 /// <param name="commercialTransactions"><see cref="Common.Entity.Invoice"/></param>
 /// <returns>bool confirmation</returns>
 /// <history>
 ///    Version      Author              Date         Description
 ///    1.0.0.0      David Vanegas     27/11/2021  Creation
 /// </history>
 public Task <Common.Entity.Result <int> > Insert(Common.Entity.Invoice invoices)
 {
     Common.Entity.Result <int> result = new Common.Entity.Result <int> {
     };
     try
     {
         using (var context = new BillingContext())
         {
             result.Data = context.Database.SqlQuery <int>("exec sp_InsertInvoice @RegistrationDate , @Total , @Iva , @IdClient",
                                                           new SqlParameter("@RegistrationDate", DateTime.Now),
                                                           new SqlParameter("@Total", invoices.Total),
                                                           new SqlParameter("@Iva", invoices.Iva),
                                                           new SqlParameter("@IdClient", invoices.Client.IdClient)).SingleOrDefault();
             result.StatusCode = System.Net.HttpStatusCode.OK;
             Log.Info($"new transactions were inserted....");
         }
     }
     catch (Exception ex)
     {
         result.StatusCode = System.Net.HttpStatusCode.InternalServerError;
         Log.Exception(ex, $"{GetType().FullName}.Insert");
     }
     return(Task.FromResult(result));
 }