45 lines
1.9 KiB
C#
Raw Normal View History

2025-02-12 22:16:56 +04:00
using System;
2025-02-13 16:13:21 +04:00
using CandyHouseBase.Enums;
2025-02-12 22:16:56 +04:00
using CandyHouseBase.Exceptions;
using CandyHouseBase.Extensions;
using CandyHouseBase.Infrastructure;
namespace CandyHouseBase.DataModels
{
public class OrderDataModel : IValidation
{
public string Id { get; private set; }
2025-02-13 16:13:21 +04:00
public string CustomerName { get; private set; } // Может быть null, если клиент разовый
2025-02-12 22:16:56 +04:00
public DateTime OrderDate { get; private set; }
public decimal TotalAmount { get; private set; }
public decimal DiscountAmount { get; private set; }
2025-02-26 23:49:16 +04:00
public string ProductId { get; private set; }
2025-02-13 16:13:21 +04:00
public string PekarId { get; private set; }
public StatusType StatusType { get; private set; }
2025-02-12 22:16:56 +04:00
2025-02-13 16:13:21 +04:00
public OrderDataModel(string id, string customerName, DateTime orderDate, decimal totalAmount,
2025-02-26 23:49:16 +04:00
decimal discountAmount, string productId, string pekarId, StatusType statusType)
2025-02-12 22:16:56 +04:00
{
Id = id;
2025-02-13 16:13:21 +04:00
CustomerName = customerName;
2025-02-12 22:16:56 +04:00
OrderDate = orderDate;
TotalAmount = totalAmount;
DiscountAmount = discountAmount;
2025-02-26 23:49:16 +04:00
ProductId = productId;
2025-02-13 16:13:21 +04:00
PekarId = pekarId;
StatusType = statusType;
2025-02-12 22:16:56 +04:00
}
public void Validate()
{
if (Id.IsEmpty()) throw new ValidationException("Field Id is empty");
if (!Id.IsGuid()) throw new ValidationException("Id must be a GUID");
2025-02-13 16:13:21 +04:00
if (CustomerName.IsEmpty())
throw new ValidationException("CustomerName is empty");
2025-02-12 22:16:56 +04:00
if (TotalAmount < 0) throw new ValidationException("TotalAmount cannot be negative");
if (DiscountAmount < 0) throw new ValidationException("DiscountAmount cannot be negative");
2025-02-26 23:49:16 +04:00
if (ProductId.IsEmpty()) throw new ValidationException("Field productId is empty");
if (!ProductId.IsGuid()) throw new ValidationException("productId must be a GUID");
2025-02-12 22:16:56 +04:00
}
}
}