categorys

This commit is contained in:
Tizian.Breuch
2025-07-31 15:14:51 +02:00
parent b608d116f0
commit 50ae33c258
13 changed files with 377 additions and 95 deletions

View File

@@ -12,8 +12,8 @@ using Webshop.Infrastructure.Data;
namespace Webshop.Infrastructure.Migrations
{
[DbContext(typeof(ApplicationDbContext))]
[Migration("20250729184055_InitialCreate")]
partial class InitialCreate
[Migration("20250731131435_addCategory")]
partial class addCategory
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
@@ -225,6 +225,9 @@ namespace Webshop.Infrastructure.Migrations
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<DateTimeOffset>("CreatedDate")
.HasColumnType("timestamp with time zone");
b.Property<string>("Description")
.HasMaxLength(1000)
.HasColumnType("character varying(1000)");
@@ -239,6 +242,9 @@ namespace Webshop.Infrastructure.Migrations
b.Property<bool>("IsActive")
.HasColumnType("boolean");
b.Property<DateTimeOffset?>("LastModifiedDate")
.HasColumnType("timestamp with time zone");
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(255)

View File

@@ -7,7 +7,7 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
namespace Webshop.Infrastructure.Migrations
{
/// <inheritdoc />
public partial class InitialCreate : Migration
public partial class addCategory : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
@@ -23,7 +23,9 @@ namespace Webshop.Infrastructure.Migrations
ParentCategoryId = table.Column<Guid>(type: "uuid", nullable: true),
ImageUrl = table.Column<string>(type: "character varying(2000)", maxLength: 2000, nullable: true),
IsActive = table.Column<bool>(type: "boolean", nullable: false),
DisplayOrder = table.Column<int>(type: "integer", nullable: false)
DisplayOrder = table.Column<int>(type: "integer", nullable: false),
CreatedDate = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
LastModifiedDate = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true)
},
constraints: table =>
{

View File

@@ -222,6 +222,9 @@ namespace Webshop.Infrastructure.Migrations
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<DateTimeOffset>("CreatedDate")
.HasColumnType("timestamp with time zone");
b.Property<string>("Description")
.HasMaxLength(1000)
.HasColumnType("character varying(1000)");
@@ -236,6 +239,9 @@ namespace Webshop.Infrastructure.Migrations
b.Property<bool>("IsActive")
.HasColumnType("boolean");
b.Property<DateTimeOffset?>("LastModifiedDate")
.HasColumnType("timestamp with time zone");
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(255)

View File

@@ -1,11 +1,11 @@
// Auto-generiert von CreateWebshopFiles.ps1
// src/Webshop.Infrastructure/Repositories/CategoryRepository.cs
using Microsoft.EntityFrameworkCore;
using Webshop.Domain.Entities;
using Webshop.Domain.Interfaces;
using Webshop.Infrastructure.Data;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Webshop.Domain.Entities;
using Webshop.Domain.Interfaces;
using Webshop.Infrastructure.Data;
namespace Webshop.Infrastructure.Repositories
{
@@ -18,12 +18,41 @@ namespace Webshop.Infrastructure.Repositories
_context = context;
}
// Fügen Sie hier Repository-Methoden hinzu
// Beispiel:
// public async Task<IEnumerable<T>> GetAllAsync() { return await _context.Set<T>().ToListAsync(); }
// public async Task<T?> GetByIdAsync(Guid id) { return await _context.Set<T>().FindAsync(id); }
// public async Task AddAsync(T entity) { _context.Set<T>().Add(entity); await _context.SaveChangesAsync(); }
// public async Task UpdateAsync(T entity) { _context.Set<T>().Update(entity); await _context.SaveChangesAsync(); }
// public async Task DeleteAsync(Guid id) { var entity = await _context.Set<T>().FindAsync(id); if (entity != null) { _context.Set<T>().Remove(entity); await _context.SaveChangesAsync(); } }
public async Task<IEnumerable<Category>> GetAllAsync()
{
return await _context.Categories.ToListAsync();
}
public async Task<Category?> GetByIdAsync(Guid id)
{
return await _context.Categories.FindAsync(id);
}
public async Task<Category?> GetBySlugAsync(string slug)
{
return await _context.Categories.FirstOrDefaultAsync(c => c.Slug == slug);
}
public async Task AddAsync(Category category)
{
_context.Categories.Add(category);
await _context.SaveChangesAsync();
}
public async Task UpdateAsync(Category category)
{
_context.Categories.Update(category);
await _context.SaveChangesAsync();
}
public async Task DeleteAsync(Guid id)
{
var category = await _context.Categories.FindAsync(id);
if (category != null)
{
_context.Categories.Remove(category);
await _context.SaveChangesAsync();
}
}
}
}
}