discount und summary

This commit is contained in:
Tizian.Breuch
2025-08-12 11:52:50 +02:00
parent d5742b27e8
commit b9f1b3fb7a
12 changed files with 481 additions and 44 deletions

View File

@@ -145,6 +145,32 @@ namespace Webshop.Infrastructure.Data
.HasOne(a => a.Customer) // Ein ApplicationUser hat ein optionales Customer-Profil
.WithOne(c => c.User) // Ein Customer-Profil ist mit genau einem User verknüpft
.HasForeignKey<Customer>(c => c.AspNetUserId);
modelBuilder.Entity<ProductDiscount>(entity =>
{
entity.HasOne(pd => pd.Product)
.WithMany(p => p.ProductDiscounts)
.HasForeignKey(pd => pd.ProductId);
entity.HasOne(pd => pd.Discount)
.WithMany(d => d.ProductDiscounts)
.HasForeignKey(pd => pd.DiscountId);
});
// << NEU: Beziehungskonfiguration für CategorieDiscount >>
modelBuilder.Entity<CategorieDiscount>(entity =>
{
entity.HasOne(cd => cd.categorie)
.WithMany(c => c.categorieDiscounts)
.HasForeignKey(cd => cd.categorieId);
entity.HasOne(cd => cd.Discount)
.WithMany(d => d.categorieDiscounts)
.HasForeignKey(cd => cd.DiscountId);
});
}
}
}

View File

@@ -1,4 +1,4 @@
// Auto-generiert von CreateWebshopFiles.ps1
// src/Webshop.Infrastructure/Repositories/DiscountRepository.cs
using Microsoft.EntityFrameworkCore;
using Webshop.Domain.Entities;
using Webshop.Domain.Interfaces;
@@ -18,12 +18,43 @@ 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<Discount>> GetAllAsync()
{
return await _context.Discounts
.Include(d => d.ProductDiscounts)
.Include(d => d.categorieDiscounts)
.OrderBy(d => d.Name)
.ToListAsync();
}
public async Task<Discount?> GetByIdAsync(Guid id)
{
return await _context.Discounts
.Include(d => d.ProductDiscounts)
.Include(d => d.categorieDiscounts)
.FirstOrDefaultAsync(d => d.Id == id);
}
public async Task AddAsync(Discount discount)
{
await _context.Discounts.AddAsync(discount);
await _context.SaveChangesAsync();
}
public async Task UpdateAsync(Discount discount)
{
_context.Discounts.Update(discount);
await _context.SaveChangesAsync();
}
public async Task DeleteAsync(Guid id)
{
var discount = await _context.Discounts.FindAsync(id);
if (discount != null)
{
_context.Discounts.Remove(discount);
await _context.SaveChangesAsync();
}
}
}
}
}