using System.Collections; using System.ComponentModel; namespace GasStation.Entities; public class Selling { public int Id { get; private set; } [Browsable(false)] public int GasmanId { get; private set; } [DisplayName("Имя заправщика")] public string GasmanName { get; private set; } = string.Empty; [DisplayName("Товары")] public string Product => ProdutcSellings != null ? string.Join(", ", ProdutcSellings.Select(x => $"{x.ProductName} {x.Count}")) : string.Empty; [Browsable(false)] public IEnumerable ProdutcSellings { get; private set; } = []; [DisplayName("Дата продажи")] public DateTime SellingDateTime { get; private set; } public static Selling CreateSelling(int id, int gasmanId, IEnumerable produtcSellings) { return new Selling { Id = id, GasmanId = gasmanId, SellingDateTime = DateTime.Now, ProdutcSellings = produtcSellings }; } public void SetProductSelling(IEnumerable produtcSellings) { if (produtcSellings != null && produtcSellings.Any()) { ProdutcSellings = produtcSellings; } } }