Пример #1
0
        public static void PopulateChildrenWithId(ref AnnualProdReport theReports)
        {
            var id = theReports.result.resource_id;

            theReports.result.fields.ForEach(f => f.ResultId  = id);
            theReports.result.records.ForEach(r => r.ResultId = id);
            theReports.result._links.ResultId = id;
        }
Пример #2
0
        public static void InsertValuesToDB(AnnualProdReport theReports)
        {
            using (var connection = new SqlConnection(@"Data Source=Will-PC;Trusted_Connection = True;User Id=Will-PC\beswe_000;"))
            {
                var query = "DELETE FROM [dot_net_angular_demo].dbo.Fields; DELETE FROM [dot_net_angular_demo].dbo.Records; " +
                            "DELETE FROM [dot_net_angular_demo].dbo._Links; DELETE FROM [dot_net_angular_demo].dbo.Results; ";
                connection.Execute(query);

                query = "INSERT INTO [dot_net_angular_demo].dbo.Results VALUES (@resource_id, @limit, @total)";
                connection.Execute(query, theReports.result);

                query = "INSERT INTO [dot_net_angular_demo].dbo.Fields VALUES (@ResultId, @type, @id)";
                connection.Execute(query, theReports.result.fields);

                query = "INSERT INTO [dot_net_angular_demo].dbo.Records VALUES (@ResultId, @_id, @_5Bills, @_50Bills, @_1Bills, @_10Bills, @_100Bills, @_2Bills, @_20Bills, @FiscalYear)";
                connection.Execute(query, theReports.result.records);

                query = "INSERT INTO [dot_net_angular_demo].dbo._Links VALUES (@ResultId, @start, @next)";
                connection.Execute(query, theReports.result._links);
            }
        }
Пример #3
0
        public static AnnualProdReport GetAnnualProdReportFromAPI(string baseUri, string requestUri)
        {
            var theReport = new AnnualProdReport();

            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri(baseUri);
                //HTTP GET
                var responseTask = client.GetAsync(requestUri);
                responseTask.Wait();

                var result = responseTask.Result;
                if (result.IsSuccessStatusCode)
                {
                    var readTask = result.Content.ReadAsAsync <AnnualProdReport>();
                    readTask.Wait();

                    theReport = readTask.Result;
                    AnnualProdReport.PopulateChildrenWithId(ref theReport);
                }
            }
            return(theReport);
        }