From c8f380bb15d96e89829e36c21df2040d1420bf07 Mon Sep 17 00:00:00 2001 From: MacBook Pro Developer <4freelancerdevelopers@gmail.com> Date: Wed, 23 Dec 2020 15:29:07 -0700 Subject: [PATCH 1/5] add net5 api --- .../Controllers/WeatherForecastController.cs | 39 ++++++++++++ Facware.Base.Api/Facware.Base.Api.csproj | 13 ++++ Facware.Base.Api/Facware.Base.Api.sln | 17 ++++++ Facware.Base.Api/Program.cs | 26 ++++++++ .../Properties/launchSettings.json | 31 ++++++++++ Facware.Base.Api/Startup.cs | 59 +++++++++++++++++++ Facware.Base.Api/WeatherForecast.cs | 15 +++++ Facware.Base.Api/appsettings.Development.json | 9 +++ Facware.Base.Api/appsettings.json | 10 ++++ 9 files changed, 219 insertions(+) create mode 100644 Facware.Base.Api/Controllers/WeatherForecastController.cs create mode 100644 Facware.Base.Api/Facware.Base.Api.csproj create mode 100644 Facware.Base.Api/Facware.Base.Api.sln create mode 100644 Facware.Base.Api/Program.cs create mode 100644 Facware.Base.Api/Properties/launchSettings.json create mode 100644 Facware.Base.Api/Startup.cs create mode 100644 Facware.Base.Api/WeatherForecast.cs create mode 100644 Facware.Base.Api/appsettings.Development.json create mode 100644 Facware.Base.Api/appsettings.json diff --git a/Facware.Base.Api/Controllers/WeatherForecastController.cs b/Facware.Base.Api/Controllers/WeatherForecastController.cs new file mode 100644 index 0000000..746c338 --- /dev/null +++ b/Facware.Base.Api/Controllers/WeatherForecastController.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Logging; + +namespace Facware.Base.Api.Controllers +{ + [ApiController] + [Route("[controller]")] + public class WeatherForecastController : ControllerBase + { + private static readonly string[] Summaries = new[] + { + "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" + }; + + private readonly ILogger _logger; + + public WeatherForecastController(ILogger logger) + { + _logger = logger; + } + + [HttpGet] + public IEnumerable Get() + { + var rng = new Random(); + return Enumerable.Range(1, 5).Select(index => new WeatherForecast + { + Date = DateTime.Now.AddDays(index), + TemperatureC = rng.Next(-20, 55), + Summary = Summaries[rng.Next(Summaries.Length)] + }) + .ToArray(); + } + } +} diff --git a/Facware.Base.Api/Facware.Base.Api.csproj b/Facware.Base.Api/Facware.Base.Api.csproj new file mode 100644 index 0000000..218b809 --- /dev/null +++ b/Facware.Base.Api/Facware.Base.Api.csproj @@ -0,0 +1,13 @@ + + + + net5.0 + + + + + + + + + diff --git a/Facware.Base.Api/Facware.Base.Api.sln b/Facware.Base.Api/Facware.Base.Api.sln new file mode 100644 index 0000000..63ef543 --- /dev/null +++ b/Facware.Base.Api/Facware.Base.Api.sln @@ -0,0 +1,17 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Facware.Base.Api", "Facware.Base.Api.csproj", "{A3AE6E45-6B4F-477A-85B0-93EFD1A1BF9B}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {A3AE6E45-6B4F-477A-85B0-93EFD1A1BF9B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A3AE6E45-6B4F-477A-85B0-93EFD1A1BF9B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A3AE6E45-6B4F-477A-85B0-93EFD1A1BF9B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A3AE6E45-6B4F-477A-85B0-93EFD1A1BF9B}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal diff --git a/Facware.Base.Api/Program.cs b/Facware.Base.Api/Program.cs new file mode 100644 index 0000000..358000d --- /dev/null +++ b/Facware.Base.Api/Program.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; + +namespace Facware.Base.Api +{ + public class Program + { + public static void Main(string[] args) + { + CreateHostBuilder(args).Build().Run(); + } + + public static IHostBuilder CreateHostBuilder(string[] args) => + Host.CreateDefaultBuilder(args) + .ConfigureWebHostDefaults(webBuilder => + { + webBuilder.UseStartup(); + }); + } +} diff --git a/Facware.Base.Api/Properties/launchSettings.json b/Facware.Base.Api/Properties/launchSettings.json new file mode 100644 index 0000000..293108d --- /dev/null +++ b/Facware.Base.Api/Properties/launchSettings.json @@ -0,0 +1,31 @@ +{ + "$schema": "http://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:1888", + "sslPort": 44395 + } + }, + "profiles": { + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "Facware.Base.Api": { + "commandName": "Project", + "dotnetRunMessages": "true", + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "https://localhost:5001;http://localhost:5000", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/Facware.Base.Api/Startup.cs b/Facware.Base.Api/Startup.cs new file mode 100644 index 0000000..9b28dbf --- /dev/null +++ b/Facware.Base.Api/Startup.cs @@ -0,0 +1,59 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.HttpsPolicy; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; +using Microsoft.OpenApi.Models; + +namespace Facware.Base.Api +{ + public class Startup + { + public Startup(IConfiguration configuration) + { + Configuration = configuration; + } + + public IConfiguration Configuration { get; } + + // This method gets called by the runtime. Use this method to add services to the container. + public void ConfigureServices(IServiceCollection services) + { + + services.AddControllers(); + services.AddSwaggerGen(c => + { + c.SwaggerDoc("v1", new OpenApiInfo { Title = "Facware.Base.Api", Version = "v1" }); + }); + } + + // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. + public void Configure(IApplicationBuilder app, IWebHostEnvironment env) + { + if (env.IsDevelopment()) + { + app.UseDeveloperExceptionPage(); + app.UseSwagger(); + app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "Facware.Base.Api v1")); + } + + app.UseHttpsRedirection(); + + app.UseRouting(); + + app.UseAuthorization(); + + app.UseEndpoints(endpoints => + { + endpoints.MapControllers(); + }); + } + } +} diff --git a/Facware.Base.Api/WeatherForecast.cs b/Facware.Base.Api/WeatherForecast.cs new file mode 100644 index 0000000..fc07f99 --- /dev/null +++ b/Facware.Base.Api/WeatherForecast.cs @@ -0,0 +1,15 @@ +using System; + +namespace Facware.Base.Api +{ + public class WeatherForecast + { + public DateTime Date { get; set; } + + public int TemperatureC { get; set; } + + public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); + + public string Summary { get; set; } + } +} diff --git a/Facware.Base.Api/appsettings.Development.json b/Facware.Base.Api/appsettings.Development.json new file mode 100644 index 0000000..dba68eb --- /dev/null +++ b/Facware.Base.Api/appsettings.Development.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } + } +} diff --git a/Facware.Base.Api/appsettings.json b/Facware.Base.Api/appsettings.json new file mode 100644 index 0000000..81ff877 --- /dev/null +++ b/Facware.Base.Api/appsettings.json @@ -0,0 +1,10 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } + }, + "AllowedHosts": "*" +} From fe82a0ca4c1ee21631c0aa10a0fff301ade2e5ca Mon Sep 17 00:00:00 2001 From: MacBook Pro Developer <4freelancerdevelopers@gmail.com> Date: Wed, 23 Dec 2020 15:40:53 -0700 Subject: [PATCH 2/5] add two projects add xunit test project for integration testing and models library --- .vscode/settings.json | 2 ++ .../Facware.Base.Api.Test.csproj | 22 +++++++++++++++++++ Facware.Base.Api.Test/UnitTest1.cs | 14 ++++++++++++ Facware.Base.Models/Class1.cs | 8 +++++++ .../Facware.Base.Models.csproj | 7 ++++++ 5 files changed, 53 insertions(+) create mode 100644 .vscode/settings.json create mode 100644 Facware.Base.Api.Test/Facware.Base.Api.Test.csproj create mode 100644 Facware.Base.Api.Test/UnitTest1.cs create mode 100644 Facware.Base.Models/Class1.cs create mode 100644 Facware.Base.Models/Facware.Base.Models.csproj diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..7a73a41 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,2 @@ +{ +} \ No newline at end of file diff --git a/Facware.Base.Api.Test/Facware.Base.Api.Test.csproj b/Facware.Base.Api.Test/Facware.Base.Api.Test.csproj new file mode 100644 index 0000000..89e935f --- /dev/null +++ b/Facware.Base.Api.Test/Facware.Base.Api.Test.csproj @@ -0,0 +1,22 @@ + + + + net5.0 + + false + + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + diff --git a/Facware.Base.Api.Test/UnitTest1.cs b/Facware.Base.Api.Test/UnitTest1.cs new file mode 100644 index 0000000..99e3d47 --- /dev/null +++ b/Facware.Base.Api.Test/UnitTest1.cs @@ -0,0 +1,14 @@ +using System; +using Xunit; + +namespace Facware.Base.Api.Test +{ + public class UnitTest1 + { + [Fact] + public void Test1() + { + + } + } +} diff --git a/Facware.Base.Models/Class1.cs b/Facware.Base.Models/Class1.cs new file mode 100644 index 0000000..e57a60c --- /dev/null +++ b/Facware.Base.Models/Class1.cs @@ -0,0 +1,8 @@ +using System; + +namespace Facware.Base.Models +{ + public class Class1 + { + } +} diff --git a/Facware.Base.Models/Facware.Base.Models.csproj b/Facware.Base.Models/Facware.Base.Models.csproj new file mode 100644 index 0000000..563e6f9 --- /dev/null +++ b/Facware.Base.Models/Facware.Base.Models.csproj @@ -0,0 +1,7 @@ + + + + net5.0 + + + From 850c9088f81813defd15154c38e9c0e7a19c57b4 Mon Sep 17 00:00:00 2001 From: MacBook Pro Developer <4freelancerdevelopers@gmail.com> Date: Wed, 23 Dec 2020 20:33:48 -0700 Subject: [PATCH 3/5] add models test repos helpers --- .vscode/launch.json | 36 +++++++++++++++ .vscode/tasks.json | 42 +++++++++++++++++ .../Extensions/Database/DatabaseExtension.cs | 24 ++++++++++ Facware.Base.Api/Facware.Base.Api.csproj | 10 ++++ Facware.Base.Api/Helpers/AppSettings.cs | 41 +++++++++++++++++ Facware.Base.Api/Startup.cs | 29 +++++++++++- Facware.Base.Api/appsettings.Development.json | 20 ++++++-- .../Facware.Base.Database.Access.csproj | 23 ++++++++++ .../FacwareBaseContext.cs | 46 +++++++++++++++++++ Facware.Base.Models/Definitions/Item.cs | 14 ++++++ .../Class1.cs | 2 +- .../Facware.Base.Repositories.csproj | 7 +++ FacwareBase.API/appsettings.Development.json | 2 +- FacwareBase.API/appsettings.Local.json | 2 +- FacwareBase.API/appsettings.Production.json | 2 +- FacwareBase.API/appsettings.Staging.json | 2 +- FacwareBase.API/appsettings.json | 2 +- FacwareBaseBackend.sln | 42 +++++++++++++++++ 18 files changed, 335 insertions(+), 11 deletions(-) create mode 100644 .vscode/launch.json create mode 100644 .vscode/tasks.json create mode 100644 Facware.Base.Api/Extensions/Database/DatabaseExtension.cs create mode 100644 Facware.Base.Api/Helpers/AppSettings.cs create mode 100644 Facware.Base.Database.Access/Facware.Base.Database.Access.csproj create mode 100644 Facware.Base.Database.Access/FacwareBaseContext.cs create mode 100644 Facware.Base.Models/Definitions/Item.cs rename {Facware.Base.Models => Facware.Base.Repositories}/Class1.cs (56%) create mode 100644 Facware.Base.Repositories/Facware.Base.Repositories.csproj diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..1f2e959 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,36 @@ +{ + // Use IntelliSense to find out which attributes exist for C# debugging + // Use hover for the description of the existing attributes + // For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md + "version": "0.2.0", + "configurations": [ + { + "name": ".NET Core Launch (web)", + "type": "coreclr", + "request": "launch", + "preLaunchTask": "build", + // If you have changed target frameworks, make sure to update the program path. + "program": "${workspaceFolder}/FacwareBase.API/bin/Debug/netcoreapp3.1/FacwareBase.API.dll", + "args": [], + "cwd": "${workspaceFolder}/FacwareBase.API", + "stopAtEntry": false, + // Enable launching a web browser when ASP.NET Core starts. For more information: https://aka.ms/VSCode-CS-LaunchJson-WebBrowser + "serverReadyAction": { + "action": "openExternally", + "pattern": "\\bNow listening on:\\s+(https?://\\S+)" + }, + "env": { + "ASPNETCORE_ENVIRONMENT": "Development" + }, + "sourceFileMap": { + "/Views": "${workspaceFolder}/Views" + } + }, + { + "name": ".NET Core Attach", + "type": "coreclr", + "request": "attach", + "processId": "${command:pickProcess}" + } + ] +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..550ded2 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,42 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "build", + "command": "dotnet", + "type": "process", + "args": [ + "build", + "${workspaceFolder}/FacwareBase.API/FacwareBase.API.csproj", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary" + ], + "problemMatcher": "$msCompile" + }, + { + "label": "publish", + "command": "dotnet", + "type": "process", + "args": [ + "publish", + "${workspaceFolder}/FacwareBase.API/FacwareBase.API.csproj", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary" + ], + "problemMatcher": "$msCompile" + }, + { + "label": "watch", + "command": "dotnet", + "type": "process", + "args": [ + "watch", + "run", + "${workspaceFolder}/FacwareBase.API/FacwareBase.API.csproj", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary" + ], + "problemMatcher": "$msCompile" + } + ] +} \ No newline at end of file diff --git a/Facware.Base.Api/Extensions/Database/DatabaseExtension.cs b/Facware.Base.Api/Extensions/Database/DatabaseExtension.cs new file mode 100644 index 0000000..0bf94f7 --- /dev/null +++ b/Facware.Base.Api/Extensions/Database/DatabaseExtension.cs @@ -0,0 +1,24 @@ +using System; +using Facware.Base.Database; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.DependencyInjection; + +namespace Facware.Base.Api.Extensions.Database +{ + public static class DatabaseExtension + { + /// + /// Set up the Service PostgreSQL DB Context + /// + /// The + /// The data migration connection string + public static void UsePostgreSqlServer(this IServiceCollection serviceCollection, string applicationConfigurationConnectionString) + { + // https://www.npgsql.org/efcore/api/Microsoft.Extensions.DependencyInjection.NpgsqlServiceCollectionExtensions.html#Microsoft_Extensions_DependencyInjection_NpgsqlServiceCollectionExtensions_AddEntityFrameworkNpgsql_IServiceCollection_ + // https://www.npgsql.org/efcore/index.html#additional-configuration-for-aspnet-core-applications + + // TODO: use your context + serviceCollection.AddDbContext(options => options.UseNpgsql(applicationConfigurationConnectionString)); + } + } +} diff --git a/Facware.Base.Api/Facware.Base.Api.csproj b/Facware.Base.Api/Facware.Base.Api.csproj index 218b809..1283a09 100644 --- a/Facware.Base.Api/Facware.Base.Api.csproj +++ b/Facware.Base.Api/Facware.Base.Api.csproj @@ -10,4 +10,14 @@ + + + + + + + + + + diff --git a/Facware.Base.Api/Helpers/AppSettings.cs b/Facware.Base.Api/Helpers/AppSettings.cs new file mode 100644 index 0000000..a28ce15 --- /dev/null +++ b/Facware.Base.Api/Helpers/AppSettings.cs @@ -0,0 +1,41 @@ +namespace Facware.Base.Api.Helpers +{ + public class AppSettings + { + public Logging Logging { get; set; } + public ConnectionStrings ConnectionStrings { get; set; } + public SwaggerConfiguration SwaggerConfiguration { get; set; } + } + + public class LogLevel + { + public string Default { get; set; } + public string Microsoft { get; set; } + public string MicrosoftHostingLifetime { get; set; } + } + + public class Logging + { + public LogLevel LogLevel { get; set; } + } + + public class ConnectionStrings + { + public string FacwareConnectionString { get; set; } + } + + public class SwaggerConfiguration + { + public string SwaggerJSONEndpoints { get; set; } + public string Title { get; set; } + public string Version { get; set; } + public string Description { get; set; } + public string TermsOfService { get; set; } + public string ContactName { get; set; } + public string ContactEmail { get; set; } + public string LicenseName { get; set; } + public string LicenseUrl { get; set; } + } + + +} diff --git a/Facware.Base.Api/Startup.cs b/Facware.Base.Api/Startup.cs index 9b28dbf..2e53487 100644 --- a/Facware.Base.Api/Startup.cs +++ b/Facware.Base.Api/Startup.cs @@ -2,15 +2,19 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using Facware.Base.Api.Extensions.Database; +using Facware.Base.Database; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.HttpsPolicy; using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; using Microsoft.OpenApi.Models; +using Facware.Base.Api.Helpers; namespace Facware.Base.Api { @@ -18,14 +22,35 @@ public class Startup { public Startup(IConfiguration configuration) { - Configuration = configuration; + _configuration = configuration; } - public IConfiguration Configuration { get; } + public IConfiguration _configuration { get; } + + /// + /// Load configuration settings + /// + /// + private void ConfigureConfigSettings(IServiceCollection services) + { + services + .AddOptions() + .Configure(_configuration.GetSection(nameof(ConnectionStrings))); + } // This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { + #region Database context service + + var cn = _configuration.GetSection("ConnectionStrings:FacwareConnectionString"); + + // TODO: before use this, create your own dbcontext + services.UsePostgreSqlServer(cn.Value); + + // in memory db + // services.UseInMemoryDatabase(); + #endregion services.AddControllers(); services.AddSwaggerGen(c => diff --git a/Facware.Base.Api/appsettings.Development.json b/Facware.Base.Api/appsettings.Development.json index dba68eb..cedea21 100644 --- a/Facware.Base.Api/appsettings.Development.json +++ b/Facware.Base.Api/appsettings.Development.json @@ -1,9 +1,23 @@ { "Logging": { "LogLevel": { - "Default": "Information", - "Microsoft": "Warning", - "Microsoft.Hosting.Lifetime": "Information" + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" } + }, + "ConnectionStrings": { + "FacwareConnectionString": "Server=127.0.0.1;Port=5432;Database=Facware;User Id=postgres;Password=postgres;" + }, + "SwaggerConfiguration": { + "SwaggerJSONEndpoints": "swagger/v1/swagger.json", + "Title": "Facware Base", + "Version": "V1.0", + "Description": "Facware base project.", + "TermsOfService": "https://luisespinoza.facware.com/", + "ContactName": "luis.espinoza@afacware.com respinozabarboza@gmail.com", + "ContactEmail": "luis.espinoza@afacware.com respinozabarboza@gmail.com", + "LicenseName": "MIT", + "LicenseUrl": "https://opensource.org/licenses/MIT" } } diff --git a/Facware.Base.Database.Access/Facware.Base.Database.Access.csproj b/Facware.Base.Database.Access/Facware.Base.Database.Access.csproj new file mode 100644 index 0000000..c6a6598 --- /dev/null +++ b/Facware.Base.Database.Access/Facware.Base.Database.Access.csproj @@ -0,0 +1,23 @@ + + + + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + + + net5.0 + + + diff --git a/Facware.Base.Database.Access/FacwareBaseContext.cs b/Facware.Base.Database.Access/FacwareBaseContext.cs new file mode 100644 index 0000000..e268e47 --- /dev/null +++ b/Facware.Base.Database.Access/FacwareBaseContext.cs @@ -0,0 +1,46 @@ +using System; +using Facware.Base.Models.Definitions; +using Microsoft.EntityFrameworkCore; + +namespace Facware.Base.Database +{ + public class FacwareBaseContext : DbContext + { + public FacwareBaseContext() { } + /* + public FacwareBaseContext(DbContextOptions options) + : base(options) + { + _ = Database.EnsureCreated(); + }*/ + + + public DbSet Item { get; set; } + + + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + base.OnModelCreating(modelBuilder); + + modelBuilder.Entity().HasData( + new Item + { + ItemId = 1, + Name = "Electronics", + Price = 1, + Enabled = true, + CreatedDate = DateTimeOffset.Now + }, + new Item + { + ItemId = 2, + Name = "Electronics", + Price = 2, + Enabled = true, + CreatedDate = DateTimeOffset.Now + } + );; + } + + } +} \ No newline at end of file diff --git a/Facware.Base.Models/Definitions/Item.cs b/Facware.Base.Models/Definitions/Item.cs new file mode 100644 index 0000000..40af534 --- /dev/null +++ b/Facware.Base.Models/Definitions/Item.cs @@ -0,0 +1,14 @@ +using System; + +namespace Facware.Base.Models.Definitions +{ + public class Item + { + public int ItemId { get; set; } + public string Name { get; set; } + public decimal Price { get; set; } + public DateTimeOffset CreatedDate { get; set; } + public bool Enabled { get; set; } + + } +} diff --git a/Facware.Base.Models/Class1.cs b/Facware.Base.Repositories/Class1.cs similarity index 56% rename from Facware.Base.Models/Class1.cs rename to Facware.Base.Repositories/Class1.cs index e57a60c..eb0113f 100644 --- a/Facware.Base.Models/Class1.cs +++ b/Facware.Base.Repositories/Class1.cs @@ -1,6 +1,6 @@ using System; -namespace Facware.Base.Models +namespace Facware.Base.Repositories { public class Class1 { diff --git a/Facware.Base.Repositories/Facware.Base.Repositories.csproj b/Facware.Base.Repositories/Facware.Base.Repositories.csproj new file mode 100644 index 0000000..563e6f9 --- /dev/null +++ b/Facware.Base.Repositories/Facware.Base.Repositories.csproj @@ -0,0 +1,7 @@ + + + + net5.0 + + + diff --git a/FacwareBase.API/appsettings.Development.json b/FacwareBase.API/appsettings.Development.json index 1610a2a..38116b4 100644 --- a/FacwareBase.API/appsettings.Development.json +++ b/FacwareBase.API/appsettings.Development.json @@ -11,7 +11,7 @@ "Environment": "Development" }, "ConnectionStrings": { - "ApplicationConfigurationConnectionString": "Server=127.0.0.1;Port=5432;Database=eBaseline;User Id=postgres;Password=postgres;" + "ApplicationConfigurationConnectionString": "Server=127.0.0.1;Port=5432;Database=Facware;User Id=postgres;Password=postgres;" }, "Cors": { "AllowedOrigin": [ diff --git a/FacwareBase.API/appsettings.Local.json b/FacwareBase.API/appsettings.Local.json index 5261d84..bcda878 100644 --- a/FacwareBase.API/appsettings.Local.json +++ b/FacwareBase.API/appsettings.Local.json @@ -11,7 +11,7 @@ "Environment": "Local" }, "ConnectionStrings": { - "ApplicationConfigurationConnectionString": "Server=127.0.0.1;Port=5432;Database=eBaseline;User Id=postgres;Password=postgres;" + "ApplicationConfigurationConnectionString": "Server=127.0.0.1;Port=5432;Database=Facware;User Id=postgres;Password=postgres;" }, "Cors": { "AllowedOrigin": [ diff --git a/FacwareBase.API/appsettings.Production.json b/FacwareBase.API/appsettings.Production.json index ff0969b..9d4af4c 100644 --- a/FacwareBase.API/appsettings.Production.json +++ b/FacwareBase.API/appsettings.Production.json @@ -11,7 +11,7 @@ "Environment": "Production" }, "ConnectionStrings": { - "ApplicationConfigurationConnectionString": "Server=127.0.0.1;Port=5432;Database=eBaseline;User Id=postgres;Password=postgres;" + "ApplicationConfigurationConnectionString": "Server=127.0.0.1;Port=5432;Database=Facware;User Id=postgres;Password=postgres;" }, "Cors": { "AllowedOrigin": [ diff --git a/FacwareBase.API/appsettings.Staging.json b/FacwareBase.API/appsettings.Staging.json index 32d3755..b330032 100644 --- a/FacwareBase.API/appsettings.Staging.json +++ b/FacwareBase.API/appsettings.Staging.json @@ -11,7 +11,7 @@ "Environment": "Staging" }, "ConnectionStrings": { - "ApplicationConfigurationConnectionString": "Server=127.0.0.1;Port=5432;Database=eBaseline;User Id=postgres;Password=postgres;" + "ApplicationConfigurationConnectionString": "Server=127.0.0.1;Port=5432;Database=Facware;User Id=postgres;Password=postgres;" }, "Cors": { "AllowedOrigin": [ diff --git a/FacwareBase.API/appsettings.json b/FacwareBase.API/appsettings.json index 28ae1c6..72a476a 100644 --- a/FacwareBase.API/appsettings.json +++ b/FacwareBase.API/appsettings.json @@ -8,7 +8,7 @@ }, "AllowedHosts": "*", "ConnectionStrings": { - "ApplicationConfigurationConnectionString": "Server=127.0.0.1;Port=5432;Database=eBaseline;User Id=postgres;Password=postgres;" + "ApplicationConfigurationConnectionString": "Server=127.0.0.1;Port=5432;Database=Facware;User Id=postgres;Password=postgres;" }, "Cors": { "AllowedOrigin": [ diff --git a/FacwareBaseBackend.sln b/FacwareBaseBackend.sln index 5649491..ca84165 100644 --- a/FacwareBaseBackend.sln +++ b/FacwareBaseBackend.sln @@ -5,6 +5,12 @@ VisualStudioVersion = 15.0.26124.0 MinimumVisualStudioVersion = 15.0.26124.0 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FacwareBase.API", "FacwareBase.API\FacwareBase.API.csproj", "{2FF05973-CAA5-4888-8533-E5E3CCDE7235}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Facware.Base.Api", "Facware.Base.Api\Facware.Base.Api.csproj", "{B5EB89DA-C4DF-4100-922E-E82B60956F38}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Facware.Base.Models", "Facware.Base.Models\Facware.Base.Models.csproj", "{A7B9A426-ADDE-469E-A2E3-A8B1A4E5CB0D}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Facware.Base.Database.Access", "Facware.Base.Database.Access\Facware.Base.Database.Access.csproj", "{A57A66D0-5AB8-4F10-8DDC-8856BDC3A4DD}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -30,5 +36,41 @@ Global {2FF05973-CAA5-4888-8533-E5E3CCDE7235}.Release|x64.Build.0 = Release|Any CPU {2FF05973-CAA5-4888-8533-E5E3CCDE7235}.Release|x86.ActiveCfg = Release|Any CPU {2FF05973-CAA5-4888-8533-E5E3CCDE7235}.Release|x86.Build.0 = Release|Any CPU + {B5EB89DA-C4DF-4100-922E-E82B60956F38}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B5EB89DA-C4DF-4100-922E-E82B60956F38}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B5EB89DA-C4DF-4100-922E-E82B60956F38}.Debug|x64.ActiveCfg = Debug|Any CPU + {B5EB89DA-C4DF-4100-922E-E82B60956F38}.Debug|x64.Build.0 = Debug|Any CPU + {B5EB89DA-C4DF-4100-922E-E82B60956F38}.Debug|x86.ActiveCfg = Debug|Any CPU + {B5EB89DA-C4DF-4100-922E-E82B60956F38}.Debug|x86.Build.0 = Debug|Any CPU + {B5EB89DA-C4DF-4100-922E-E82B60956F38}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B5EB89DA-C4DF-4100-922E-E82B60956F38}.Release|Any CPU.Build.0 = Release|Any CPU + {B5EB89DA-C4DF-4100-922E-E82B60956F38}.Release|x64.ActiveCfg = Release|Any CPU + {B5EB89DA-C4DF-4100-922E-E82B60956F38}.Release|x64.Build.0 = Release|Any CPU + {B5EB89DA-C4DF-4100-922E-E82B60956F38}.Release|x86.ActiveCfg = Release|Any CPU + {B5EB89DA-C4DF-4100-922E-E82B60956F38}.Release|x86.Build.0 = Release|Any CPU + {A7B9A426-ADDE-469E-A2E3-A8B1A4E5CB0D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A7B9A426-ADDE-469E-A2E3-A8B1A4E5CB0D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A7B9A426-ADDE-469E-A2E3-A8B1A4E5CB0D}.Debug|x64.ActiveCfg = Debug|Any CPU + {A7B9A426-ADDE-469E-A2E3-A8B1A4E5CB0D}.Debug|x64.Build.0 = Debug|Any CPU + {A7B9A426-ADDE-469E-A2E3-A8B1A4E5CB0D}.Debug|x86.ActiveCfg = Debug|Any CPU + {A7B9A426-ADDE-469E-A2E3-A8B1A4E5CB0D}.Debug|x86.Build.0 = Debug|Any CPU + {A7B9A426-ADDE-469E-A2E3-A8B1A4E5CB0D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A7B9A426-ADDE-469E-A2E3-A8B1A4E5CB0D}.Release|Any CPU.Build.0 = Release|Any CPU + {A7B9A426-ADDE-469E-A2E3-A8B1A4E5CB0D}.Release|x64.ActiveCfg = Release|Any CPU + {A7B9A426-ADDE-469E-A2E3-A8B1A4E5CB0D}.Release|x64.Build.0 = Release|Any CPU + {A7B9A426-ADDE-469E-A2E3-A8B1A4E5CB0D}.Release|x86.ActiveCfg = Release|Any CPU + {A7B9A426-ADDE-469E-A2E3-A8B1A4E5CB0D}.Release|x86.Build.0 = Release|Any CPU + {A57A66D0-5AB8-4F10-8DDC-8856BDC3A4DD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A57A66D0-5AB8-4F10-8DDC-8856BDC3A4DD}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A57A66D0-5AB8-4F10-8DDC-8856BDC3A4DD}.Debug|x64.ActiveCfg = Debug|Any CPU + {A57A66D0-5AB8-4F10-8DDC-8856BDC3A4DD}.Debug|x64.Build.0 = Debug|Any CPU + {A57A66D0-5AB8-4F10-8DDC-8856BDC3A4DD}.Debug|x86.ActiveCfg = Debug|Any CPU + {A57A66D0-5AB8-4F10-8DDC-8856BDC3A4DD}.Debug|x86.Build.0 = Debug|Any CPU + {A57A66D0-5AB8-4F10-8DDC-8856BDC3A4DD}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A57A66D0-5AB8-4F10-8DDC-8856BDC3A4DD}.Release|Any CPU.Build.0 = Release|Any CPU + {A57A66D0-5AB8-4F10-8DDC-8856BDC3A4DD}.Release|x64.ActiveCfg = Release|Any CPU + {A57A66D0-5AB8-4F10-8DDC-8856BDC3A4DD}.Release|x64.Build.0 = Release|Any CPU + {A57A66D0-5AB8-4F10-8DDC-8856BDC3A4DD}.Release|x86.ActiveCfg = Release|Any CPU + {A57A66D0-5AB8-4F10-8DDC-8856BDC3A4DD}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection EndGlobal From ff11ca7c276d5092dd9c62af8dbff14c76833766 Mon Sep 17 00:00:00 2001 From: MacBook Pro Developer <4freelancerdevelopers@gmail.com> Date: Thu, 24 Dec 2020 16:24:53 -0700 Subject: [PATCH 4/5] add net 5 projects --- Facware.Api/Controllers/ItemsController.cs | 61 +++++++++++++++ .../Controllers/WeatherForecastController.cs | 39 ++++++++++ Facware.Api/Facware.Api.csproj | 22 ++++++ Facware.Api/Program.cs | 26 +++++++ Facware.Api/Properties/launchSettings.json | 30 ++++++++ Facware.Api/Startup.cs | 74 +++++++++++++++++++ Facware.Api/WeatherForecast.cs | 15 ++++ Facware.Api/appsettings.Development.json | 12 +++ Facware.Api/appsettings.json | 10 +++ .../Base/Base/GenericRepository.cs | 52 +++++++++++++ .../Base/Base/IGenericRepository.cs | 17 +++++ .../Facware.Data.Access.csproj | 32 ++++++++ Facware.Data.Access/FacwareDbContext.cs | 22 ++++++ .../20201224232012_init.Designer.cs | 41 ++++++++++ .../Migrations/20201224232012_init.cs | 30 ++++++++ .../FacwareDbContextModelSnapshot.cs | 39 ++++++++++ Facware.Data.Access/Readme.md | 5 ++ .../Implementation/ItemRepository.cs | 20 +++++ .../Repository/Interface/IItemRepository.cs | 11 +++ .../Seed/ModelBuilderExtension.cs | 15 ++++ Facware.Models/Facware.Models.csproj | 7 ++ Facware.Models/Item.cs | 14 ++++ FacwareBaseBackend.sln | 42 +++++++++++ 23 files changed, 636 insertions(+) create mode 100644 Facware.Api/Controllers/ItemsController.cs create mode 100644 Facware.Api/Controllers/WeatherForecastController.cs create mode 100644 Facware.Api/Facware.Api.csproj create mode 100644 Facware.Api/Program.cs create mode 100644 Facware.Api/Properties/launchSettings.json create mode 100644 Facware.Api/Startup.cs create mode 100644 Facware.Api/WeatherForecast.cs create mode 100644 Facware.Api/appsettings.Development.json create mode 100644 Facware.Api/appsettings.json create mode 100644 Facware.Data.Access/Base/Base/GenericRepository.cs create mode 100644 Facware.Data.Access/Base/Base/IGenericRepository.cs create mode 100644 Facware.Data.Access/Facware.Data.Access.csproj create mode 100644 Facware.Data.Access/FacwareDbContext.cs create mode 100644 Facware.Data.Access/Migrations/20201224232012_init.Designer.cs create mode 100644 Facware.Data.Access/Migrations/20201224232012_init.cs create mode 100644 Facware.Data.Access/Migrations/FacwareDbContextModelSnapshot.cs create mode 100644 Facware.Data.Access/Readme.md create mode 100644 Facware.Data.Access/Repository/Implementation/ItemRepository.cs create mode 100644 Facware.Data.Access/Repository/Interface/IItemRepository.cs create mode 100644 Facware.Data.Access/Seed/ModelBuilderExtension.cs create mode 100644 Facware.Models/Facware.Models.csproj create mode 100644 Facware.Models/Item.cs diff --git a/Facware.Api/Controllers/ItemsController.cs b/Facware.Api/Controllers/ItemsController.cs new file mode 100644 index 0000000..3381453 --- /dev/null +++ b/Facware.Api/Controllers/ItemsController.cs @@ -0,0 +1,61 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Facware.Data.Access; +using Facware.Data.Access.Repository.Interface; +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; + +// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860 + +namespace Facware.Api.Controllers +{ + [Route("api/[controller]")] + public class ItemsController : Controller + { + private readonly FacwareDbContext _context; + + private IItemRepository _itemRepository; + + public ItemsController(FacwareDbContext context, + IItemRepository itemRepository) + { + _context = context; + _itemRepository = itemRepository; + } + + // GET: api/values + [HttpGet] + public async Task Get() + { + var data = await _context.Items.ToListAsync(); + return Ok(data); + } + + // GET api/values/5 + [HttpGet("{id}")] + public IActionResult Get(int id) + { + return Ok(_itemRepository.GetById(id)); + } + + // POST api/values + [HttpPost] + public void Post([FromBody] string value) + { + } + + // PUT api/values/5 + [HttpPut("{id}")] + public void Put(int id, [FromBody] string value) + { + } + + // DELETE api/values/5 + [HttpDelete("{id}")] + public void Delete(int id) + { + } + } +} diff --git a/Facware.Api/Controllers/WeatherForecastController.cs b/Facware.Api/Controllers/WeatherForecastController.cs new file mode 100644 index 0000000..09ea7b5 --- /dev/null +++ b/Facware.Api/Controllers/WeatherForecastController.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Logging; + +namespace Facware.Api.Controllers +{ + [ApiController] + [Route("[controller]")] + public class WeatherForecastController : ControllerBase + { + private static readonly string[] Summaries = new[] + { + "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" + }; + + private readonly ILogger _logger; + + public WeatherForecastController(ILogger logger) + { + _logger = logger; + } + + [HttpGet] + public IEnumerable Get() + { + var rng = new Random(); + return Enumerable.Range(1, 5).Select(index => new WeatherForecast + { + Date = DateTime.Now.AddDays(index), + TemperatureC = rng.Next(-20, 55), + Summary = Summaries[rng.Next(Summaries.Length)] + }) + .ToArray(); + } + } +} diff --git a/Facware.Api/Facware.Api.csproj b/Facware.Api/Facware.Api.csproj new file mode 100644 index 0000000..03db28e --- /dev/null +++ b/Facware.Api/Facware.Api.csproj @@ -0,0 +1,22 @@ + + + + net5.0 + + + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + + + + + + diff --git a/Facware.Api/Program.cs b/Facware.Api/Program.cs new file mode 100644 index 0000000..744a60c --- /dev/null +++ b/Facware.Api/Program.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; + +namespace Facware.Api +{ + public class Program + { + public static void Main(string[] args) + { + CreateHostBuilder(args).Build().Run(); + } + + public static IHostBuilder CreateHostBuilder(string[] args) => + Host.CreateDefaultBuilder(args) + .ConfigureWebHostDefaults(webBuilder => + { + webBuilder.UseStartup(); + }); + } +} diff --git a/Facware.Api/Properties/launchSettings.json b/Facware.Api/Properties/launchSettings.json new file mode 100644 index 0000000..1433dbe --- /dev/null +++ b/Facware.Api/Properties/launchSettings.json @@ -0,0 +1,30 @@ +{ + "$schema": "http://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:65515", + "sslPort": 44376 + } + }, + "profiles": { + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "Facware.Api": { + "commandName": "Project", + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "https://localhost:60832;http://localhost:56470", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} \ No newline at end of file diff --git a/Facware.Api/Startup.cs b/Facware.Api/Startup.cs new file mode 100644 index 0000000..0ae5338 --- /dev/null +++ b/Facware.Api/Startup.cs @@ -0,0 +1,74 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Facware.Data.Access; +using Facware.Data.Access.Base.Base; +using Facware.Data.Access.Repository.Implementation; +using Facware.Data.Access.Repository.Interface; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.HttpsPolicy; +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; +using Microsoft.OpenApi.Models; + +namespace Facware.Api +{ + public class Startup + { + public Startup(IConfiguration configuration) + { + _configuration = configuration; + } + + public IConfiguration _configuration { get; } + + // This method gets called by the runtime. Use this method to add services to the container. + public void ConfigureServices(IServiceCollection services) + { + + services.AddControllers(); + services.AddSwaggerGen(c => + { + c.SwaggerDoc("v1", new OpenApiInfo { Title = "Facware.Api", Version = "v1" }); + }); + + var connectionString = _configuration["DbContextSettings:ConnectionString"]; + services.AddDbContext(options => + options.UseNpgsql( + connectionString, + x => x.MigrationsAssembly("Facware.Data.Access"))); + + services.AddTransient(typeof(IGenericRepository<>), typeof(GenericRepository<>)); + services.AddTransient(); + + } + + // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. + public void Configure(IApplicationBuilder app, IWebHostEnvironment env) + { + if (env.IsDevelopment()) + { + app.UseDeveloperExceptionPage(); + app.UseSwagger(); + app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "Facware.Api v1")); + } + + app.UseHttpsRedirection(); + + app.UseRouting(); + + app.UseAuthorization(); + + app.UseEndpoints(endpoints => + { + endpoints.MapControllers(); + }); + } + } +} diff --git a/Facware.Api/WeatherForecast.cs b/Facware.Api/WeatherForecast.cs new file mode 100644 index 0000000..c46dfc2 --- /dev/null +++ b/Facware.Api/WeatherForecast.cs @@ -0,0 +1,15 @@ +using System; + +namespace Facware.Api +{ + public class WeatherForecast + { + public DateTime Date { get; set; } + + public int TemperatureC { get; set; } + + public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); + + public string Summary { get; set; } + } +} diff --git a/Facware.Api/appsettings.Development.json b/Facware.Api/appsettings.Development.json new file mode 100644 index 0000000..87922e9 --- /dev/null +++ b/Facware.Api/appsettings.Development.json @@ -0,0 +1,12 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } + }, + "DbContextSettings": { + "ConnectionString": "Server=127.0.0.1;Port=5432;Database=facware;User Id=postgres;Password=postgres;" + } +} diff --git a/Facware.Api/appsettings.json b/Facware.Api/appsettings.json new file mode 100644 index 0000000..d9d9a9b --- /dev/null +++ b/Facware.Api/appsettings.json @@ -0,0 +1,10 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } + }, + "AllowedHosts": "*" +} diff --git a/Facware.Data.Access/Base/Base/GenericRepository.cs b/Facware.Data.Access/Base/Base/GenericRepository.cs new file mode 100644 index 0000000..d9b7768 --- /dev/null +++ b/Facware.Data.Access/Base/Base/GenericRepository.cs @@ -0,0 +1,52 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Linq.Expressions; + +namespace Facware.Data.Access.Base.Base +{ + public class GenericRepository: IGenericRepository where T: class + { + protected readonly FacwareDbContext _context; + + public GenericRepository(FacwareDbContext context) + { + _context = context; + } + + public void Add(T entity) + { + _context.Set().Add(entity); + } + + public void AddRange(IEnumerable entities) + { + _context.Set().AddRange(entities); + } + + public IEnumerable Find(Expression> expression) + { + return _context.Set().Where(expression); + } + + public IEnumerable GetAll() + { + return _context.Set().ToList(); + } + + public T GetById(int id) + { + return _context.Set().Find(id); + } + + public void Remove(T entity) + { + _context.Set().Remove(entity); + } + + public void Remove(IEnumerable entites) + { + _context.Set().RemoveRange(entites); + } + } +} diff --git a/Facware.Data.Access/Base/Base/IGenericRepository.cs b/Facware.Data.Access/Base/Base/IGenericRepository.cs new file mode 100644 index 0000000..a96af45 --- /dev/null +++ b/Facware.Data.Access/Base/Base/IGenericRepository.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq.Expressions; + +namespace Facware.Data.Access.Base.Base +{ + public interface IGenericRepository where T: class + { + T GetById(int id); + IEnumerable GetAll(); + IEnumerable Find(Expression> expression); + void Add(T entity); + void AddRange(IEnumerable entities); + void Remove(T entity); + void Remove(IEnumerable entites); + } +} diff --git a/Facware.Data.Access/Facware.Data.Access.csproj b/Facware.Data.Access/Facware.Data.Access.csproj new file mode 100644 index 0000000..f000fce --- /dev/null +++ b/Facware.Data.Access/Facware.Data.Access.csproj @@ -0,0 +1,32 @@ + + + + net5.0 + + + + + + + + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + + + + + + + diff --git a/Facware.Data.Access/FacwareDbContext.cs b/Facware.Data.Access/FacwareDbContext.cs new file mode 100644 index 0000000..3e7519e --- /dev/null +++ b/Facware.Data.Access/FacwareDbContext.cs @@ -0,0 +1,22 @@ +using Facware.Data.Access.Seed; +using Facware.Models; +using Microsoft.EntityFrameworkCore; + +namespace Facware.Data.Access +{ + public class FacwareDbContext: DbContext + { + public FacwareDbContext(DbContextOptions dbContextOptions) : + base(dbContextOptions) + { + + } + + public DbSet Items { get; set; } + + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + // modelBuilder.Seed(); + } + } +} diff --git a/Facware.Data.Access/Migrations/20201224232012_init.Designer.cs b/Facware.Data.Access/Migrations/20201224232012_init.Designer.cs new file mode 100644 index 0000000..16cb74e --- /dev/null +++ b/Facware.Data.Access/Migrations/20201224232012_init.Designer.cs @@ -0,0 +1,41 @@ +// +using Facware.Data.Access; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +namespace Facware.Data.Access.Migrations +{ + [DbContext(typeof(FacwareDbContext))] + [Migration("20201224232012_init")] + partial class init + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .UseIdentityByDefaultColumns() + .HasAnnotation("Relational:MaxIdentifierLength", 63) + .HasAnnotation("ProductVersion", "5.0.1"); + + modelBuilder.Entity("Facware.Models.Item", b => + { + b.Property("ItemId") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .UseIdentityByDefaultColumn(); + + b.Property("Name") + .HasMaxLength(50) + .HasColumnType("varchar"); + + b.HasKey("ItemId"); + + b.ToTable("Items"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Facware.Data.Access/Migrations/20201224232012_init.cs b/Facware.Data.Access/Migrations/20201224232012_init.cs new file mode 100644 index 0000000..edf0dcb --- /dev/null +++ b/Facware.Data.Access/Migrations/20201224232012_init.cs @@ -0,0 +1,30 @@ +using Microsoft.EntityFrameworkCore.Migrations; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +namespace Facware.Data.Access.Migrations +{ + public partial class init : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Items", + columns: table => new + { + ItemId = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + Name = table.Column(type: "varchar", maxLength: 50, nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Items", x => x.ItemId); + }); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Items"); + } + } +} diff --git a/Facware.Data.Access/Migrations/FacwareDbContextModelSnapshot.cs b/Facware.Data.Access/Migrations/FacwareDbContextModelSnapshot.cs new file mode 100644 index 0000000..635117e --- /dev/null +++ b/Facware.Data.Access/Migrations/FacwareDbContextModelSnapshot.cs @@ -0,0 +1,39 @@ +// +using Facware.Data.Access; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +namespace Facware.Data.Access.Migrations +{ + [DbContext(typeof(FacwareDbContext))] + partial class FacwareDbContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .UseIdentityByDefaultColumns() + .HasAnnotation("Relational:MaxIdentifierLength", 63) + .HasAnnotation("ProductVersion", "5.0.1"); + + modelBuilder.Entity("Facware.Models.Item", b => + { + b.Property("ItemId") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .UseIdentityByDefaultColumn(); + + b.Property("Name") + .HasMaxLength(50) + .HasColumnType("varchar"); + + b.HasKey("ItemId"); + + b.ToTable("Items"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Facware.Data.Access/Readme.md b/Facware.Data.Access/Readme.md new file mode 100644 index 0000000..bdeeffe --- /dev/null +++ b/Facware.Data.Access/Readme.md @@ -0,0 +1,5 @@ +dotnet add package Microsoft.EntityFrameworkCore.Tools.DotNet --version 2.0.3 + +dotnet ef migrations add init --startup-project ../Facware.Api --verbose + +dotnet ef migrations update --startup-project ../Facware.Api --verbose \ No newline at end of file diff --git a/Facware.Data.Access/Repository/Implementation/ItemRepository.cs b/Facware.Data.Access/Repository/Implementation/ItemRepository.cs new file mode 100644 index 0000000..e115654 --- /dev/null +++ b/Facware.Data.Access/Repository/Implementation/ItemRepository.cs @@ -0,0 +1,20 @@ +using System; +using System.Linq; +using Facware.Data.Access.Base.Base; +using Facware.Data.Access.Repository.Interface; +using Facware.Models; + +namespace Facware.Data.Access.Repository.Implementation +{ + public class ItemRepository : GenericRepository, IItemRepository + { + public ItemRepository(FacwareDbContext context) : base(context) + { + } + + public IEquatable GetSpecialItems(int count) + { + return (IEquatable)_context.Items.OrderByDescending(x => x.Name).Take(count).ToList(); + } + } +} diff --git a/Facware.Data.Access/Repository/Interface/IItemRepository.cs b/Facware.Data.Access/Repository/Interface/IItemRepository.cs new file mode 100644 index 0000000..405e260 --- /dev/null +++ b/Facware.Data.Access/Repository/Interface/IItemRepository.cs @@ -0,0 +1,11 @@ +using System; +using Facware.Data.Access.Base.Base; +using Facware.Models; + +namespace Facware.Data.Access.Repository.Interface +{ + public interface IItemRepository : IGenericRepository + { + IEquatable GetSpecialItems(int count); + } +} diff --git a/Facware.Data.Access/Seed/ModelBuilderExtension.cs b/Facware.Data.Access/Seed/ModelBuilderExtension.cs new file mode 100644 index 0000000..b38c0a4 --- /dev/null +++ b/Facware.Data.Access/Seed/ModelBuilderExtension.cs @@ -0,0 +1,15 @@ +using Facware.Models; +using Microsoft.EntityFrameworkCore; + +namespace Facware.Data.Access.Seed +{ + public static class ModelBuilderExtension + { + public static void Seed(this ModelBuilder modelBuilder) + { + modelBuilder.Entity().HasData( + new Item { Name = "A"} + ); + } + } +} diff --git a/Facware.Models/Facware.Models.csproj b/Facware.Models/Facware.Models.csproj new file mode 100644 index 0000000..563e6f9 --- /dev/null +++ b/Facware.Models/Facware.Models.csproj @@ -0,0 +1,7 @@ + + + + net5.0 + + + diff --git a/Facware.Models/Item.cs b/Facware.Models/Item.cs new file mode 100644 index 0000000..037e4d5 --- /dev/null +++ b/Facware.Models/Item.cs @@ -0,0 +1,14 @@ +using System; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; + +namespace Facware.Models +{ + public class Item + { + [Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)] + public int ItemId { get; set; } + [Column(TypeName = "varchar"), MaxLength(50)] + public string Name { get; set; } + } +} diff --git a/FacwareBaseBackend.sln b/FacwareBaseBackend.sln index ca84165..2606d16 100644 --- a/FacwareBaseBackend.sln +++ b/FacwareBaseBackend.sln @@ -11,6 +11,12 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Facware.Base.Models", "Facw EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Facware.Base.Database.Access", "Facware.Base.Database.Access\Facware.Base.Database.Access.csproj", "{A57A66D0-5AB8-4F10-8DDC-8856BDC3A4DD}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Facware.Api", "Facware.Api\Facware.Api.csproj", "{47EFADC2-A1E9-469F-ABEA-5650111CA298}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Facware.Data.Access", "Facware.Data.Access\Facware.Data.Access.csproj", "{35F3CCFF-FE63-4B92-96F7-AA45AE20995D}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Facware.Models", "Facware.Models\Facware.Models.csproj", "{AD281B1D-A50E-4C8C-B29C-BF33B3FD53B2}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -72,5 +78,41 @@ Global {A57A66D0-5AB8-4F10-8DDC-8856BDC3A4DD}.Release|x64.Build.0 = Release|Any CPU {A57A66D0-5AB8-4F10-8DDC-8856BDC3A4DD}.Release|x86.ActiveCfg = Release|Any CPU {A57A66D0-5AB8-4F10-8DDC-8856BDC3A4DD}.Release|x86.Build.0 = Release|Any CPU + {47EFADC2-A1E9-469F-ABEA-5650111CA298}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {47EFADC2-A1E9-469F-ABEA-5650111CA298}.Debug|Any CPU.Build.0 = Debug|Any CPU + {47EFADC2-A1E9-469F-ABEA-5650111CA298}.Debug|x64.ActiveCfg = Debug|Any CPU + {47EFADC2-A1E9-469F-ABEA-5650111CA298}.Debug|x64.Build.0 = Debug|Any CPU + {47EFADC2-A1E9-469F-ABEA-5650111CA298}.Debug|x86.ActiveCfg = Debug|Any CPU + {47EFADC2-A1E9-469F-ABEA-5650111CA298}.Debug|x86.Build.0 = Debug|Any CPU + {47EFADC2-A1E9-469F-ABEA-5650111CA298}.Release|Any CPU.ActiveCfg = Release|Any CPU + {47EFADC2-A1E9-469F-ABEA-5650111CA298}.Release|Any CPU.Build.0 = Release|Any CPU + {47EFADC2-A1E9-469F-ABEA-5650111CA298}.Release|x64.ActiveCfg = Release|Any CPU + {47EFADC2-A1E9-469F-ABEA-5650111CA298}.Release|x64.Build.0 = Release|Any CPU + {47EFADC2-A1E9-469F-ABEA-5650111CA298}.Release|x86.ActiveCfg = Release|Any CPU + {47EFADC2-A1E9-469F-ABEA-5650111CA298}.Release|x86.Build.0 = Release|Any CPU + {35F3CCFF-FE63-4B92-96F7-AA45AE20995D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {35F3CCFF-FE63-4B92-96F7-AA45AE20995D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {35F3CCFF-FE63-4B92-96F7-AA45AE20995D}.Debug|x64.ActiveCfg = Debug|Any CPU + {35F3CCFF-FE63-4B92-96F7-AA45AE20995D}.Debug|x64.Build.0 = Debug|Any CPU + {35F3CCFF-FE63-4B92-96F7-AA45AE20995D}.Debug|x86.ActiveCfg = Debug|Any CPU + {35F3CCFF-FE63-4B92-96F7-AA45AE20995D}.Debug|x86.Build.0 = Debug|Any CPU + {35F3CCFF-FE63-4B92-96F7-AA45AE20995D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {35F3CCFF-FE63-4B92-96F7-AA45AE20995D}.Release|Any CPU.Build.0 = Release|Any CPU + {35F3CCFF-FE63-4B92-96F7-AA45AE20995D}.Release|x64.ActiveCfg = Release|Any CPU + {35F3CCFF-FE63-4B92-96F7-AA45AE20995D}.Release|x64.Build.0 = Release|Any CPU + {35F3CCFF-FE63-4B92-96F7-AA45AE20995D}.Release|x86.ActiveCfg = Release|Any CPU + {35F3CCFF-FE63-4B92-96F7-AA45AE20995D}.Release|x86.Build.0 = Release|Any CPU + {AD281B1D-A50E-4C8C-B29C-BF33B3FD53B2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {AD281B1D-A50E-4C8C-B29C-BF33B3FD53B2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {AD281B1D-A50E-4C8C-B29C-BF33B3FD53B2}.Debug|x64.ActiveCfg = Debug|Any CPU + {AD281B1D-A50E-4C8C-B29C-BF33B3FD53B2}.Debug|x64.Build.0 = Debug|Any CPU + {AD281B1D-A50E-4C8C-B29C-BF33B3FD53B2}.Debug|x86.ActiveCfg = Debug|Any CPU + {AD281B1D-A50E-4C8C-B29C-BF33B3FD53B2}.Debug|x86.Build.0 = Debug|Any CPU + {AD281B1D-A50E-4C8C-B29C-BF33B3FD53B2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {AD281B1D-A50E-4C8C-B29C-BF33B3FD53B2}.Release|Any CPU.Build.0 = Release|Any CPU + {AD281B1D-A50E-4C8C-B29C-BF33B3FD53B2}.Release|x64.ActiveCfg = Release|Any CPU + {AD281B1D-A50E-4C8C-B29C-BF33B3FD53B2}.Release|x64.Build.0 = Release|Any CPU + {AD281B1D-A50E-4C8C-B29C-BF33B3FD53B2}.Release|x86.ActiveCfg = Release|Any CPU + {AD281B1D-A50E-4C8C-B29C-BF33B3FD53B2}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection EndGlobal From 0ffb31e9f7a7bf88493be3e79b8d947b434a94a8 Mon Sep 17 00:00:00 2001 From: MacBook Pro Developer <4freelancerdevelopers@gmail.com> Date: Thu, 24 Dec 2020 16:31:34 -0700 Subject: [PATCH 5/5] removed proof of concept projects --- .../Facware.Base.Api.Test.csproj | 22 ----- Facware.Base.Api.Test/UnitTest1.cs | 14 ---- .../Controllers/WeatherForecastController.cs | 39 --------- .../Extensions/Database/DatabaseExtension.cs | 24 ------ Facware.Base.Api/Facware.Base.Api.csproj | 23 ----- Facware.Base.Api/Facware.Base.Api.sln | 17 ---- Facware.Base.Api/Helpers/AppSettings.cs | 41 --------- Facware.Base.Api/Program.cs | 26 ------ .../Properties/launchSettings.json | 31 ------- Facware.Base.Api/Startup.cs | 84 ------------------- Facware.Base.Api/WeatherForecast.cs | 15 ---- Facware.Base.Api/appsettings.Development.json | 23 ----- Facware.Base.Api/appsettings.json | 10 --- .../Facware.Base.Database.Access.csproj | 23 ----- .../FacwareBaseContext.cs | 46 ---------- Facware.Base.Models/Definitions/Item.cs | 14 ---- .../Facware.Base.Models.csproj | 7 -- Facware.Base.Repositories/Class1.cs | 8 -- .../Facware.Base.Repositories.csproj | 7 -- Facware.Data.Access/Readme.md | 1 + 20 files changed, 1 insertion(+), 474 deletions(-) delete mode 100644 Facware.Base.Api.Test/Facware.Base.Api.Test.csproj delete mode 100644 Facware.Base.Api.Test/UnitTest1.cs delete mode 100644 Facware.Base.Api/Controllers/WeatherForecastController.cs delete mode 100644 Facware.Base.Api/Extensions/Database/DatabaseExtension.cs delete mode 100644 Facware.Base.Api/Facware.Base.Api.csproj delete mode 100644 Facware.Base.Api/Facware.Base.Api.sln delete mode 100644 Facware.Base.Api/Helpers/AppSettings.cs delete mode 100644 Facware.Base.Api/Program.cs delete mode 100644 Facware.Base.Api/Properties/launchSettings.json delete mode 100644 Facware.Base.Api/Startup.cs delete mode 100644 Facware.Base.Api/WeatherForecast.cs delete mode 100644 Facware.Base.Api/appsettings.Development.json delete mode 100644 Facware.Base.Api/appsettings.json delete mode 100644 Facware.Base.Database.Access/Facware.Base.Database.Access.csproj delete mode 100644 Facware.Base.Database.Access/FacwareBaseContext.cs delete mode 100644 Facware.Base.Models/Definitions/Item.cs delete mode 100644 Facware.Base.Models/Facware.Base.Models.csproj delete mode 100644 Facware.Base.Repositories/Class1.cs delete mode 100644 Facware.Base.Repositories/Facware.Base.Repositories.csproj diff --git a/Facware.Base.Api.Test/Facware.Base.Api.Test.csproj b/Facware.Base.Api.Test/Facware.Base.Api.Test.csproj deleted file mode 100644 index 89e935f..0000000 --- a/Facware.Base.Api.Test/Facware.Base.Api.Test.csproj +++ /dev/null @@ -1,22 +0,0 @@ - - - - net5.0 - - false - - - - - - - runtime; build; native; contentfiles; analyzers; buildtransitive - all - - - runtime; build; native; contentfiles; analyzers; buildtransitive - all - - - - diff --git a/Facware.Base.Api.Test/UnitTest1.cs b/Facware.Base.Api.Test/UnitTest1.cs deleted file mode 100644 index 99e3d47..0000000 --- a/Facware.Base.Api.Test/UnitTest1.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; -using Xunit; - -namespace Facware.Base.Api.Test -{ - public class UnitTest1 - { - [Fact] - public void Test1() - { - - } - } -} diff --git a/Facware.Base.Api/Controllers/WeatherForecastController.cs b/Facware.Base.Api/Controllers/WeatherForecastController.cs deleted file mode 100644 index 746c338..0000000 --- a/Facware.Base.Api/Controllers/WeatherForecastController.cs +++ /dev/null @@ -1,39 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc; -using Microsoft.Extensions.Logging; - -namespace Facware.Base.Api.Controllers -{ - [ApiController] - [Route("[controller]")] - public class WeatherForecastController : ControllerBase - { - private static readonly string[] Summaries = new[] - { - "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" - }; - - private readonly ILogger _logger; - - public WeatherForecastController(ILogger logger) - { - _logger = logger; - } - - [HttpGet] - public IEnumerable Get() - { - var rng = new Random(); - return Enumerable.Range(1, 5).Select(index => new WeatherForecast - { - Date = DateTime.Now.AddDays(index), - TemperatureC = rng.Next(-20, 55), - Summary = Summaries[rng.Next(Summaries.Length)] - }) - .ToArray(); - } - } -} diff --git a/Facware.Base.Api/Extensions/Database/DatabaseExtension.cs b/Facware.Base.Api/Extensions/Database/DatabaseExtension.cs deleted file mode 100644 index 0bf94f7..0000000 --- a/Facware.Base.Api/Extensions/Database/DatabaseExtension.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System; -using Facware.Base.Database; -using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.DependencyInjection; - -namespace Facware.Base.Api.Extensions.Database -{ - public static class DatabaseExtension - { - /// - /// Set up the Service PostgreSQL DB Context - /// - /// The - /// The data migration connection string - public static void UsePostgreSqlServer(this IServiceCollection serviceCollection, string applicationConfigurationConnectionString) - { - // https://www.npgsql.org/efcore/api/Microsoft.Extensions.DependencyInjection.NpgsqlServiceCollectionExtensions.html#Microsoft_Extensions_DependencyInjection_NpgsqlServiceCollectionExtensions_AddEntityFrameworkNpgsql_IServiceCollection_ - // https://www.npgsql.org/efcore/index.html#additional-configuration-for-aspnet-core-applications - - // TODO: use your context - serviceCollection.AddDbContext(options => options.UseNpgsql(applicationConfigurationConnectionString)); - } - } -} diff --git a/Facware.Base.Api/Facware.Base.Api.csproj b/Facware.Base.Api/Facware.Base.Api.csproj deleted file mode 100644 index 1283a09..0000000 --- a/Facware.Base.Api/Facware.Base.Api.csproj +++ /dev/null @@ -1,23 +0,0 @@ - - - - net5.0 - - - - - - - - - - - - - - - - - - - diff --git a/Facware.Base.Api/Facware.Base.Api.sln b/Facware.Base.Api/Facware.Base.Api.sln deleted file mode 100644 index 63ef543..0000000 --- a/Facware.Base.Api/Facware.Base.Api.sln +++ /dev/null @@ -1,17 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 15 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Facware.Base.Api", "Facware.Base.Api.csproj", "{A3AE6E45-6B4F-477A-85B0-93EFD1A1BF9B}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {A3AE6E45-6B4F-477A-85B0-93EFD1A1BF9B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {A3AE6E45-6B4F-477A-85B0-93EFD1A1BF9B}.Debug|Any CPU.Build.0 = Debug|Any CPU - {A3AE6E45-6B4F-477A-85B0-93EFD1A1BF9B}.Release|Any CPU.ActiveCfg = Release|Any CPU - {A3AE6E45-6B4F-477A-85B0-93EFD1A1BF9B}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection -EndGlobal diff --git a/Facware.Base.Api/Helpers/AppSettings.cs b/Facware.Base.Api/Helpers/AppSettings.cs deleted file mode 100644 index a28ce15..0000000 --- a/Facware.Base.Api/Helpers/AppSettings.cs +++ /dev/null @@ -1,41 +0,0 @@ -namespace Facware.Base.Api.Helpers -{ - public class AppSettings - { - public Logging Logging { get; set; } - public ConnectionStrings ConnectionStrings { get; set; } - public SwaggerConfiguration SwaggerConfiguration { get; set; } - } - - public class LogLevel - { - public string Default { get; set; } - public string Microsoft { get; set; } - public string MicrosoftHostingLifetime { get; set; } - } - - public class Logging - { - public LogLevel LogLevel { get; set; } - } - - public class ConnectionStrings - { - public string FacwareConnectionString { get; set; } - } - - public class SwaggerConfiguration - { - public string SwaggerJSONEndpoints { get; set; } - public string Title { get; set; } - public string Version { get; set; } - public string Description { get; set; } - public string TermsOfService { get; set; } - public string ContactName { get; set; } - public string ContactEmail { get; set; } - public string LicenseName { get; set; } - public string LicenseUrl { get; set; } - } - - -} diff --git a/Facware.Base.Api/Program.cs b/Facware.Base.Api/Program.cs deleted file mode 100644 index 358000d..0000000 --- a/Facware.Base.Api/Program.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Hosting; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.Hosting; -using Microsoft.Extensions.Logging; - -namespace Facware.Base.Api -{ - public class Program - { - public static void Main(string[] args) - { - CreateHostBuilder(args).Build().Run(); - } - - public static IHostBuilder CreateHostBuilder(string[] args) => - Host.CreateDefaultBuilder(args) - .ConfigureWebHostDefaults(webBuilder => - { - webBuilder.UseStartup(); - }); - } -} diff --git a/Facware.Base.Api/Properties/launchSettings.json b/Facware.Base.Api/Properties/launchSettings.json deleted file mode 100644 index 293108d..0000000 --- a/Facware.Base.Api/Properties/launchSettings.json +++ /dev/null @@ -1,31 +0,0 @@ -{ - "$schema": "http://json.schemastore.org/launchsettings.json", - "iisSettings": { - "windowsAuthentication": false, - "anonymousAuthentication": true, - "iisExpress": { - "applicationUrl": "http://localhost:1888", - "sslPort": 44395 - } - }, - "profiles": { - "IIS Express": { - "commandName": "IISExpress", - "launchBrowser": true, - "launchUrl": "swagger", - "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" - } - }, - "Facware.Base.Api": { - "commandName": "Project", - "dotnetRunMessages": "true", - "launchBrowser": true, - "launchUrl": "swagger", - "applicationUrl": "https://localhost:5001;http://localhost:5000", - "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" - } - } - } -} diff --git a/Facware.Base.Api/Startup.cs b/Facware.Base.Api/Startup.cs deleted file mode 100644 index 2e53487..0000000 --- a/Facware.Base.Api/Startup.cs +++ /dev/null @@ -1,84 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Facware.Base.Api.Extensions.Database; -using Facware.Base.Database; -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.HttpsPolicy; -using Microsoft.AspNetCore.Mvc; -using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; -using Microsoft.Extensions.Logging; -using Microsoft.OpenApi.Models; -using Facware.Base.Api.Helpers; - -namespace Facware.Base.Api -{ - public class Startup - { - public Startup(IConfiguration configuration) - { - _configuration = configuration; - } - - public IConfiguration _configuration { get; } - - /// - /// Load configuration settings - /// - /// - private void ConfigureConfigSettings(IServiceCollection services) - { - services - .AddOptions() - .Configure(_configuration.GetSection(nameof(ConnectionStrings))); - } - - // This method gets called by the runtime. Use this method to add services to the container. - public void ConfigureServices(IServiceCollection services) - { - #region Database context service - - var cn = _configuration.GetSection("ConnectionStrings:FacwareConnectionString"); - - // TODO: before use this, create your own dbcontext - services.UsePostgreSqlServer(cn.Value); - - // in memory db - // services.UseInMemoryDatabase(); - #endregion - - services.AddControllers(); - services.AddSwaggerGen(c => - { - c.SwaggerDoc("v1", new OpenApiInfo { Title = "Facware.Base.Api", Version = "v1" }); - }); - } - - // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. - public void Configure(IApplicationBuilder app, IWebHostEnvironment env) - { - if (env.IsDevelopment()) - { - app.UseDeveloperExceptionPage(); - app.UseSwagger(); - app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "Facware.Base.Api v1")); - } - - app.UseHttpsRedirection(); - - app.UseRouting(); - - app.UseAuthorization(); - - app.UseEndpoints(endpoints => - { - endpoints.MapControllers(); - }); - } - } -} diff --git a/Facware.Base.Api/WeatherForecast.cs b/Facware.Base.Api/WeatherForecast.cs deleted file mode 100644 index fc07f99..0000000 --- a/Facware.Base.Api/WeatherForecast.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System; - -namespace Facware.Base.Api -{ - public class WeatherForecast - { - public DateTime Date { get; set; } - - public int TemperatureC { get; set; } - - public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); - - public string Summary { get; set; } - } -} diff --git a/Facware.Base.Api/appsettings.Development.json b/Facware.Base.Api/appsettings.Development.json deleted file mode 100644 index cedea21..0000000 --- a/Facware.Base.Api/appsettings.Development.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "Logging": { - "LogLevel": { - "Default": "Information", - "Microsoft": "Warning", - "Microsoft.Hosting.Lifetime": "Information" - } - }, - "ConnectionStrings": { - "FacwareConnectionString": "Server=127.0.0.1;Port=5432;Database=Facware;User Id=postgres;Password=postgres;" - }, - "SwaggerConfiguration": { - "SwaggerJSONEndpoints": "swagger/v1/swagger.json", - "Title": "Facware Base", - "Version": "V1.0", - "Description": "Facware base project.", - "TermsOfService": "https://luisespinoza.facware.com/", - "ContactName": "luis.espinoza@afacware.com respinozabarboza@gmail.com", - "ContactEmail": "luis.espinoza@afacware.com respinozabarboza@gmail.com", - "LicenseName": "MIT", - "LicenseUrl": "https://opensource.org/licenses/MIT" - } -} diff --git a/Facware.Base.Api/appsettings.json b/Facware.Base.Api/appsettings.json deleted file mode 100644 index 81ff877..0000000 --- a/Facware.Base.Api/appsettings.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "Logging": { - "LogLevel": { - "Default": "Information", - "Microsoft": "Warning", - "Microsoft.Hosting.Lifetime": "Information" - } - }, - "AllowedHosts": "*" -} diff --git a/Facware.Base.Database.Access/Facware.Base.Database.Access.csproj b/Facware.Base.Database.Access/Facware.Base.Database.Access.csproj deleted file mode 100644 index c6a6598..0000000 --- a/Facware.Base.Database.Access/Facware.Base.Database.Access.csproj +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - - - - runtime; build; native; contentfiles; analyzers; buildtransitive - all - - - runtime; build; native; contentfiles; analyzers; buildtransitive - all - - - - - - net5.0 - - - diff --git a/Facware.Base.Database.Access/FacwareBaseContext.cs b/Facware.Base.Database.Access/FacwareBaseContext.cs deleted file mode 100644 index e268e47..0000000 --- a/Facware.Base.Database.Access/FacwareBaseContext.cs +++ /dev/null @@ -1,46 +0,0 @@ -using System; -using Facware.Base.Models.Definitions; -using Microsoft.EntityFrameworkCore; - -namespace Facware.Base.Database -{ - public class FacwareBaseContext : DbContext - { - public FacwareBaseContext() { } - /* - public FacwareBaseContext(DbContextOptions options) - : base(options) - { - _ = Database.EnsureCreated(); - }*/ - - - public DbSet Item { get; set; } - - - protected override void OnModelCreating(ModelBuilder modelBuilder) - { - base.OnModelCreating(modelBuilder); - - modelBuilder.Entity().HasData( - new Item - { - ItemId = 1, - Name = "Electronics", - Price = 1, - Enabled = true, - CreatedDate = DateTimeOffset.Now - }, - new Item - { - ItemId = 2, - Name = "Electronics", - Price = 2, - Enabled = true, - CreatedDate = DateTimeOffset.Now - } - );; - } - - } -} \ No newline at end of file diff --git a/Facware.Base.Models/Definitions/Item.cs b/Facware.Base.Models/Definitions/Item.cs deleted file mode 100644 index 40af534..0000000 --- a/Facware.Base.Models/Definitions/Item.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; - -namespace Facware.Base.Models.Definitions -{ - public class Item - { - public int ItemId { get; set; } - public string Name { get; set; } - public decimal Price { get; set; } - public DateTimeOffset CreatedDate { get; set; } - public bool Enabled { get; set; } - - } -} diff --git a/Facware.Base.Models/Facware.Base.Models.csproj b/Facware.Base.Models/Facware.Base.Models.csproj deleted file mode 100644 index 563e6f9..0000000 --- a/Facware.Base.Models/Facware.Base.Models.csproj +++ /dev/null @@ -1,7 +0,0 @@ - - - - net5.0 - - - diff --git a/Facware.Base.Repositories/Class1.cs b/Facware.Base.Repositories/Class1.cs deleted file mode 100644 index eb0113f..0000000 --- a/Facware.Base.Repositories/Class1.cs +++ /dev/null @@ -1,8 +0,0 @@ -using System; - -namespace Facware.Base.Repositories -{ - public class Class1 - { - } -} diff --git a/Facware.Base.Repositories/Facware.Base.Repositories.csproj b/Facware.Base.Repositories/Facware.Base.Repositories.csproj deleted file mode 100644 index 563e6f9..0000000 --- a/Facware.Base.Repositories/Facware.Base.Repositories.csproj +++ /dev/null @@ -1,7 +0,0 @@ - - - - net5.0 - - - diff --git a/Facware.Data.Access/Readme.md b/Facware.Data.Access/Readme.md index bdeeffe..aee369a 100644 --- a/Facware.Data.Access/Readme.md +++ b/Facware.Data.Access/Readme.md @@ -1,4 +1,5 @@ dotnet add package Microsoft.EntityFrameworkCore.Tools.DotNet --version 2.0.3 +https://www.nuget.org/packages/Microsoft.EntityFrameworkCore.Tools.DotNet/ dotnet ef migrations add init --startup-project ../Facware.Api --verbose