├── obj ├── Debug │ └── netcoreapp2.2 │ │ ├── TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs │ │ ├── TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs │ │ ├── TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs │ │ ├── CommandAPI.RazorAssemblyInfo.cache │ │ ├── CommandAPI.AssemblyInfoInputs.cache │ │ ├── CommandAPI.RazorTargetAssemblyInfo.cache │ │ ├── CommandAPI.csproj.CoreCompileInputs.cache │ │ ├── CommandAPI.dll │ │ ├── CommandAPI.pdb │ │ ├── CommandAPI.assets.cache │ │ ├── CommandAPI.csprojAssemblyReference.cache │ │ ├── project.razor.json │ │ ├── CommandAPI.RazorAssemblyInfo.cs │ │ ├── CommandAPI.AssemblyInfo.cs │ │ └── CommandAPI.csproj.FileListAbsolute.txt ├── CommandAPI.csproj.nuget.cache ├── CommandAPI.csproj.EntityFrameworkCore.targets ├── CommandAPI.csproj.nuget.g.targets └── CommandAPI.csproj.nuget.g.props ├── README.md ├── bin └── Debug │ └── netcoreapp2.2 │ ├── CommandAPI.dll │ ├── CommandAPI.pdb │ ├── CommandAPI.runtimeconfig.dev.json │ └── CommandAPI.runtimeconfig.json ├── appsettings.Development.json ├── appsettings.json ├── Models ├── Command.cs └── CommandContext.cs ├── .vscode ├── tasks.json └── launch.json ├── azure-pipelines.yml ├── CommandAPI.csproj ├── Program.cs ├── Properties └── launchSettings.json ├── Migrations ├── 20190226100232_StartAgain.cs ├── CommandContextModelSnapshot.cs └── 20190226100232_StartAgain.Designer.cs ├── Startup.cs └── Controllers └── CommandsController.cs /obj/Debug/netcoreapp2.2/TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /obj/Debug/netcoreapp2.2/TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /obj/Debug/netcoreapp2.2/TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /obj/Debug/netcoreapp2.2/CommandAPI.RazorAssemblyInfo.cache: -------------------------------------------------------------------------------- 1 | abfcb7602b1c9a0225c1ebba43c6b786441749a8 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # S02E01-REST-API-.Net-Core 2 | Example of a full REST API build using .Net Core 2.2 and c# 3 | -------------------------------------------------------------------------------- /obj/Debug/netcoreapp2.2/CommandAPI.AssemblyInfoInputs.cache: -------------------------------------------------------------------------------- 1 | 34c0678c3c5fa4d061af6d77fdc0e4e4ff64c0f6 2 | -------------------------------------------------------------------------------- /obj/Debug/netcoreapp2.2/CommandAPI.RazorTargetAssemblyInfo.cache: -------------------------------------------------------------------------------- 1 | 7d1d28477c4467525b67b7f780bc66be9970939c 2 | -------------------------------------------------------------------------------- /obj/Debug/netcoreapp2.2/CommandAPI.csproj.CoreCompileInputs.cache: -------------------------------------------------------------------------------- 1 | a7d78abb67ce12bc3d42819ad4772db650d28a95 2 | -------------------------------------------------------------------------------- /bin/Debug/netcoreapp2.2/CommandAPI.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/binarythistle/S02E01-REST-API-.Net-Core/HEAD/bin/Debug/netcoreapp2.2/CommandAPI.dll -------------------------------------------------------------------------------- /bin/Debug/netcoreapp2.2/CommandAPI.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/binarythistle/S02E01-REST-API-.Net-Core/HEAD/bin/Debug/netcoreapp2.2/CommandAPI.pdb -------------------------------------------------------------------------------- /obj/Debug/netcoreapp2.2/CommandAPI.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/binarythistle/S02E01-REST-API-.Net-Core/HEAD/obj/Debug/netcoreapp2.2/CommandAPI.dll -------------------------------------------------------------------------------- /obj/Debug/netcoreapp2.2/CommandAPI.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/binarythistle/S02E01-REST-API-.Net-Core/HEAD/obj/Debug/netcoreapp2.2/CommandAPI.pdb -------------------------------------------------------------------------------- /obj/Debug/netcoreapp2.2/CommandAPI.assets.cache: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/binarythistle/S02E01-REST-API-.Net-Core/HEAD/obj/Debug/netcoreapp2.2/CommandAPI.assets.cache -------------------------------------------------------------------------------- /obj/CommandAPI.csproj.nuget.cache: -------------------------------------------------------------------------------- 1 | { 2 | "version": 1, 3 | "dgSpecHash": "qYB3Jq4eIMNzZE2Aayq7qNiRAPCfArOPlBXZ4zs6Mpv6af4/eKM95NtI7GXTKO8QNOZ7V+xxmrkzSDZH5vBZgQ==", 4 | "success": true 5 | } -------------------------------------------------------------------------------- /obj/Debug/netcoreapp2.2/CommandAPI.csprojAssemblyReference.cache: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/binarythistle/S02E01-REST-API-.Net-Core/HEAD/obj/Debug/netcoreapp2.2/CommandAPI.csprojAssemblyReference.cache -------------------------------------------------------------------------------- /appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Debug", 5 | "System": "Information", 6 | "Microsoft": "Information" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Data": 3 | { 4 | "CommandAPIConnection" : 5 | { 6 | "ConnectionString" : "Server=DESKTOP-H958OBO\\SQLEXPRESS;Database=CommandAPI;Trusted_Connection=True;MultipleActiveResultSets=true" 7 | } 8 | } 9 | } -------------------------------------------------------------------------------- /bin/Debug/netcoreapp2.2/CommandAPI.runtimeconfig.dev.json: -------------------------------------------------------------------------------- 1 | { 2 | "runtimeOptions": { 3 | "additionalProbingPaths": [ 4 | "C:\\Users\\lesja\\.dotnet\\store\\|arch|\\|tfm|", 5 | "C:\\Users\\lesja\\.nuget\\packages", 6 | "C:\\Program Files\\dotnet\\sdk\\NuGetFallbackFolder" 7 | ] 8 | } 9 | } -------------------------------------------------------------------------------- /bin/Debug/netcoreapp2.2/CommandAPI.runtimeconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "runtimeOptions": { 3 | "tfm": "netcoreapp2.2", 4 | "framework": { 5 | "name": "Microsoft.AspNetCore.App", 6 | "version": "2.2.0" 7 | }, 8 | "configProperties": { 9 | "System.GC.Server": true 10 | } 11 | } 12 | } -------------------------------------------------------------------------------- /Models/Command.cs: -------------------------------------------------------------------------------- 1 | namespace CommandAPI.Models 2 | { 3 | public class Command 4 | { 5 | 6 | //Comment set after pulling azure-pipelines.yaml 7 | 8 | public int Id {get; set;} 9 | public string Howto {get; set;} 10 | public string Platform {get; set;} 11 | public string Commandline {get; set;} 12 | } 13 | } 14 | 15 | -------------------------------------------------------------------------------- /Models/CommandContext.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore; 2 | 3 | namespace CommandAPI.Models 4 | { 5 | public class CommandContext : DbContext 6 | { 7 | public CommandContext(DbContextOptions options) :base(options) 8 | { 9 | 10 | } 11 | 12 | public DbSet CommandItems {get; set;} 13 | } 14 | } -------------------------------------------------------------------------------- /.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "2.0.0", 3 | "tasks": [ 4 | { 5 | "label": "build", 6 | "command": "dotnet", 7 | "type": "process", 8 | "args": [ 9 | "build", 10 | "${workspaceFolder}/CommandAPI.csproj" 11 | ], 12 | "problemMatcher": "$msCompile" 13 | } 14 | ] 15 | } -------------------------------------------------------------------------------- /obj/Debug/netcoreapp2.2/project.razor.json: -------------------------------------------------------------------------------- 1 | { 2 | "ProjectFilePath": "c:\\Users\\lesja\\OneDrive\\Documents\\VSCode\\CommandAPI\\CommandAPI.csproj", 3 | "TargetFramework": "netcoreapp2.2", 4 | "TagHelpers": [], 5 | "Configuration": { 6 | "ConfigurationName": "MVC-2.1", 7 | "LanguageVersion": "2.1", 8 | "Extensions": [ 9 | { 10 | "ExtensionName": "MVC-2.1" 11 | } 12 | ] 13 | } 14 | } -------------------------------------------------------------------------------- /azure-pipelines.yml: -------------------------------------------------------------------------------- 1 | # ASP.NET Core 2 | # Build and test ASP.NET Core projects targeting .NET Core. 3 | # Add steps that run tests, create a NuGet package, deploy, and more: 4 | # https://docs.microsoft.com/azure/devops/pipelines/languages/dotnet-core 5 | 6 | trigger: 7 | - master 8 | 9 | pool: 10 | vmImage: 'Ubuntu-16.04' 11 | 12 | variables: 13 | buildConfiguration: 'Release' 14 | 15 | steps: 16 | - script: dotnet build --configuration $(buildConfiguration) 17 | displayName: 'dotnet build $(buildConfiguration)' 18 | -------------------------------------------------------------------------------- /CommandAPI.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp2.2 5 | InProcess 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | using Microsoft.AspNetCore; 7 | using Microsoft.AspNetCore.Hosting; 8 | using Microsoft.Extensions.Configuration; 9 | using Microsoft.Extensions.Logging; 10 | 11 | namespace CommandAPI 12 | { 13 | public class Program 14 | { 15 | public static void Main(string[] args) 16 | { 17 | CreateWebHostBuilder(args).Build().Run(); 18 | } 19 | 20 | public static IWebHostBuilder CreateWebHostBuilder(string[] args) => 21 | WebHost.CreateDefaultBuilder(args) 22 | .UseStartup(); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:5672", 7 | "sslPort": 44333 8 | } 9 | }, 10 | "profiles": { 11 | "IIS Express": { 12 | "commandName": "IISExpress", 13 | "launchBrowser": true, 14 | "environmentVariables": { 15 | "ASPNETCORE_ENVIRONMENT": "Development" 16 | } 17 | }, 18 | "CommandAPI": { 19 | "commandName": "Project", 20 | "launchBrowser": true, 21 | "applicationUrl": "https://localhost:5001;http://localhost:5000", 22 | "environmentVariables": { 23 | "ASPNETCORE_ENVIRONMENT": "Development" 24 | } 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /obj/Debug/netcoreapp2.2/CommandAPI.RazorAssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | using System; 12 | using System.Reflection; 13 | 14 | [assembly: Microsoft.AspNetCore.Mvc.ApplicationParts.RelatedAssemblyAttribute("CommandAPI.Views")] 15 | [assembly: Microsoft.AspNetCore.Razor.Hosting.RazorLanguageVersionAttribute("2.1")] 16 | [assembly: Microsoft.AspNetCore.Razor.Hosting.RazorConfigurationNameAttribute("MVC-2.1")] 17 | [assembly: Microsoft.AspNetCore.Razor.Hosting.RazorExtensionAssemblyNameAttribute("MVC-2.1", "Microsoft.AspNetCore.Mvc.Razor.Extensions")] 18 | 19 | // Generated by the MSBuild WriteCodeFragment class. 20 | 21 | -------------------------------------------------------------------------------- /obj/Debug/netcoreapp2.2/CommandAPI.AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | using System; 12 | using System.Reflection; 13 | 14 | [assembly: System.Reflection.AssemblyCompanyAttribute("CommandAPI")] 15 | [assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")] 16 | [assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")] 17 | [assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0")] 18 | [assembly: System.Reflection.AssemblyProductAttribute("CommandAPI")] 19 | [assembly: System.Reflection.AssemblyTitleAttribute("CommandAPI")] 20 | [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] 21 | 22 | // Generated by the MSBuild WriteCodeFragment class. 23 | 24 | -------------------------------------------------------------------------------- /Migrations/20190226100232_StartAgain.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore.Metadata; 2 | using Microsoft.EntityFrameworkCore.Migrations; 3 | 4 | namespace CommandAPI.Migrations 5 | { 6 | public partial class StartAgain : Migration 7 | { 8 | protected override void Up(MigrationBuilder migrationBuilder) 9 | { 10 | migrationBuilder.CreateTable( 11 | name: "CommandItems", 12 | columns: table => new 13 | { 14 | Id = table.Column(nullable: false) 15 | .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn), 16 | Howto = table.Column(nullable: true), 17 | Platform = table.Column(nullable: true), 18 | Commandline = table.Column(nullable: true) 19 | }, 20 | constraints: table => 21 | { 22 | table.PrimaryKey("PK_CommandItems", x => x.Id); 23 | }); 24 | } 25 | 26 | protected override void Down(MigrationBuilder migrationBuilder) 27 | { 28 | migrationBuilder.DropTable( 29 | name: "CommandItems"); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /obj/Debug/netcoreapp2.2/CommandAPI.csproj.FileListAbsolute.txt: -------------------------------------------------------------------------------- 1 | C:\Users\lesja\OneDrive\Documents\VSCode\CommandAPI\bin\Debug\netcoreapp2.2\CommandAPI.deps.json 2 | C:\Users\lesja\OneDrive\Documents\VSCode\CommandAPI\bin\Debug\netcoreapp2.2\CommandAPI.runtimeconfig.json 3 | C:\Users\lesja\OneDrive\Documents\VSCode\CommandAPI\bin\Debug\netcoreapp2.2\CommandAPI.runtimeconfig.dev.json 4 | C:\Users\lesja\OneDrive\Documents\VSCode\CommandAPI\bin\Debug\netcoreapp2.2\CommandAPI.dll 5 | C:\Users\lesja\OneDrive\Documents\VSCode\CommandAPI\bin\Debug\netcoreapp2.2\CommandAPI.pdb 6 | C:\Users\lesja\OneDrive\Documents\VSCode\CommandAPI\obj\Debug\netcoreapp2.2\CommandAPI.csprojAssemblyReference.cache 7 | C:\Users\lesja\OneDrive\Documents\VSCode\CommandAPI\obj\Debug\netcoreapp2.2\CommandAPI.csproj.CoreCompileInputs.cache 8 | C:\Users\lesja\OneDrive\Documents\VSCode\CommandAPI\obj\Debug\netcoreapp2.2\CommandAPI.RazorAssemblyInfo.cache 9 | C:\Users\lesja\OneDrive\Documents\VSCode\CommandAPI\obj\Debug\netcoreapp2.2\CommandAPI.RazorAssemblyInfo.cs 10 | C:\Users\lesja\OneDrive\Documents\VSCode\CommandAPI\obj\Debug\netcoreapp2.2\CommandAPI.AssemblyInfoInputs.cache 11 | C:\Users\lesja\OneDrive\Documents\VSCode\CommandAPI\obj\Debug\netcoreapp2.2\CommandAPI.AssemblyInfo.cs 12 | C:\Users\lesja\OneDrive\Documents\VSCode\CommandAPI\obj\Debug\netcoreapp2.2\CommandAPI.RazorTargetAssemblyInfo.cache 13 | C:\Users\lesja\OneDrive\Documents\VSCode\CommandAPI\obj\Debug\netcoreapp2.2\CommandAPI.dll 14 | C:\Users\lesja\OneDrive\Documents\VSCode\CommandAPI\obj\Debug\netcoreapp2.2\CommandAPI.pdb 15 | -------------------------------------------------------------------------------- /Migrations/CommandContextModelSnapshot.cs: -------------------------------------------------------------------------------- 1 | // 2 | using CommandAPI.Models; 3 | using Microsoft.EntityFrameworkCore; 4 | using Microsoft.EntityFrameworkCore.Infrastructure; 5 | using Microsoft.EntityFrameworkCore.Metadata; 6 | using Microsoft.EntityFrameworkCore.Storage.ValueConversion; 7 | 8 | namespace CommandAPI.Migrations 9 | { 10 | [DbContext(typeof(CommandContext))] 11 | partial class CommandContextModelSnapshot : ModelSnapshot 12 | { 13 | protected override void BuildModel(ModelBuilder modelBuilder) 14 | { 15 | #pragma warning disable 612, 618 16 | modelBuilder 17 | .HasAnnotation("ProductVersion", "2.2.0-rtm-35687") 18 | .HasAnnotation("Relational:MaxIdentifierLength", 128) 19 | .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); 20 | 21 | modelBuilder.Entity("CommandAPI.Models.Command", b => 22 | { 23 | b.Property("Id") 24 | .ValueGeneratedOnAdd() 25 | .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); 26 | 27 | b.Property("Commandline"); 28 | 29 | b.Property("Howto"); 30 | 31 | b.Property("Platform"); 32 | 33 | b.HasKey("Id"); 34 | 35 | b.ToTable("CommandItems"); 36 | }); 37 | #pragma warning restore 612, 618 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /obj/CommandAPI.csproj.EntityFrameworkCore.targets: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /Migrations/20190226100232_StartAgain.Designer.cs: -------------------------------------------------------------------------------- 1 | // 2 | using CommandAPI.Models; 3 | using Microsoft.EntityFrameworkCore; 4 | using Microsoft.EntityFrameworkCore.Infrastructure; 5 | using Microsoft.EntityFrameworkCore.Metadata; 6 | using Microsoft.EntityFrameworkCore.Migrations; 7 | using Microsoft.EntityFrameworkCore.Storage.ValueConversion; 8 | 9 | namespace CommandAPI.Migrations 10 | { 11 | [DbContext(typeof(CommandContext))] 12 | [Migration("20190226100232_StartAgain")] 13 | partial class StartAgain 14 | { 15 | protected override void BuildTargetModel(ModelBuilder modelBuilder) 16 | { 17 | #pragma warning disable 612, 618 18 | modelBuilder 19 | .HasAnnotation("ProductVersion", "2.2.0-rtm-35687") 20 | .HasAnnotation("Relational:MaxIdentifierLength", 128) 21 | .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); 22 | 23 | modelBuilder.Entity("CommandAPI.Models.Command", b => 24 | { 25 | b.Property("Id") 26 | .ValueGeneratedOnAdd() 27 | .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); 28 | 29 | b.Property("Commandline"); 30 | 31 | b.Property("Howto"); 32 | 33 | b.Property("Platform"); 34 | 35 | b.HasKey("Id"); 36 | 37 | b.ToTable("CommandItems"); 38 | }); 39 | #pragma warning restore 612, 618 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Startup.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Builder; 6 | using Microsoft.AspNetCore.Hosting; 7 | using Microsoft.AspNetCore.Http; 8 | using Microsoft.Extensions.DependencyInjection; 9 | using Microsoft.Extensions.Configuration; 10 | using Microsoft.AspNetCore.Mvc; 11 | using Microsoft.EntityFrameworkCore; 12 | using CommandAPI.Models; 13 | using Swashbuckle.AspNetCore.Swagger; 14 | 15 | namespace CommandAPI 16 | { 17 | public class Startup 18 | { 19 | public IConfiguration Configuration {get;} 20 | 21 | public Startup(IConfiguration configuration) => Configuration = configuration; 22 | 23 | 24 | public void ConfigureServices(IServiceCollection services) 25 | { 26 | services.AddDbContext 27 | (opt => opt.UseSqlServer(Configuration["Data:CommandAPIConnection:ConnectionString"])); 28 | 29 | services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2); 30 | 31 | services.AddSwaggerGen(c => 32 | { 33 | c.SwaggerDoc("v1", new Info { Title = "My API", Version = "v1" }); 34 | }); 35 | } 36 | 37 | public void Configure(IApplicationBuilder app, IHostingEnvironment env) 38 | { 39 | if (env.IsDevelopment()) 40 | { 41 | app.UseDeveloperExceptionPage(); 42 | } 43 | 44 | app.UseMvc(); 45 | app.UseSwagger(); 46 | 47 | app.UseSwaggerUI(c => 48 | { 49 | c.SwaggerEndpoint("/swagger/v1/swagger.json", "CommandAPI"); 50 | }); 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to find out which attributes exist for C# debugging 3 | // Use hover for the description of the existing attributes 4 | // For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": ".NET Core Launch (web)", 9 | "type": "coreclr", 10 | "request": "launch", 11 | "preLaunchTask": "build", 12 | // If you have changed target frameworks, make sure to update the program path. 13 | "program": "${workspaceFolder}/bin/Debug/netcoreapp2.2/CommandAPI.dll", 14 | "args": [], 15 | "cwd": "${workspaceFolder}", 16 | "stopAtEntry": false, 17 | "internalConsoleOptions": "openOnSessionStart", 18 | "launchBrowser": { 19 | "enabled": true, 20 | "args": "${auto-detect-url}", 21 | "windows": { 22 | "command": "cmd.exe", 23 | "args": "/C start ${auto-detect-url}" 24 | }, 25 | "osx": { 26 | "command": "open" 27 | }, 28 | "linux": { 29 | "command": "xdg-open" 30 | } 31 | }, 32 | "env": { 33 | "ASPNETCORE_ENVIRONMENT": "Development" 34 | }, 35 | "sourceFileMap": { 36 | "/Views": "${workspaceFolder}/Views" 37 | } 38 | }, 39 | { 40 | "name": ".NET Core Attach", 41 | "type": "coreclr", 42 | "request": "attach", 43 | "processId": "${command:pickProcess}" 44 | } 45 | ,] 46 | } -------------------------------------------------------------------------------- /Controllers/CommandsController.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using Microsoft.AspNetCore.Mvc; 3 | using CommandAPI.Models; 4 | using Microsoft.EntityFrameworkCore; 5 | 6 | namespace CommandAPI.Controllers 7 | { 8 | [Route("api/[controller]")] 9 | [ApiController] 10 | public class CommandsController : ControllerBase 11 | { 12 | private readonly CommandContext _context; 13 | 14 | public CommandsController(CommandContext context) 15 | { 16 | _context = context; 17 | } 18 | 19 | //GET: api/commands 20 | [HttpGet] 21 | public ActionResult> GetCommandItems() 22 | { 23 | return _context.CommandItems; 24 | } 25 | 26 | //GET: api/commands/n 27 | [HttpGet("{id}")] 28 | 29 | public ActionResult GetCommandItem(int id) 30 | { 31 | var commandItem = _context.CommandItems.Find(id); 32 | 33 | if (commandItem == null) 34 | { 35 | return NotFound(); 36 | } 37 | 38 | return commandItem; 39 | } 40 | 41 | //POST: api/commands 42 | [HttpPost] 43 | public ActionResult PostCommandItem(Command command) 44 | { 45 | _context.CommandItems.Add(command); 46 | _context.SaveChanges(); 47 | 48 | return CreatedAtAction("GetCommandItem", new Command{Id = command.Id}, command); 49 | } 50 | 51 | //PUT: api/commands/n 52 | [HttpPut("{id}")] 53 | public ActionResult PutCommandItem(int id, Command command) 54 | { 55 | if (id != command.Id) 56 | { 57 | return BadRequest(); 58 | } 59 | 60 | _context.Entry(command).State = EntityState.Modified; 61 | _context.SaveChanges(); 62 | 63 | return NoContent(); 64 | } 65 | 66 | //DELETE: api/commands/n 67 | [HttpDelete("{id}")] 68 | public ActionResult DeleteCommandItem(int id) 69 | { 70 | var commandItem = _context.CommandItems.Find(id); 71 | 72 | if (commandItem == null) 73 | { 74 | return NotFound(); 75 | } 76 | 77 | _context.CommandItems.Remove(commandItem); 78 | _context.SaveChanges(); 79 | 80 | return commandItem; 81 | } 82 | } 83 | } -------------------------------------------------------------------------------- /obj/CommandAPI.csproj.nuget.g.targets: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | $(MSBuildAllProjects);$(MSBuildThisFileFullPath) 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /obj/CommandAPI.csproj.nuget.g.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | True 5 | NuGet 6 | C:\Users\lesja\OneDrive\Documents\VSCode\CommandAPI\obj\project.assets.json 7 | $(UserProfile)\.nuget\packages\ 8 | C:\Users\lesja\.nuget\packages\;C:\Program Files\dotnet\sdk\NuGetFallbackFolder 9 | PackageReference 10 | 4.9.2 11 | 12 | 13 | $(MSBuildAllProjects);$(MSBuildThisFileFullPath) 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.entityframeworkcore.tools\2.2.0 26 | C:\Users\lesja\.nuget\packages\microsoft.codeanalysis.analyzers\1.1.0 27 | C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.aspnetcore.razor.design\2.2.0 28 | 29 | --------------------------------------------------------------------------------