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>
        /// method for send a GET request
        /// </summary>
        /// <param name="webServiceRequest"><see cref="Common.Entity.WebServiceRequest"/></param>
        /// <returns><see cref="Entity.Result{T}"/></returns>
        /// <history>
        ///    Version      Author              Date         Description
        ///    1.0.0.0      David Vanegas     27/11/2021  Creation
        /// </history>
        public async Task <Common.Entity.Result <HttpResponseMessage> > GetAsync(Common.Entity.WebServiceRequest webServiceRequest)
        {
            Common.Entity.Result <HttpResponseMessage> result = new Common.Entity.Result <HttpResponseMessage> {
            };
            try
            {
                using (HttpClient client = new HttpClient(new HttpClientHandler
                {
                    UseDefaultCredentials = false
                }))
                {
                    ////base address
                    client.BaseAddress = new Uri(webServiceRequest.Uri);
                    // Update port # in the following line.
                    client.DefaultRequestHeaders.Accept.Clear();
                    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(webServiceRequest.MediaType));
                    HttpResponseMessage response = new HttpResponseMessage();
                    ////execute get request
                    response = await client.GetAsync(webServiceRequest.Uri);

                    result.Data = response;
                };
            }
            catch (Exception ex)
            {
                result.StatusCode = HttpStatusCode.InternalServerError;
                result.Message    = ex.Message;
            }
            return(result);
        }
Example #3
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 #5
0
 public async Task <Common.Entity.Result <int> > Update(Common.Entity.Client client)
 {
     Common.Entity.Result <int> result = new Common.Entity.Result <int> {
     };
     try
     {
         result = await ClientService.Update(client);
     }
     catch (Exception ex)
     {
         result.StatusCode = System.Net.HttpStatusCode.InternalServerError;
         Log.Exception(ex, $"{GetType().FullName}.Update");
     }
     return(await Task.FromResult(result));
 }
Example #6
0
 /// <summary>
 /// </summary>
 /// <param name="InvoiceDetail"><see cref="Entity.InvoiceDetail"/>convertion rate</param>
 /// <returns></returns>
 /// <history>
 ///    Version      Author              Date         Description
 ///    1.0.0.0      David Vanegas     27/11/2021  Creation
 /// </history>
 public async Task <Common.Entity.Result <IEnumerable <Common.Entity.Client> > > Get()
 {
     Common.Entity.Result <IEnumerable <Common.Entity.Client> > result = new Common.Entity.Result <IEnumerable <Common.Entity.Client> > {
     };
     try
     {
         result = await ClientService.Get();
     }
     catch (Exception ex)
     {
         result.StatusCode = System.Net.HttpStatusCode.InternalServerError;
         Log.Exception(ex, $"{GetType().FullName}.Convert");
     }
     return(await Task.FromResult(result));
 }
 public async Task <Common.Entity.Result <bool> > Insert(IEnumerable <Common.Entity.InvoiceDetail> invoices)
 {
     Common.Entity.Result <bool> result = new Common.Entity.Result <bool> {
     };
     try
     {
         result = await InvoiceDetailService.Insert(invoices);
     }
     catch (Exception ex)
     {
         result.StatusCode = System.Net.HttpStatusCode.InternalServerError;
         Log.Exception(ex, $"{GetType().FullName}.Convert");
     }
     return(await Task.FromResult(result));
 }
Example #8
0
 public async Task <Common.Entity.Result <int> > Insert(Common.Entity.Invoice invoice)
 {
     Common.Entity.Result <int> result = new Common.Entity.Result <int> {
     };
     try
     {
         result = await InvoiceService.Insert(invoice);
     }
     catch (Exception ex)
     {
         result.StatusCode = System.Net.HttpStatusCode.InternalServerError;
         Log.Exception(ex, $"{GetType().FullName}.Insert");
     }
     return(await Task.FromResult(result));
 }
Example #9
0
        public async Task <Common.Entity.Result <HttpResponseMessage> > PostAsync(Common.Entity.WebServiceRequest webServiceRequest)
        {
            Common.Entity.Result <HttpResponseMessage> result = new Common.Entity.Result <HttpResponseMessage> {
            };

            string json = await Task.Run(() => JsonConvert.SerializeObject(webServiceRequest.Request));

            try
            {
                using (HttpClient client = new HttpClient(new HttpClientHandler
                {
                    UseDefaultCredentials = false
                }))
                {
                    ////base address
                    var httpContent = new StringContent(json, Encoding.UTF8, webServiceRequest.MediaType);

                    client.BaseAddress = new Uri(webServiceRequest.Uri);

                    // Update port # in the following line.
                    client.DefaultRequestHeaders.Accept.Clear();
                    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(webServiceRequest.MediaType));

                    HttpResponseMessage response = new HttpResponseMessage();
                    ////execute get request
                    response = await client.PostAsync(webServiceRequest.Uri, httpContent);

                    response.EnsureSuccessStatusCode();
                    result.Data = response;
                };
            }
            catch (Exception ex)
            {
                result.StatusCode = HttpStatusCode.InternalServerError;
                result.Message    = ex.Message;
            }
            return(result);
        }
Example #10
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));
 }
Example #11
0
 public Task <Common.Entity.Result <IEnumerable <Common.Entity.InvoiceDetail> > > Get()
 {
     Common.Entity.Result <IEnumerable <Common.Entity.InvoiceDetail> > result = new Common.Entity.Result <IEnumerable <Common.Entity.InvoiceDetail> > {
     };
     return(Task.FromResult(result));
 }