Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -360,4 +360,7 @@ MigrationBackup/
.ionide/

# Fody - auto-generated XML schema
FodyWeavers.xsd
FodyWeavers.xsd
.idea/.idea.BlazorMinimalApis/.idea/workspace.xml
*.xml
*.xml
57 changes: 36 additions & 21 deletions .idea/.idea.BlazorMinimalApis/.idea/workspace.xml

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

4 changes: 4 additions & 0 deletions BlazorMinimalApis/BlazorMinimalApis.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
<PackageReference Include="Htmx" Version="1.6.1" />
<PackageReference Include="Microsoft.AspNetCore.Components" Version="8.0.0-rc.2.23480.2" />
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="8.0.0-rc.2.23480.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.1">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>

</Project>
6 changes: 6 additions & 0 deletions Samples/BlazorMinimalApis.Mvc/BlazorMinimalApis.Mvc.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.1" />
<PackageReference Include="Riok.Mapperly" Version="3.2.0" />
</ItemGroup>

Expand Down
51 changes: 51 additions & 0 deletions Samples/BlazorMinimalApis.Mvc/Controllers/PlatoController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using System.ComponentModel.DataAnnotations;
using BlazorMinimalApis.Lib.Routing;
using BlazorMinimalApis.Mvc.Data;
using BlazorMinimalApis.Mvc.Views.Contacts;
using Riok.Mapperly.Abstractions;

namespace BlazorMinimalApis.Mvc.Controllers;

public class PlatoController(RambosaDbContext dbContext) : XController
{
public IResult List(HttpContext context)
{
var parameters = new { Clientes = dbContext.Clientes.ToList() };
return View<List>(parameters);
/*var parameters = new { Contacts = Database.Contacts };
return View<List>(parameters);*/
}

/*public IResult Create()
{
var model = new { Form = new CreateContactForm() };
return View<Create>(model);
}*/
}

public class CreatePlatoForm
{
[Required] public string Name { get; set; }
[Required] public int Price { get; set; }
}

[Mapper]
public partial class CreatePlatoMapper
{
public partial CreatePlatoForm PlatoToForm(Plato Plato);
public partial Plato FormToPlato(CreatePlatoForm Plato);
}

public class EditPlatoForm
{
public int Id { get; set; }
[Required] public string Name { get; set; }
[Required] public int Price { get; set; }
}

[Mapper]
public partial class EditPlatoMapper
{
public partial EditPlatoForm PlatoToForm(Plato Plato);
public partial Plato FormToPlato(EditPlatoForm Plato);
}
57 changes: 57 additions & 0 deletions Samples/BlazorMinimalApis.Mvc/Data/RambosaDbContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using System.ComponentModel.DataAnnotations;
using Microsoft.EntityFrameworkCore;

namespace BlazorMinimalApis.Mvc.Data;
/*
* Para hacer migraciones correr:
* dotnet ef migrations add NombreDeLaMigracion
* dotnet ef database update
*/
public class RambosaDbContext : DbContext
{
public RambosaDbContext(DbContextOptions<RambosaDbContext> options) : base(options)
{
}
public DbSet<Blog> Blogs { get; set; }
public DbSet<Post> Posts { get; set; }
public DbSet<Plato> Platos { get; set; }
public DbSet<Cliente> Clientes { get; set; }

/*protected override void OnConfiguring(DbContextOptionsBuilder options)
=> options.UseSqlServer("Server=(local);Database=RambosaDb;Integrated Security=True;MultipleActiveResultSets=False;TrustServerCertificate=True");*/
}

public class Plato
{
public int PlatoId { get; set; }
public int Price { get; set; }
[MaxLength(50)]
public string Name { get; set; } = null!;
}

public class Cliente
{
public int ClienteId { get; set; }
public string Nombre { get; set; }
}

//Un cliente puede pedir muchos platos. Un plato puede ser pedido por muchos clientes.
//La tabla intermedia se va a llamar pedidos. Es una relacion de muchos a muchos.

public class Blog
{
public int BlogId { get; set; }
public string Url { get; set; }

public List<Post> Posts { get; } = new();
}

public class Post
{
public int PostId { get; set; }
public string Title { get; set; }
public string Content { get; set; }

public int BlogId { get; set; }
public Blog Blog { 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,63 @@
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace BlazorMinimalApis.Mvc.Migrations
{
/// <inheritdoc />
public partial class InitialCreate : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Blogs",
columns: table => new
{
BlogId = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Url = table.Column<string>(type: "nvarchar(max)", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Blogs", x => x.BlogId);
});

migrationBuilder.CreateTable(
name: "Posts",
columns: table => new
{
PostId = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Title = table.Column<string>(type: "nvarchar(max)", nullable: false),
Content = table.Column<string>(type: "nvarchar(max)", nullable: false),
BlogId = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Posts", x => x.PostId);
table.ForeignKey(
name: "FK_Posts_Blogs_BlogId",
column: x => x.BlogId,
principalTable: "Blogs",
principalColumn: "BlogId",
onDelete: ReferentialAction.Cascade);
});

migrationBuilder.CreateIndex(
name: "IX_Posts_BlogId",
table: "Posts",
column: "BlogId");
}

/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Posts");

migrationBuilder.DropTable(
name: "Blogs");
}
}
}
Loading