discount und summary
This commit is contained in:
@@ -1,24 +1,86 @@
|
||||
// Auto-generiert von CreateWebshopFiles.ps1
|
||||
// src/Webshop.Application/DTOs/Discounts/DiscountDto.cs
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
||||
using Webshop.Domain.Enums;
|
||||
|
||||
namespace Webshop.Application.DTOs.Discounts
|
||||
{
|
||||
/// <summary>
|
||||
/// Repr<70>sentiert einen Rabatt mit all seinen Konfigurationen und Zuweisungen.
|
||||
/// </summary>
|
||||
public class DiscountDto
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Der Name des Rabatts (z.B. "Sommerschlussverkauf", "10% auf alles").
|
||||
/// </summary>
|
||||
public string Name { get; set; } = string.Empty;
|
||||
public DiscountType Type { get; set; }
|
||||
public decimal Value { get; set; }
|
||||
public string? CouponCode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Der Typ des Rabatts. 'Percentage' f<>r prozentuale Rabatte, 'FixedAmount' f<>r feste Betr<74>ge.
|
||||
/// </summary>
|
||||
public DiscountType DiscountType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Der Wert des Rabatts. Bei 'Percentage' z.B. 10 f<>r 10%. Bei 'FixedAmount' z.B. 5 f<>r 5,00<30>.
|
||||
/// </summary>
|
||||
public decimal DiscountValue { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Das Datum, an dem der Rabatt aktiv wird.
|
||||
/// </summary>
|
||||
public DateTimeOffset StartDate { get; set; }
|
||||
public DateTimeOffset EndDate { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Optionales Enddatum. Wenn null, ist der Rabatt unbegrenzt g<>ltig.
|
||||
/// </summary>
|
||||
public DateTimeOffset? EndDate { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gibt an, ob der Rabatt derzeit aktiv ist und angewendet werden kann.
|
||||
/// </summary>
|
||||
public bool IsActive { get; set; }
|
||||
public int? MaxUses { get; set; }
|
||||
public int CurrentUses { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Wenn 'true', muss ein Gutscheincode eingegeben werden, um den Rabatt zu erhalten.
|
||||
/// </summary>
|
||||
public bool RequiresCouponCode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Der Gutscheincode, der eingegeben werden muss (z.B. "SUMMER2025"). Muss eindeutig sein.
|
||||
/// </summary>
|
||||
public string? CouponCode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Der Mindestbestellwert, der erreicht werden muss, damit der Rabatt angewendet wird.
|
||||
/// </summary>
|
||||
public decimal? MinimumOrderAmount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Die maximale Anzahl, wie oft dieser Rabatt insgesamt eingel<65>st werden kann.
|
||||
/// </summary>
|
||||
public int? MaximumUsageCount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Die aktuelle Anzahl der Einl<6E>sungen. Wird vom System verwaltet.
|
||||
/// </summary>
|
||||
public int CurrentUsageCount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Eine interne Beschreibung f<>r den Admin.
|
||||
/// </summary>
|
||||
public string? Description { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Eine Liste von Produkt-IDs, auf die dieser Rabatt exklusiv angewendet wird.
|
||||
/// Wenn leer, gilt der Rabatt f<>r alle Produkte (sofern keine Kategorien zugewiesen sind).
|
||||
/// </summary>
|
||||
public List<Guid> AssignedProductIds { get; set; } = new List<Guid>();
|
||||
|
||||
/// <summary>
|
||||
/// Eine Liste von Kategorie-IDs. Der Rabatt wird auf alle Produkte in diesen Kategorien angewendet.
|
||||
/// </summary>
|
||||
public List<Guid> AssignedCategoryIds { get; set; } = new List<Guid>();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,46 +1,88 @@
|
||||
// src/Webshop.Application/DTOs/Admin/AdminShopInfoDto.cs
|
||||
// src/Webshop.Application/DTOs/Shop/AdminShopInfoDto.cs
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Webshop.Application.DTOs.Shop
|
||||
{
|
||||
/// <summary>
|
||||
/// Repräsentiert alle zentralen Stammdaten des Shops für die administrative Verwaltung.
|
||||
/// </summary>
|
||||
public class AdminShopInfoDto
|
||||
{
|
||||
/// <summary>
|
||||
/// Der offizielle Name des Webshops.
|
||||
/// </summary>
|
||||
[Required, MaxLength(255)]
|
||||
public string ShopName { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Ein kurzer Marketing-Slogan, der auf der Startseite angezeigt werden kann.
|
||||
/// </summary>
|
||||
[MaxLength(500)]
|
||||
public string? Slogan { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Die primäre Kontakt-E-Mail-Adresse für Kundenanfragen.
|
||||
/// </summary>
|
||||
[Required, EmailAddress, MaxLength(255)]
|
||||
public string ContactEmail { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Die offizielle Telefonnummer des Shops.
|
||||
/// </summary>
|
||||
[Phone, MaxLength(50)]
|
||||
public string? PhoneNumber { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Straße und Hausnummer der Firmenadresse.
|
||||
/// </summary>
|
||||
[MaxLength(255)]
|
||||
public string? Street { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Stadt der Firmenadresse.
|
||||
/// </summary>
|
||||
[MaxLength(100)]
|
||||
public string? City { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Postleitzahl der Firmenadresse.
|
||||
/// </summary>
|
||||
[MaxLength(20)]
|
||||
public string? PostalCode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Land der Firmenadresse.
|
||||
/// </summary>
|
||||
[MaxLength(100)]
|
||||
public string? Country { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Die Umsatzsteuer-Identifikationsnummer des Unternehmens.
|
||||
/// </summary>
|
||||
[MaxLength(50)]
|
||||
public string? VatNumber { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Die Handelsregisternummer des Unternehmens.
|
||||
/// </summary>
|
||||
[MaxLength(100)]
|
||||
public string? CompanyRegistrationNumber { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Die URL zur offiziellen Facebook-Seite.
|
||||
/// </summary>
|
||||
[Url, MaxLength(255)]
|
||||
public string? FacebookUrl { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Die URL zum offiziellen Instagram-Profil.
|
||||
/// </summary>
|
||||
[Url, MaxLength(255)]
|
||||
public string? InstagramUrl { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Die URL zum offiziellen Twitter/X-Profil.
|
||||
/// </summary>
|
||||
[Url, MaxLength(255)]
|
||||
public string? TwitterUrl { get; set; }
|
||||
}
|
||||
|
||||
@@ -1,19 +1,64 @@
|
||||
// src/Webshop.Application/DTOs/Shop/PublicShopInfoDto.cs
|
||||
namespace Webshop.Application.DTOs.Shop
|
||||
{
|
||||
// Dieses DTO enthält nur die Informationen, die ein normaler Kunde sehen soll.
|
||||
/// <summary>
|
||||
/// Enthält die öffentlichen Stammdaten des Shops, die für Kunden sichtbar sind (z.B. im Footer oder auf der Kontaktseite).
|
||||
/// </summary>
|
||||
public class PublicShopInfoDto
|
||||
{
|
||||
/// <summary>
|
||||
/// Der offizielle Name des Webshops.
|
||||
/// </summary>
|
||||
public string ShopName { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Ein kurzer Marketing-Slogan.
|
||||
/// </summary>
|
||||
public string? Slogan { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Die primäre Kontakt-E-Mail-Adresse.
|
||||
/// </summary>
|
||||
public string ContactEmail { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Die offizielle Telefonnummer.
|
||||
/// </summary>
|
||||
public string? PhoneNumber { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Straße und Hausnummer.
|
||||
/// </summary>
|
||||
public string? Street { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Stadt.
|
||||
/// </summary>
|
||||
public string? City { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Postleitzahl.
|
||||
/// </summary>
|
||||
public string? PostalCode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Land.
|
||||
/// </summary>
|
||||
public string? Country { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// URL zur Facebook-Seite.
|
||||
/// </summary>
|
||||
public string? FacebookUrl { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// URL zum Instagram-Profil.
|
||||
/// </summary>
|
||||
public string? InstagramUrl { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// URL zum Twitter/X-Profil.
|
||||
/// </summary>
|
||||
public string? TwitterUrl { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,18 +1,134 @@
|
||||
// Auto-generiert von CreateWebshopFiles.ps1
|
||||
// src/Webshop.Application/Services/Admin/AdminDiscountService.cs
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Webshop.Application.DTOs.Discounts;
|
||||
using Webshop.Application.Services.Admin.Interfaces;
|
||||
|
||||
using Webshop.Domain.Entities;
|
||||
using Webshop.Domain.Enums;
|
||||
using Webshop.Domain.Interfaces;
|
||||
|
||||
namespace Webshop.Application.Services.Admin
|
||||
{
|
||||
public class AdminDiscountService : IAdminDiscountService
|
||||
{
|
||||
// Fügen Sie hier Abhängigkeiten per Dependency Injection hinzu (z.B. Repositories)
|
||||
private readonly IDiscountRepository _discountRepository;
|
||||
|
||||
// public AdminDiscountService(IYourRepository repository) { }
|
||||
public AdminDiscountService(IDiscountRepository discountRepository)
|
||||
{
|
||||
_discountRepository = discountRepository;
|
||||
}
|
||||
|
||||
// Fügen Sie hier Service-Methoden hinzu
|
||||
public async Task<IEnumerable<DiscountDto>> GetAllDiscountsAsync()
|
||||
{
|
||||
var discounts = await _discountRepository.GetAllAsync();
|
||||
return discounts.Select(MapToDto).ToList();
|
||||
}
|
||||
|
||||
public async Task<DiscountDto?> GetDiscountByIdAsync(Guid id)
|
||||
{
|
||||
var discount = await _discountRepository.GetByIdAsync(id);
|
||||
return discount != null ? MapToDto(discount) : null;
|
||||
}
|
||||
|
||||
public async Task<DiscountDto?> CreateDiscountAsync(DiscountDto discountDto)
|
||||
{
|
||||
var discount = MapToEntity(discountDto);
|
||||
discount.Id = Guid.NewGuid();
|
||||
|
||||
await _discountRepository.AddAsync(discount);
|
||||
return MapToDto(discount);
|
||||
}
|
||||
|
||||
public async Task<bool> UpdateDiscountAsync(DiscountDto discountDto)
|
||||
{
|
||||
var existingDiscount = await _discountRepository.GetByIdAsync(discountDto.Id);
|
||||
if (existingDiscount == null) return false;
|
||||
|
||||
// Update simple properties
|
||||
existingDiscount.Name = discountDto.Name;
|
||||
existingDiscount.Description = discountDto.Description;
|
||||
existingDiscount.DiscountType = discountDto.DiscountType.ToString();
|
||||
existingDiscount.DiscountValue = discountDto.DiscountValue;
|
||||
existingDiscount.StartDate = discountDto.StartDate;
|
||||
existingDiscount.EndDate = discountDto.EndDate;
|
||||
existingDiscount.IsActive = discountDto.IsActive;
|
||||
existingDiscount.RequiresCouponCode = discountDto.RequiresCouponCode;
|
||||
existingDiscount.CouponCode = discountDto.CouponCode;
|
||||
existingDiscount.MinimumOrderAmount = discountDto.MinimumOrderAmount;
|
||||
existingDiscount.MaximumUsageCount = discountDto.MaximumUsageCount;
|
||||
|
||||
// Sync assigned products
|
||||
existingDiscount.ProductDiscounts.Clear();
|
||||
foreach (var productId in discountDto.AssignedProductIds)
|
||||
{
|
||||
existingDiscount.ProductDiscounts.Add(new ProductDiscount { ProductId = productId });
|
||||
}
|
||||
|
||||
// Sync assigned categories
|
||||
existingDiscount.categorieDiscounts.Clear();
|
||||
foreach (var categoryId in discountDto.AssignedCategoryIds)
|
||||
{
|
||||
existingDiscount.categorieDiscounts.Add(new CategorieDiscount { categorieId = categoryId });
|
||||
}
|
||||
|
||||
await _discountRepository.UpdateAsync(existingDiscount);
|
||||
return true;
|
||||
}
|
||||
|
||||
public async Task<bool> DeleteDiscountAsync(Guid id)
|
||||
{
|
||||
var discount = await _discountRepository.GetByIdAsync(id);
|
||||
if (discount == null) return false;
|
||||
|
||||
await _discountRepository.DeleteAsync(id);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Helper methods for mapping
|
||||
private DiscountDto MapToDto(Discount discount)
|
||||
{
|
||||
return new DiscountDto
|
||||
{
|
||||
Id = discount.Id,
|
||||
Name = discount.Name,
|
||||
Description = discount.Description,
|
||||
DiscountType = Enum.Parse<DiscountType>(discount.DiscountType),
|
||||
DiscountValue = discount.DiscountValue,
|
||||
StartDate = discount.StartDate,
|
||||
EndDate = discount.EndDate,
|
||||
IsActive = discount.IsActive,
|
||||
RequiresCouponCode = discount.RequiresCouponCode,
|
||||
CouponCode = discount.CouponCode,
|
||||
MinimumOrderAmount = discount.MinimumOrderAmount,
|
||||
MaximumUsageCount = discount.MaximumUsageCount,
|
||||
CurrentUsageCount = discount.CurrentUsageCount,
|
||||
AssignedProductIds = discount.ProductDiscounts.Select(pd => pd.ProductId).ToList(),
|
||||
AssignedCategoryIds = discount.categorieDiscounts.Select(cd => cd.categorieId).ToList()
|
||||
};
|
||||
}
|
||||
|
||||
private Discount MapToEntity(DiscountDto dto)
|
||||
{
|
||||
return new Discount
|
||||
{
|
||||
Id = dto.Id,
|
||||
Name = dto.Name,
|
||||
Description = dto.Description,
|
||||
DiscountType = dto.DiscountType.ToString(),
|
||||
DiscountValue = dto.DiscountValue,
|
||||
StartDate = dto.StartDate,
|
||||
EndDate = dto.EndDate,
|
||||
IsActive = dto.IsActive,
|
||||
RequiresCouponCode = dto.RequiresCouponCode,
|
||||
CouponCode = dto.CouponCode,
|
||||
MinimumOrderAmount = dto.MinimumOrderAmount,
|
||||
MaximumUsageCount = dto.MaximumUsageCount,
|
||||
CurrentUsageCount = dto.CurrentUsageCount,
|
||||
ProductDiscounts = dto.AssignedProductIds.Select(pid => new ProductDiscount { ProductId = pid }).ToList(),
|
||||
categorieDiscounts = dto.AssignedCategoryIds.Select(cid => new CategorieDiscount { categorieId = cid }).ToList()
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,16 +1,17 @@
|
||||
// Auto-generiert von CreateWebshopFiles.ps1
|
||||
// src/Webshop.Application/Services/Admin/Interfaces/IAdminDiscountService.cs
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Webshop.Application.DTOs;
|
||||
using Webshop.Application.DTOs.Auth;
|
||||
using Webshop.Application.DTOs.Users;
|
||||
|
||||
using Webshop.Application.DTOs.Discounts;
|
||||
|
||||
namespace Webshop.Application.Services.Admin.Interfaces
|
||||
{
|
||||
public interface IAdminDiscountService
|
||||
{
|
||||
// Fügen Sie hier Methodensignaturen hinzu
|
||||
Task<IEnumerable<DiscountDto>> GetAllDiscountsAsync();
|
||||
Task<DiscountDto?> GetDiscountByIdAsync(Guid id);
|
||||
Task<DiscountDto?> CreateDiscountAsync(DiscountDto discountDto);
|
||||
Task<bool> UpdateDiscountAsync(DiscountDto discountDto);
|
||||
Task<bool> DeleteDiscountAsync(Guid id);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user