Upgraded BelgradeProductCatalog to .csproj

This commit is contained in:
Jovan Popovic
2018-09-30 17:48:35 +02:00
parent ef33b71298
commit 649efa4ead
8 changed files with 108 additions and 132 deletions
@@ -22,7 +22,7 @@ namespace ProductCatalog.Controllers
[HttpGet]
public async Task Get()
{
await sqlQuery.Stream("select CompanyID as [value], Name as [text] from Company FOR JSON PATH", Response.Body);
await sqlQuery.Sql("select CompanyID as [value], Name as [text] from Company FOR JSON PATH").Stream(Response.Body);
}
[HttpGet("login")]
@@ -37,11 +37,11 @@ namespace ProductCatalog.Controllers
this.Response.StatusCode = 500;
throw ex;
})
.Stream(@"
.Sql(@"
select ProductID, Name, Color, Price, Quantity,
JSON_VALUE(Data, '$.MadeIn') as MadeIn, JSON_QUERY(Tags) as Tags
from Product
FOR JSON PATH, ROOT('data')", Response.Body, EMPTY_PRODUCTS_ARRAY);
FOR JSON PATH, ROOT('data')").Stream(Response.Body);
}
// GET api/Product/compressed
@@ -50,29 +50,28 @@ namespace ProductCatalog.Controllers
{
Response.Headers.Add("Content-Type", "application/json;charset=utf-16");
Response.Headers.Add("Content-Encoding", "gzip");
await sqlQuery.Stream(@"
await sqlQuery.Sql(@"
select COMPRESS(
(select ProductID, Name, Color, Price, Quantity,
JSON_VALUE(Data, '$.MadeIn') as MadeIn, JSON_QUERY(Tags) as Tags
from Product
FOR JSON PATH, ROOT('data') )
)", Response.Body, EMPTY_PRODUCTS_ARRAY_GZIPPED);
)").Stream(Response.Body, EMPTY_PRODUCTS_ARRAY_GZIPPED);
}
// GET api/Product/5
[HttpGet("{id}")]
public async Task Get(int id)
{
var cmd = new SqlCommand(
await sqlQuery.Sql(
@"select ProductID, Product.Name, Color, Price, Quantity,
Company.Name as Company, Company.Address, Company.Email, Company.Phone
from Product
join Company on Product.CompanyID = Company.CompanyID
where ProductID = @id
FOR JSON PATH, WITHOUT_ARRAY_WRAPPER");
cmd.Parameters.AddWithValue("id", id);
await sqlQuery.Stream(cmd, Response.Body, "{}");
FOR JSON PATH, WITHOUT_ARRAY_WRAPPER")
.Param("id", id)
.Stream(Response.Body, "{}");
}
// POST api/Product
@@ -80,9 +79,10 @@ FOR JSON PATH, WITHOUT_ARRAY_WRAPPER");
public async Task Post()
{
string product = new StreamReader(Request.Body).ReadToEnd();
var cmd = new SqlCommand("EXEC InsertProductFromJson @ProductJson");
cmd.Parameters.AddWithValue("ProductJson", product);
await sqlCmd.ExecuteNonQuery(cmd);
await sqlCmd
.Sql("EXEC InsertProductFromJson @ProductJson")
.Param("ProductJson", product)
.Exec();
}
// PUT api/Product/5
@@ -90,19 +90,20 @@ FOR JSON PATH, WITHOUT_ARRAY_WRAPPER");
public async Task Put(int id)
{
string product = new StreamReader(Request.Body).ReadToEnd();
var cmd = new SqlCommand("EXEC UpdateProductFromJson @ProductID, @ProductJson");
cmd.Parameters.AddWithValue("ProductID", id);
cmd.Parameters.AddWithValue("ProductJson", product);
await sqlCmd.ExecuteNonQuery(cmd);
await sqlCmd
.Sql("EXEC UpdateProductFromJson @ProductID, @ProductJson")
.Param("ProductID", id)
.Param("ProductJson", product)
.Exec();
}
// DELETE api/Product/5
[HttpDelete("{id}")]
public async Task Delete(int id)
{
var cmd = new SqlCommand(@"delete Product where ProductID = @id");
cmd.Parameters.AddWithValue("id", id);
await sqlCmd.ExecuteNonQuery(cmd);
await sqlCmd.Sql(@"delete Product where ProductID = @id")
.Param("id", id)
.Exec();
}
[HttpGet("temporal")]
@@ -110,23 +111,23 @@ FOR JSON PATH, WITHOUT_ARRAY_WRAPPER");
public async Task Get(DateTime? date)
{
if (date == null)
await this.sqlQuery.Stream("EXEC GetProducts", this.Response.Body, EMPTY_PRODUCTS_ARRAY);
await this.sqlQuery
.Sql("EXEC GetProducts")
.Stream(this.Response.Body, EMPTY_PRODUCTS_ARRAY);
else
{
var cmd = new SqlCommand("EXEC GetProductsAsOf @date");
cmd.Parameters.AddWithValue("@date", date);
await this.sqlQuery.Stream(cmd, this.Response.Body, EMPTY_PRODUCTS_ARRAY);
}
await this.sqlQuery.Sql("EXEC GetProductsAsOf @date")
.Param("date", date)
.Stream(this.Response.Body, EMPTY_PRODUCTS_ARRAY);
}
[HttpGet("restore")]
[Produces("application/json")]
public void RestoreVersion(int ProductId, DateTime DateModified)
{
var cmd = new SqlCommand("EXEC RestoreProduct @productid, @date");
cmd.Parameters.AddWithValue("@productid", ProductId);
cmd.Parameters.AddWithValue("@date", DateModified);
this.sqlCmd
.Sql("EXEC RestoreProduct @productid, @date")
.Param("productid", ProductId)
.Param("date", DateModified)
.OnError(
ex =>
{
@@ -134,7 +135,7 @@ FOR JSON PATH, WITHOUT_ARRAY_WRAPPER");
this.Response.StatusCode = 500;
throw ex;
})
.ExecuteNonQuery(cmd);
.Exec();
}
@@ -143,12 +144,13 @@ FOR JSON PATH, WITHOUT_ARRAY_WRAPPER");
public async Task Report1()
{
await sqlQuery
.Stream(@"
.Sql(@"
select color as x, sum(quantity) as y
from product
where color is not null
group by color
for json path", Response.Body, EMPTY_PRODUCTS_ARRAY);
for json path")
.Stream(Response.Body, EMPTY_PRODUCTS_ARRAY);
}
@@ -157,7 +159,7 @@ for json path", Response.Body, EMPTY_PRODUCTS_ARRAY);
public async Task Report2()
{
await sqlQuery
.Stream(@"
.Sql(@"
select name as [key], [values].x, [values].y
from company
join (select companyid, color as x, sum(quantity) as y
@@ -166,7 +168,8 @@ select name as [key], [values].x, [values].y
group by companyid, color
) as [values] on company.companyid = [values].companyid
order by company.companyid
for json auto", Response.Body, EMPTY_PRODUCTS_ARRAY);
for json auto")
.Stream(Response.Body, EMPTY_PRODUCTS_ARRAY);
}
}
}
@@ -1,19 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" />
<PropertyGroup Label="Globals">
<ProjectGuid>7e230e5a-b0b6-4f56-9561-942fd1817b80</ProjectGuid>
<RootNamespace>ProductCatalog</RootNamespace>
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">.\obj</BaseIntermediateOutputPath>
<OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath>
<TargetFrameworkVersion>v4.6</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup>
<SchemaVersion>2.0</SchemaVersion>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DotNet.Web\Microsoft.DotNet.Web.targets" Condition="'$(VSToolsPath)' != ''" />
</Project>
@@ -9,10 +9,9 @@ using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using ProductCatalog.Models;
using Serilog;
#if NET46
using Serilog;
using Serilog.Sinks;
using Serilog.Sinks.MSSqlServer;
#endif
using System;
using System.Data.SqlClient;
using System.Linq;
@@ -29,7 +28,7 @@ namespace ProductCatalog
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
.AddEnvironmentVariables();
Configuration = builder.Build();
#if NETCOREAPP1_0
#if NETCOREAPP2_0
Log.Logger = new LoggerConfiguration()
.WriteTo.RollingFile(new Serilog.Formatting.Json.JsonFormatter(), System.IO.Path.Combine(env.ContentRootPath, "logs\\log-{Date}.ndjson"))
.CreateLogger();
@@ -37,14 +36,16 @@ namespace ProductCatalog
#if NET46
var columnOptions = new ColumnOptions();
// Don't include the Properties XML column.
columnOptions.Store.Remove(StandardColumn.Id);
columnOptions.Store.Remove(StandardColumn.Properties);
columnOptions.Store.Remove(StandardColumn.MessageTemplate);
columnOptions.Store.Remove(StandardColumn.Exception);
columnOptions.TimeStamp.ColumnName = "EventTime";
// Do include the log event data as JSON.
columnOptions.Store.Add(StandardColumn.LogEvent);
Log.Logger = new LoggerConfiguration()
.WriteTo.MSSqlServer(Configuration["ConnectionStrings:BelgradeDemo"], "dbo.Logs", columnOptions: columnOptions)
.WriteTo.MSSqlServer(Configuration["ConnectionStrings:BelgradeDemo"], "Logs", columnOptions: columnOptions, autoCreateSqlTable: false)
.CreateLogger();
#endif
}
@@ -8,6 +8,6 @@
}
},
"ConnectionStrings": {
"BelgradeDemo": "Server=.\\SQLEXPRESS;Database=ProductCatalog;Integrated Security=true"
"BelgradeDemo": "Server=.\\SQLEXPRESS;Database=ProductCatalog;Integrated Security=true;Application Name=Belgrade"
}
}
@@ -0,0 +1,57 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<PreserveCompilationContext>true</PreserveCompilationContext>
<AssemblyName>belgrade-product-catalog-demo</AssemblyName>
<OutputType>Exe</OutputType>
<PackageId>belgrade-product-catalog-demo</PackageId>
<TargetFrameworkIdentifier>.NETFramework</TargetFrameworkIdentifier>
<TargetFrameworkVersion>v4.6</TargetFrameworkVersion>
<TargetFrameworkProfile />
</PropertyGroup>
<ItemGroup>
<None Update="wwwroot\**\*;Views\**\*">
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</None>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Belgrade.Sql.Client" Version="1.1.4" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.0.3" />
<PackageReference Include="Microsoft.AspNetCore.Server.IISIntegration" Version="1.0.2" />
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="1.0.3" />
<PackageReference Include="Microsoft.AspNetCore.Session" Version="1.0.2" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="1.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="1.0.3" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="1.0.2" />
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="1.0.2" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="1.0.2" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="1.0.2" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="1.0.2" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.0.2" />
<PackageReference Include="Serilog" Version="2.5.0" />
<PackageReference Include="Serilog.Extensions.Logging" Version="1.3.1" />
<PackageReference Include="Serilog.Sinks.PeriodicBatching" Version="2.1.1" />
<PackageReference Include="Serilog.Sinks.RollingFile" Version="3.3.0" />
<PackageReference Include="System.Data.SqlClient" Version="4.4.3" />
<PackageReference Include="Serilog.Sinks.MSSqlServer" Version="5.1.3-dev-00224" />
</ItemGroup>
<ItemGroup>
<None Update="sql-scripts\bcp.sql.sql">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>bcp.sql.tt</DependentUpon>
</None>
<None Update="sql-scripts\bcp.sql.tt">
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>bcp.sql.sql</LastGenOutput>
</None>
</ItemGroup>
<ItemGroup>
<Service Include="{508349b6-6b84-4df5-91f0-309beebad82d}" />
</ItemGroup>
</Project>
@@ -1,63 +0,0 @@
{
"dependencies": {
"Belgrade.Sql.Client": "0.7",
"Microsoft.AspNetCore.Mvc": "1.0.0",
"Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
"Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
"Microsoft.AspNetCore.Session": "1.0.0",
"Microsoft.AspNetCore.StaticFiles": "1.0.0",
"Microsoft.EntityFrameworkCore.SqlServer": "1.0.1",
"Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0",
"Microsoft.Extensions.Configuration.FileExtensions": "1.0.0",
"Microsoft.Extensions.Configuration.Json": "1.0.0",
"Microsoft.Extensions.Logging": "1.0.0",
"Microsoft.Extensions.Logging.Console": "1.0.0",
"Microsoft.Extensions.Logging.Debug": "1.0.0",
"Serilog": "2.3.0",
"Serilog.Extensions.Logging": "1.3.1",
"Serilog.Sinks.PeriodicBatching": "2.1.0",
"Serilog.Sinks.RollingFile": "3.3.0",
"System.Data.SqlClient": "4.1.0"
},
"tools": {
"Microsoft.AspNetCore.Server.IISIntegration.Tools": {
"version": "1.0.0-preview2-final",
"imports": "portable-net45+win8+dnxcore50"
}
},
"frameworks": {
"netcoreapp1.0": {
"dependencies": {
"Microsoft.NETCore.App": {
"version": "1.0.0",
"type": "platform"
}
}
},
"net46": {
"dependencies": {
"Serilog.Sinks.MSSqlServer": "4.2.0"
}
}
},
"buildOptions": {
"emitEntryPoint": true,
"preserveCompilationContext": true
},
"publishOptions": {
"include": [
"wwwroot",
"Views",
"appsettings.json",
"web.config"
]
},
"scripts": {
"postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
}
}
@@ -115,13 +115,10 @@ END
GO
DROP TABLE IF EXISTS Logs;
GO
CREATE TABLE Logs (
Id int IDENTITY PRIMARY KEY,
Message nvarchar(max) NULL,
MessageTemplate nvarchar(max) NULL,
Level nvarchar(128) NULL,
TimeStamp datetimeoffset(7) NOT NULL,
Exception nvarchar(max) NULL,
Properties xml NULL,
LogEvent nvarchar(max) NULL
);
CREATE TABLE Logs(
[Message] NVARCHAR(4000) NOT NULL,
[Level] VARCHAR(16) NOT NULL,
[EventTime] DATETIME2 (7) NOT NULL,
[LogEvent] NVARCHAR(max) NULL
)