review
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
// Auto-generiert von CreateWebshopFiles.ps1
|
||||
// src/Webshop.Infrastructure/Repositories/ReviewRepository.cs
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Webshop.Domain.Entities;
|
||||
using Webshop.Domain.Interfaces;
|
||||
using Webshop.Infrastructure.Data;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Webshop.Infrastructure.Repositories
|
||||
{
|
||||
@@ -18,12 +19,49 @@ 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<Review>> GetAllAsync()
|
||||
{
|
||||
return await _context.Reviews
|
||||
.Include(r => r.Customer)
|
||||
.Include(r => r.Product)
|
||||
.OrderByDescending(r => r.ReviewDate)
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<Review>> GetApprovedByProductIdAsync(Guid productId)
|
||||
{
|
||||
return await _context.Reviews
|
||||
.Include(r => r.Customer)
|
||||
.Where(r => r.ProductId == productId && r.IsApproved)
|
||||
.OrderByDescending(r => r.ReviewDate)
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<Review?> GetByIdAsync(Guid id)
|
||||
{
|
||||
return await _context.Reviews.FindAsync(id);
|
||||
}
|
||||
|
||||
public async Task AddAsync(Review review)
|
||||
{
|
||||
await _context.Reviews.AddAsync(review);
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
|
||||
public async Task UpdateAsync(Review review)
|
||||
{
|
||||
_context.Reviews.Update(review);
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
|
||||
public async Task DeleteAsync(Guid id)
|
||||
{
|
||||
var review = await _context.Reviews.FindAsync(id);
|
||||
if (review != null)
|
||||
{
|
||||
_context.Reviews.Remove(review);
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user