Skip to content

Commit

Permalink
added dotnet80 stack support
Browse files Browse the repository at this point in the history
Signed-off-by: msivasubramaniaan <[email protected]>
  • Loading branch information
msivasubramaniaan committed Jul 19, 2024
1 parent e851f53 commit b795458
Show file tree
Hide file tree
Showing 19 changed files with 545 additions and 3 deletions.
13 changes: 13 additions & 0 deletions pkg/apis/recognizer/devfile_recognizer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ func TestDetectDotNet60Devfile(t *testing.T) {
detectDevfile(t, "dotnet6.0", []string{"dotnet60"})
}

func TestDetectDotNet60Devfile(t *testing.T) {

Check failure on line 47 in pkg/apis/recognizer/devfile_recognizer_test.go

View workflow job for this annotation

GitHub Actions / code-coverage-report

TestDetectDotNet60Devfile redeclared in this block

Check failure on line 47 in pkg/apis/recognizer/devfile_recognizer_test.go

View workflow job for this annotation

GitHub Actions / build

TestDetectDotNet60Devfile redeclared in this block
detectDevfile(t, "dotnet8.0", []string{"dotnet80"})
}

func TestDetectDotNetCore31Devfile(t *testing.T) {
detectDevfile(t, "dotnetcore3.1", []string{"dotnetcore31"})
}
Expand Down Expand Up @@ -686,6 +690,15 @@ func getDevfileTypes() []model.DevfileType {
".Net 6.0",
},
},
{
Name: "dotnet80",
Language: ".NET",
ProjectType: "dotnet",
Tags: []string{
".Net",
".Net 8.0",
},
},
{
Name: "dotnetcore31",
Language: ".NET",
Expand Down
6 changes: 6 additions & 0 deletions resources/projects/dotnet8.0/app/Data/AppConfiguration.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace RazorPagesContacts.Data;

public class AppConfiguration
{
public string DatabaseProvider { get; set; }
}
13 changes: 13 additions & 0 deletions resources/projects/dotnet8.0/app/Data/AppDbContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Microsoft.EntityFrameworkCore;

namespace RazorPagesContacts.Data;

public class AppDbContext : DbContext
{
public AppDbContext(DbContextOptions options)
: base(options)
{
}

public DbSet<Customer> Customers { get; set; }
}
11 changes: 11 additions & 0 deletions resources/projects/dotnet8.0/app/Data/Customer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System.ComponentModel.DataAnnotations;

namespace RazorPagesContacts.Data;

public class Customer
{
public int Id { get; set; }

[Required, StringLength(100)]
public string Name { get; set; }
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;

namespace RazorPagesContacts.Migrations
{
public partial class Initial : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Customers",
columns: table => new
{
Id = table.Column<int>(nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Name = table.Column<string>(maxLength: 100, nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Customers", x => x.Id);
});
}

protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Customers");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// <auto-generated />
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
using RazorPagesContacts.Data;

namespace RazorPagesContacts.Migrations
{
[DbContext(typeof(AppDbContext))]
partial class AppDbContextModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn)
.HasAnnotation("ProductVersion", "3.0.0")
.HasAnnotation("Relational:MaxIdentifierLength", 63);

modelBuilder.Entity("RazorPagesContacts.Data.Customer", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer")
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
b.Property<string>("Name")
.IsRequired()
.HasColumnType("character varying(100)")
.HasMaxLength(100);
b.HasKey("Id");
b.ToTable("Customers");
});
#pragma warning restore 612, 618
}
}
}
16 changes: 16 additions & 0 deletions resources/projects/dotnet8.0/app/Pages/Create.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
@page
@model RazorPagesContacts.Pages.CreateModel
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers

<html>
<body>
<p>
Enter your name.
</p>
<div asp-validation-summary="All"></div>
<form method="POST">
<div>Name: <input asp-for="Customer.Name" /></div>
<input type="submit" />
</form>
</body>
</html>
30 changes: 30 additions & 0 deletions resources/projects/dotnet8.0/app/Pages/Create.cshtml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using RazorPagesContacts.Data;

namespace RazorPagesContacts.Pages;

public class CreateModel : PageModel
{
private readonly AppDbContext _db;

public CreateModel(AppDbContext db)
{
_db = db;
}

[BindProperty]
public Customer Customer { get; set; }

public async Task<IActionResult> OnPostAsync()
{
if (!ModelState.IsValid)
{
return Page();
}

_db.Customers.Add(Customer);
await _db.SaveChangesAsync();
return RedirectToPage("/Index");
}
}
24 changes: 24 additions & 0 deletions resources/projects/dotnet8.0/app/Pages/Edit.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
@page "{id:int}"
@model RazorPagesContacts.Pages.EditModel
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers

@{
ViewData["Title"] = "Edit Customer";
}

<h1>Edit Customer - @Model.Customer.Id</h1>
<form method="post">
<div asp-validation-summary="All"></div>
<input asp-for="Customer.Id" type="hidden" />
<div>
<label asp-for="Customer.Name"></label>
<div>
<input asp-for="Customer.Name" />
<span asp-validation-for="Customer.Name" ></span>
</div>
</div>

<div>
<button type="submit">Save</button>
</div>
</form>
52 changes: 52 additions & 0 deletions resources/projects/dotnet8.0/app/Pages/Edit.cshtml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.EntityFrameworkCore;
using RazorPagesContacts.Data;

namespace RazorPagesContacts.Pages;

public class EditModel : PageModel
{
private readonly AppDbContext _db;

public EditModel(AppDbContext db)
{
_db = db;
}

[BindProperty]
public Customer Customer { get; set; }

public async Task<IActionResult> OnGetAsync(int id)
{
Customer = await _db.Customers.FindAsync(id);

if (Customer == null)
{
return RedirectToPage("/Index");
}

return Page();
}

public async Task<IActionResult> OnPostAsync()
{
if (!ModelState.IsValid)
{
return Page();
}

_db.Attach(Customer).State = EntityState.Modified;

try
{
await _db.SaveChangesAsync();
}
catch (DbUpdateConcurrencyException)
{
throw new Exception($"Customer {Customer.Id} not found!");
}

return RedirectToPage("/Index");
}
}
31 changes: 31 additions & 0 deletions resources/projects/dotnet8.0/app/Pages/Index.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
@page
@model RazorPagesContacts.Pages.IndexModel
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers

<h1>Contacts from @Model.AppConfiguration.DatabaseProvider database</h1>
<form method="post">
<table class="table">
<thead>
<tr>
<th>ID</th>
<th>Name</th>
</tr>
</thead>
<tbody>
@foreach (var contact in Model.Customers)
{
<tr>
<td>@contact.Id</td>
<td>@contact.Name</td>
<td>
<a asp-page="./Edit" asp-route-id="@contact.Id">edit</a>
<button type="submit" asp-page-handler="delete"
asp-route-id="@contact.Id">delete</button>
</td>
</tr>
}
</tbody>
</table>

<a asp-page="./Create">Create</a>
</form>
39 changes: 39 additions & 0 deletions resources/projects/dotnet8.0/app/Pages/Index.cshtml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using RazorPagesContacts.Data;
using Microsoft.EntityFrameworkCore;

namespace RazorPagesContacts.Pages;

public class IndexModel : PageModel
{
private readonly AppDbContext _db;

public IndexModel(AppDbContext db, AppConfiguration appConfig)
{
_db = db;
AppConfiguration = appConfig;
}

public IList<Customer> Customers { get; private set; }

public AppConfiguration AppConfiguration { get; }

public async Task OnGetAsync()
{
Customers = await _db.Customers.AsNoTracking().ToListAsync();
}

public async Task<IActionResult> OnPostDeleteAsync(int id)
{
var contact = await _db.Customers.FindAsync(id);

if (contact != null)
{
_db.Customers.Remove(contact);
await _db.SaveChangesAsync();
}

return RedirectToPage();
}
}
8 changes: 8 additions & 0 deletions resources/projects/dotnet8.0/app/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using RazorPagesContacts;

var builder = Microsoft.AspNetCore.WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>();

var app = builder.Build();

app.Run();
Loading

0 comments on commit b795458

Please sign in to comment.