From c359776a221414a07f4124c9dc2e13a99030db65 Mon Sep 17 00:00:00 2001 From: net Date: Thu, 3 Jun 2021 18:03:01 +0200 Subject: [PATCH] init --- .gitignore | 225 +++++++++++++++++++++++++++++++++ Controllers/UsersController.cs | 42 ++++++ Models/IUserRepository.cs | 12 ++ Models/User.cs | 13 ++ Models/UserRepository.cs | 34 +++++ Program.cs | 26 ++++ ProjectGrid.csproj | 49 +++++++ Properties/launchSettings.json | 31 +++++ README.md | 2 + Startup.cs | 59 +++++++++ appsettings.Development.json | 9 ++ appsettings.json | 10 ++ clientapp/.gitignore | 23 ++++ clientapp/package-lock.json | 3 + 14 files changed, 538 insertions(+) create mode 100644 .gitignore create mode 100644 Controllers/UsersController.cs create mode 100644 Models/IUserRepository.cs create mode 100644 Models/User.cs create mode 100644 Models/UserRepository.cs create mode 100644 Program.cs create mode 100644 ProjectGrid.csproj create mode 100644 Properties/launchSettings.json create mode 100644 README.md create mode 100644 Startup.cs create mode 100644 appsettings.Development.json create mode 100644 appsettings.json create mode 100644 clientapp/.gitignore create mode 100644 clientapp/package-lock.json diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3c5eb50 --- /dev/null +++ b/.gitignore @@ -0,0 +1,225 @@ +# The following command works for downloading when using Git for Windows: +# curl -LOf http://gist.githubusercontent.com/kmorcinek/2710267/raw/.gitignore +# +# Download this file using PowerShell v3 under Windows with the following comand: +# Invoke-WebRequest https://gist.githubusercontent.com/kmorcinek/2710267/raw/ -OutFile .gitignore +# +# or wget: +# wget --no-check-certificate http://gist.githubusercontent.com/kmorcinek/2710267/raw/.gitignore + +# User-specific files +*.suo +*.user +*.sln.docstates + +# Build results +[Dd]ebug/ +[Rr]elease/ +x64/ +[Bb]in/ +[Oo]bj/ +# build folder is nowadays used for build scripts and should not be ignored +#build/ + +# NuGet Packages +*.nupkg +# The packages folder can be ignored because of Package Restore +**/packages/* +# except build/, which is used as an MSBuild target. +!**/packages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/packages/repositories.config + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +*_i.c +*_p.c +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.log +*.scc + +# OS generated files # +.DS_Store* +Icon? + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opensdf +*.sdf +*.cachefile + +# Visual Studio profiler +*.psess +*.vsp +*.vspx + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# NCrunch +*.ncrunch* +.*crunch*.local.xml + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.Publish.xml + +# Windows Azure Build Output +csx +*.build.csdef + +# Windows Store app package directory +AppPackages/ + +# Others +*.Cache +ClientBin/ +[Ss]tyle[Cc]op.* +~$* +*~ +*.dbmdl +*.[Pp]ublish.xml +*.pfx +*.publishsettings +modulesbin/ +tempbin/ + +# EPiServer Site file (VPP) +AppData/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file to a newer +# Visual Studio version. Backup files are not needed, because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm + +# vim +*.txt~ +*.swp +*.swo + +# Temp files when opening LibreOffice on ubuntu +.~lock.* + +# svn +.svn + +# CVS - Source Control +**/CVS/ + +# Remainings from resolving conflicts in Source Control +*.orig + +# SQL Server files +**/App_Data/*.mdf +**/App_Data/*.ldf +**/App_Data/*.sdf + + +#LightSwitch generated files +GeneratedArtifacts/ +_Pvt_Extensions/ +ModelManifest.xml + +# ========================= +# Windows detritus +# ========================= + +# Windows image file caches +Thumbs.db +ehthumbs.db + +# Folder config file +Desktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Mac desktop service store files +.DS_Store + +# SASS Compiler cache +.sass-cache + +# Visual Studio 2014 CTP +**/*.sln.ide + +# Visual Studio temp something +.vs/ + +# dotnet stuff +project.lock.json + +# VS 2015+ +*.vc.vc.opendb +*.vc.db + +# Rider +.idea/ + +# Visual Studio Code +.vscode/ + +# Output folder used by Webpack or other FE stuff +**/node_modules/* +**/wwwroot/* + +# SpecFlow specific +*.feature.cs +*.feature.xlsx.* +*.Specs_*.html + +##### +# End of core ignore list, below put you custom 'per project' settings (patterns or path) +##### diff --git a/Controllers/UsersController.cs b/Controllers/UsersController.cs new file mode 100644 index 0000000..dc26737 --- /dev/null +++ b/Controllers/UsersController.cs @@ -0,0 +1,42 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net; +using System.Net.Http; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Logging; + +namespace vue_dotnet_example.Controllers +{ + [ApiController] + public class UsersController : ControllerBase + { + + private readonly ILogger _logger; + + static readonly Models.IUserRepository repository = new Models.UserRepository(); + + public UsersController(ILogger logger) + { + _logger = logger; + } + + [HttpGet] + [Route("api/users")] + public IEnumerable GetAllUsers() + { + return repository.GetAll(); + } + + [HttpPost] + [Route("api/user")] + [Consumes("application/json")] + public Models.UserModel PostUser(Models.UserModel item) + { + return repository.Add(item); + } + + + } +} diff --git a/Models/IUserRepository.cs b/Models/IUserRepository.cs new file mode 100644 index 0000000..f06647c --- /dev/null +++ b/Models/IUserRepository.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; + +namespace vue_dotnet_example.Models +{ + public interface IUserRepository + { + IEnumerable GetAll(); + + UserModel Add(UserModel user); + } +} \ No newline at end of file diff --git a/Models/User.cs b/Models/User.cs new file mode 100644 index 0000000..a8373e0 --- /dev/null +++ b/Models/User.cs @@ -0,0 +1,13 @@ +namespace vue_dotnet_example.Models +{ + public class UserModel + { + public int Id { get; set; } + + public string firstName { get; set; } + + public string lastName { get; set; } + + public string email { get; set; } + } +} \ No newline at end of file diff --git a/Models/UserRepository.cs b/Models/UserRepository.cs new file mode 100644 index 0000000..81f4c1a --- /dev/null +++ b/Models/UserRepository.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; + +namespace vue_dotnet_example.Models +{ + public class UserRepository: IUserRepository + { + private List users = new List(); + private int _nextId = 1; + + public UserRepository() + { + Add(new UserModel { firstName= "first1", lastName="last1", email="email1@gmail.com"}); + Add(new UserModel { firstName= "first2", lastName="last2", email="email2@gmail.com"}); + Add(new UserModel { firstName= "first3", lastName="last3", email="email3@gmail.com"}); + } + + public IEnumerable GetAll() + { + return users; + } + + public UserModel Add(UserModel item) + { + if (item == null) + { + throw new ArgumentNullException("item"); + } + item.Id = _nextId++; + users.Add(item); + return item; + } + } +} \ No newline at end of file diff --git a/Program.cs b/Program.cs new file mode 100644 index 0000000..df4cd9e --- /dev/null +++ b/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 vue_dotnet_example +{ + 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/ProjectGrid.csproj b/ProjectGrid.csproj new file mode 100644 index 0000000..911bae5 --- /dev/null +++ b/ProjectGrid.csproj @@ -0,0 +1,49 @@ + + + + net5.0 + ProjectGrid + clientapp\ + $(DefaultItemExcludes);$(SpaRoot)node_modules\** + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + %(DistFiles.Identity) + PreserveNewest + true + + + + + diff --git a/Properties/launchSettings.json b/Properties/launchSettings.json new file mode 100644 index 0000000..e15df3c --- /dev/null +++ b/Properties/launchSettings.json @@ -0,0 +1,31 @@ +{ + "$schema": "http://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:28358", + "sslPort": 44387 + } + }, + "profiles": { + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "vue_dotnet_example": { + "commandName": "Project", + "dotnetRunMessages": "true", + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "https://localhost:5001;http://localhost:5000", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/README.md b/README.md new file mode 100644 index 0000000..7660810 --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +# vue-dotnet-example +Example Project on how to develop and Build Vue App with DOTNET Web API diff --git a/Startup.cs b/Startup.cs new file mode 100644 index 0000000..8c40b67 --- /dev/null +++ b/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 vue_dotnet_example +{ + 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 = "vue_dotnet_example", 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", "vue_dotnet_example v1")); + } + + app.UseHttpsRedirection(); + + app.UseRouting(); + + app.UseAuthorization(); + + app.UseEndpoints(endpoints => + { + endpoints.MapControllers(); + }); + } + } +} \ No newline at end of file diff --git a/appsettings.Development.json b/appsettings.Development.json new file mode 100644 index 0000000..dba68eb --- /dev/null +++ b/appsettings.Development.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } + } +} diff --git a/appsettings.json b/appsettings.json new file mode 100644 index 0000000..81ff877 --- /dev/null +++ b/appsettings.json @@ -0,0 +1,10 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } + }, + "AllowedHosts": "*" +} diff --git a/clientapp/.gitignore b/clientapp/.gitignore new file mode 100644 index 0000000..403adbc --- /dev/null +++ b/clientapp/.gitignore @@ -0,0 +1,23 @@ +.DS_Store +node_modules +/dist + + +# local env files +.env.local +.env.*.local + +# Log files +npm-debug.log* +yarn-debug.log* +yarn-error.log* +pnpm-debug.log* + +# Editor directories and files +.idea +.vscode +*.suo +*.ntvs* +*.njsproj +*.sln +*.sw? diff --git a/clientapp/package-lock.json b/clientapp/package-lock.json new file mode 100644 index 0000000..48e341a --- /dev/null +++ b/clientapp/package-lock.json @@ -0,0 +1,3 @@ +{ + "lockfileVersion": 1 +}