46 lines
1.9 KiB
C#
Raw Normal View History

2025-02-12 22:16:56 +04:00
using System;
using System.Collections.Generic;
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-13 16:13:21 +04:00
public string OrderId { get; private set; }
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,
decimal discountAmount, string orderId, 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-13 16:13:21 +04:00
OrderId = orderId;
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-13 16:13:21 +04:00
if (OrderId.IsEmpty()) throw new ValidationException("Field OrderId is empty");
if (!OrderId.IsGuid()) throw new ValidationException("OrderId must be a GUID");
2025-02-12 22:16:56 +04:00
}
}
}