Skip to content

Commit 8ca216d

Browse files
committed
API Projected completed, NuGet Packages installed.
0 parents  commit 8ca216d

File tree

87 files changed

+11727
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

87 files changed

+11727
-0
lines changed

.vs/TaskApi/v16/.suo

55 KB
Binary file not shown.

TaskApi.sln

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.31911.196
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TaskApi", "TaskApi\TaskApi.csproj", "{3FF5DE64-49A0-4100-8817-60CC1CAAC043}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{3FF5DE64-49A0-4100-8817-60CC1CAAC043}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{3FF5DE64-49A0-4100-8817-60CC1CAAC043}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{3FF5DE64-49A0-4100-8817-60CC1CAAC043}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{3FF5DE64-49A0-4100-8817-60CC1CAAC043}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {2E8CD911-9ABE-4A73-A3B3-B438AA7E6DF4}
24+
EndGlobalSection
25+
EndGlobal

TaskApi/Controllers/TaskController.cs

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
using Microsoft.AspNetCore.Mvc;
2+
using Microsoft.EntityFrameworkCore;
3+
4+
using System.Collections.Generic;
5+
using System.Linq;
6+
using System.Threading.Tasks;
7+
8+
using TaskApi.Models;
9+
10+
namespace TaskApi.Controllers
11+
{
12+
[Route("api/[controller]")]
13+
[ApiController]
14+
public class TaskController : ControllerBase
15+
{
16+
private readonly TaskDbContext _context;
17+
18+
public TaskController(TaskDbContext context)
19+
{
20+
_context = context;
21+
}
22+
23+
[HttpGet]
24+
public async Task<ActionResult<IEnumerable<TaskModel>>> GetTasks()
25+
{
26+
return await _context.Tasks.AsNoTracking().ToArrayAsync();
27+
}
28+
29+
[HttpPost]
30+
public async Task<ActionResult> PostTask(TaskModel task)
31+
{
32+
_context.Tasks.Add(task);
33+
await _context.SaveChangesAsync();
34+
return StatusCode(201);
35+
}
36+
37+
[HttpPut("{id}")]
38+
public async Task<IActionResult> UpdateTask(int id, TaskModel task)
39+
{
40+
if (id != task.Id) return BadRequest();
41+
42+
_context.Entry(task).State = EntityState.Modified;
43+
44+
try
45+
{
46+
await _context.SaveChangesAsync();
47+
}
48+
catch (DbUpdateConcurrencyException)
49+
{
50+
if (!_context.Tasks.Any(x => x.Id == id))
51+
return NotFound();
52+
else throw;
53+
}
54+
55+
return NoContent();
56+
}
57+
58+
[HttpDelete("{id}")]
59+
public async Task<ActionResult<TaskModel>> DeleteTask(int id)
60+
{
61+
var task = await _context.Tasks.FindAsync(id);
62+
63+
if (task == null)
64+
return NotFound();
65+
66+
_context.Tasks.Remove(task);
67+
await _context.SaveChangesAsync();
68+
69+
return task;
70+
}
71+
}
72+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
using Microsoft.AspNetCore.Mvc;
2+
using Microsoft.Extensions.Logging;
3+
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Linq;
7+
using System.Threading.Tasks;
8+
9+
namespace TaskApi.Controllers
10+
{
11+
[ApiController]
12+
[Route("[controller]")]
13+
public class WeatherForecastController : ControllerBase
14+
{
15+
private static readonly string[] Summaries = new[]
16+
{
17+
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
18+
};
19+
20+
private readonly ILogger<WeatherForecastController> _logger;
21+
22+
public WeatherForecastController(ILogger<WeatherForecastController> logger)
23+
{
24+
_logger = logger;
25+
}
26+
27+
[HttpGet]
28+
public IEnumerable<WeatherForecast> Get()
29+
{
30+
var rng = new Random();
31+
return Enumerable.Range(1, 5).Select(index => new WeatherForecast
32+
{
33+
Date = DateTime.Now.AddDays(index),
34+
TemperatureC = rng.Next(-20, 55),
35+
Summary = Summaries[rng.Next(Summaries.Length)]
36+
})
37+
.ToArray();
38+
}
39+
}
40+
}

TaskApi/Migrations/20220212081651_Initial.Designer.cs

Lines changed: 48 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using Microsoft.EntityFrameworkCore.Migrations;
2+
3+
namespace TaskApi.Migrations
4+
{
5+
public partial class Initial : Migration
6+
{
7+
protected override void Up(MigrationBuilder migrationBuilder)
8+
{
9+
migrationBuilder.CreateTable(
10+
name: "Tasks",
11+
columns: table => new
12+
{
13+
Id = table.Column<int>(nullable: false)
14+
.Annotation("SqlServer:Identity", "1, 1"),
15+
Text = table.Column<string>(nullable: false),
16+
Date = table.Column<string>(nullable: false),
17+
Reminder = table.Column<bool>(nullable: false)
18+
},
19+
constraints: table =>
20+
{
21+
table.PrimaryKey("PK_Tasks", x => x.Id);
22+
});
23+
}
24+
25+
protected override void Down(MigrationBuilder migrationBuilder)
26+
{
27+
migrationBuilder.DropTable(
28+
name: "Tasks");
29+
}
30+
}
31+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// <auto-generated />
2+
using Microsoft.EntityFrameworkCore;
3+
using Microsoft.EntityFrameworkCore.Infrastructure;
4+
using Microsoft.EntityFrameworkCore.Metadata;
5+
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
6+
using TaskApi.Models;
7+
8+
namespace TaskApi.Migrations
9+
{
10+
[DbContext(typeof(TaskDbContext))]
11+
partial class TaskDbContextModelSnapshot : ModelSnapshot
12+
{
13+
protected override void BuildModel(ModelBuilder modelBuilder)
14+
{
15+
#pragma warning disable 612, 618
16+
modelBuilder
17+
.HasAnnotation("ProductVersion", "3.1.22")
18+
.HasAnnotation("Relational:MaxIdentifierLength", 128)
19+
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
20+
21+
modelBuilder.Entity("TaskApi.Models.TaskModel", b =>
22+
{
23+
b.Property<int>("Id")
24+
.ValueGeneratedOnAdd()
25+
.HasColumnType("int")
26+
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
27+
28+
b.Property<string>("Date")
29+
.IsRequired()
30+
.HasColumnType("nvarchar(max)");
31+
32+
b.Property<bool>("Reminder")
33+
.HasColumnType("bit");
34+
35+
b.Property<string>("Text")
36+
.IsRequired()
37+
.HasColumnType("nvarchar(max)");
38+
39+
b.HasKey("Id");
40+
41+
b.ToTable("Tasks");
42+
});
43+
#pragma warning restore 612, 618
44+
}
45+
}
46+
}

TaskApi/Models/TaskDbContext.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using Microsoft.EntityFrameworkCore;
2+
3+
namespace TaskApi.Models
4+
{
5+
public class TaskDbContext : DbContext
6+
{
7+
public TaskDbContext(DbContextOptions<TaskDbContext> options) : base(options) { }
8+
9+
public DbSet<TaskModel> Tasks { get; set; }
10+
}
11+
}

TaskApi/Models/TaskModel.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using System.ComponentModel.DataAnnotations;
2+
3+
namespace TaskApi.Models
4+
{
5+
public class TaskModel
6+
{
7+
[Key]
8+
public int Id { get; set; }
9+
10+
[Required(ErrorMessage = "Please enter the task's description text.")]
11+
public string Text { get; set; }
12+
13+
[Required(ErrorMessage = "Please specify the task's due date.")]
14+
public string Date { get; set; }
15+
16+
public bool Reminder { get; set; }
17+
}
18+
}

TaskApi/Program.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using Microsoft.AspNetCore.Hosting;
2+
using Microsoft.Extensions.Configuration;
3+
using Microsoft.Extensions.Hosting;
4+
using Microsoft.Extensions.Logging;
5+
6+
using System;
7+
using System.Collections.Generic;
8+
using System.Linq;
9+
using System.Threading.Tasks;
10+
11+
namespace TaskApi
12+
{
13+
public class Program
14+
{
15+
public static void Main(string[] args)
16+
{
17+
CreateHostBuilder(args).Build().Run();
18+
}
19+
20+
public static IHostBuilder CreateHostBuilder(string[] args) =>
21+
Host.CreateDefaultBuilder(args)
22+
.ConfigureWebHostDefaults(webBuilder =>
23+
{
24+
webBuilder.UseStartup<Startup>();
25+
});
26+
}
27+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"$schema": "http://json.schemastore.org/launchsettings.json",
3+
"iisSettings": {
4+
"windowsAuthentication": false,
5+
"anonymousAuthentication": true,
6+
"iisExpress": {
7+
"applicationUrl": "http://localhost:37252",
8+
"sslPort": 0
9+
}
10+
},
11+
"profiles": {
12+
"IIS Express": {
13+
"commandName": "IISExpress",
14+
"launchBrowser": true,
15+
"launchUrl": "weatherforecast",
16+
"environmentVariables": {
17+
"ASPNETCORE_ENVIRONMENT": "Development"
18+
}
19+
},
20+
"TaskApi": {
21+
"commandName": "Project",
22+
"launchBrowser": true,
23+
"launchUrl": "weatherforecast",
24+
"applicationUrl": "http://localhost:5000",
25+
"environmentVariables": {
26+
"ASPNETCORE_ENVIRONMENT": "Development"
27+
}
28+
}
29+
}
30+
}

0 commit comments

Comments
 (0)