// src/Webshop.Domain/Entities/Product.cs using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; namespace Webshop.Domain.Entities { public class Product { [Key] public Guid Id { get; set; } = Guid.NewGuid(); [Required, MaxLength(255)] public string Name { get; set; } = string.Empty; [MaxLength(4000)] public string? Description { get; set; } [MaxLength(500)] public string SKU { get; set; } = string.Empty; [Required] public decimal Price { get; set; } public decimal? OldPrice { get; set; } [Required] public bool IsActive { get; set; } [Required] public bool IsInStock { get; set; } [Required] public int StockQuantity { get; set; } public decimal? Weight { get; set; } [Required, MaxLength(255)] public string Slug { get; set; } = string.Empty; [Required] public DateTimeOffset CreatedDate { get; set; } = DateTimeOffset.UtcNow; public DateTimeOffset? LastModifiedDate { get; set; } [ForeignKey(nameof(Supplier))] public Guid? SupplierId { get; set; } public decimal? PurchasePrice { get; set; } // << NEUE EIGENSCHAFTEN FÜR SONDERANGEBOTE >> public bool IsFeatured { get; set; } = false; public int FeaturedDisplayOrder { get; set; } = 0; // << ENDE NEUE EIGENSCHAFTEN >> public virtual Supplier? Supplier { get; set; } public virtual ICollection Variants { get; set; } = new List(); public virtual ICollection Reviews { get; set; } = new List(); public virtual ICollection ProductDiscounts { get; set; } = new List(); public virtual ICollection Productcategories { get; set; } = new List(); public virtual ICollection Images { get; set; } = new List(); // --- HINZUGEFÜGTE METHODE ZUR AKTUALISIERUNG --- // Diese Methode kapselt die Logik zur Aktualisierung der Entität aus einem DTO. // Sie stellt sicher, dass alle relevanten Felder konsistent geändert werden. public void UpdateFromDto( string name, string? description, string sku, decimal price, decimal? oldPrice, bool isActive, int stockQuantity, string slug, decimal? weight, Guid? supplierId, decimal? purchasePrice, bool isFeatured, int featuredDisplayOrder, List categorieIds) { // 1. Einfache Eigenschaften aktualisieren Name = name; Description = description; SKU = sku; Price = price; OldPrice = oldPrice; IsActive = isActive; StockQuantity = stockQuantity; IsInStock = stockQuantity > 0; // Abgeleitete Logik Slug = slug; Weight = weight; SupplierId = supplierId; PurchasePrice = purchasePrice; IsFeatured = isFeatured; FeaturedDisplayOrder = featuredDisplayOrder; LastModifiedDate = DateTimeOffset.UtcNow; // 2. Kategori-Beziehungen sauber neu aufbauen Productcategories.Clear(); if (categorieIds != null) { foreach (var catId in categorieIds) { Productcategories.Add(new Productcategorie { categorieId = catId }); } } } } }