все модели сделаны
This commit is contained in:
parent
636060a3e2
commit
0e159d5d0e
@ -35,14 +35,14 @@ public class CropDataModell(string id, string harvestId, string cropName, double
|
||||
throw new ValidationException("Field Id is empty");
|
||||
|
||||
if (!Id.IsGuid())
|
||||
throw new ValidationException("The value in the field Id is not a unique identifier");
|
||||
|
||||
throw new ValidationException("The value in the field Id is not a unique identifier");
|
||||
|
||||
if (HarvestId.IsEmpty())
|
||||
throw new ValidationException("Field HarvestId is empty");
|
||||
|
||||
if (!HarvestId.IsGuid())
|
||||
throw new ValidationException("The value in the field HarvestId is not a unique identifier");
|
||||
|
||||
throw new ValidationException("The value in the field HarvestId is not a unique identifier");
|
||||
|
||||
if (CropName.IsEmpty())
|
||||
throw new ValidationException("Field CropName is empty");
|
||||
|
||||
@ -50,6 +50,6 @@ public class CropDataModell(string id, string harvestId, string cropName, double
|
||||
throw new ValidationException("Field CropType is empty");
|
||||
|
||||
if (Price <= 0)
|
||||
throw new ValidationException("Field Price is less than or equal to 0");
|
||||
throw new ValidationException("Field Price is less than or equal to 0");
|
||||
}
|
||||
}
|
||||
}
|
@ -1,31 +0,0 @@
|
||||
using SeniorPomidorContracts.Extensions;
|
||||
using SeniorPomidorContracts.Infrastructure;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SeniorPomidorContracts.DataModels;
|
||||
|
||||
public class CropHistoryDataModell(string cropId, double oldPrice) : IValidation
|
||||
{
|
||||
public string CropId { get; private set; } = cropId;
|
||||
|
||||
public double OldPrice { get; private set; } = oldPrice;
|
||||
|
||||
public DateTime ChangeDate { get; private set; } = DateTime.UtcNow;
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
if (CropId.IsEmpty())
|
||||
throw new ValidationException("Field CropId is empty");
|
||||
|
||||
if (!CropId.IsGuid())
|
||||
throw new ValidationException("The value in the field CropId is not a unique identifier");
|
||||
|
||||
if (OldPrice <= 0)
|
||||
throw new ValidationException("Field OldPrice is less than or equal to 0");
|
||||
}
|
||||
}
|
@ -28,9 +28,12 @@ public class HarvestDataModel(string id, string harvestName
|
||||
throw new ValidationException("Field Id is empty");
|
||||
|
||||
if (Id.IsGuid())
|
||||
throw new ValidationException("\"The value in the field Id is not a unique identifier");
|
||||
throw new ValidationException("The value in the field Id is not a unique identifier");
|
||||
|
||||
if (HarvestName.IsEmpty())
|
||||
throw new ValidationException("Field HarvestName is empty");
|
||||
|
||||
if (HarvestAmount < 0)
|
||||
throw new ValidationException("Field HarvestAmount is less than 0");
|
||||
}
|
||||
}
|
||||
|
37
SeniorPomidorContracts/DataModels/SupplyCropDataModel.cs
Normal file
37
SeniorPomidorContracts/DataModels/SupplyCropDataModel.cs
Normal file
@ -0,0 +1,37 @@
|
||||
using SeniorPomidorContracts.Extensions;
|
||||
using SeniorPomidorContracts.Infrastructure;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SeniorPomidorContracts.DataModels;
|
||||
|
||||
public class SupplyCropDataModel(string supplyId, string cropId, int amount) : IValidation
|
||||
{
|
||||
public string SupplyId { get; private set; } = supplyId;
|
||||
|
||||
public string CropId { get; private set; } = cropId;
|
||||
|
||||
public int Amount { get; private set; } = amount;
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
if (SupplyId.IsEmpty())
|
||||
throw new ValidationException("Field SupplyId is empty");
|
||||
|
||||
if (!SupplyId.IsGuid())
|
||||
throw new ValidationException("The value in the field SupplyId is not a unique identifier");
|
||||
|
||||
if (CropId.IsEmpty())
|
||||
throw new ValidationException("Field CropId is empty");
|
||||
|
||||
if (!CropId.IsGuid())
|
||||
throw new ValidationException("The value in the field CropId is not a unique identifier");
|
||||
|
||||
if (Amount <= 0)
|
||||
throw new ValidationException("Field Amount is less than or equal to 0");
|
||||
}
|
||||
}
|
49
SeniorPomidorContracts/DataModels/SupplyDataModel.cs
Normal file
49
SeniorPomidorContracts/DataModels/SupplyDataModel.cs
Normal file
@ -0,0 +1,49 @@
|
||||
using SeniorPomidorContracts.Enums;
|
||||
using SeniorPomidorContracts.Extensions;
|
||||
using SeniorPomidorContracts.Infrastructure;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SeniorPomidorContracts.DataModels;
|
||||
|
||||
public class SupplyDataModel(string id, string supplierId, int sum, DateTime supplyDate,
|
||||
bool isCancel, List<SupplyCropDataModel> crops, DiscountType discountType, double discount) : IValidation
|
||||
{
|
||||
public string Id { get; private set; } = id;
|
||||
|
||||
public string? SupplierId { get; private set; } = supplierId;
|
||||
|
||||
public int Sum { get; private set; } = sum;
|
||||
|
||||
public DateTime SupplyDate { get; private set; } = supplyDate;
|
||||
|
||||
public List<SupplyCropDataModel> Crops { get; private set; } = crops;
|
||||
|
||||
public DiscountType DiscountType { get; private set; } = discountType;
|
||||
|
||||
public double Discount { get; private set; } = discount;
|
||||
|
||||
public bool IsCancel { get; private set; } = isCancel;
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
if (Id.IsEmpty())
|
||||
throw new ValidationException("Field Id is empty");
|
||||
|
||||
if (!Id.IsGuid())
|
||||
throw new ValidationException("The value in the field Id is not a unique identifier");
|
||||
|
||||
if (!SupplierId?.IsGuid() ?? !SupplierId?.IsEmpty() ?? false)
|
||||
throw new ValidationException("The value in the field SupplierId is not a unique identifier");
|
||||
|
||||
if (Sum <= 0)
|
||||
throw new ValidationException("Field Sum is less than or equal to 0");
|
||||
|
||||
if ((Crops?.Count ?? 0) == 0)
|
||||
throw new ValidationException("The sale must include products");
|
||||
}
|
||||
}
|
28
SeniorPomidorContracts/DataModels/SupplyHistoryDataModel.cs
Normal file
28
SeniorPomidorContracts/DataModels/SupplyHistoryDataModel.cs
Normal file
@ -0,0 +1,28 @@
|
||||
using SeniorPomidorContracts.Extensions;
|
||||
using SeniorPomidorContracts.Infrastructure;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SeniorPomidorContracts.DataModels;
|
||||
|
||||
public class SupplyHistoryDataModell(string id, string SupplyId) : IValidation
|
||||
{
|
||||
public string Id { get; set; } = id;
|
||||
|
||||
public string SupplyId { get; private set; } = SupplyId;
|
||||
|
||||
public DateTime SupplyDate { get; private set; } = DateTime.UtcNow;
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
if (SupplyId.IsEmpty())
|
||||
throw new ValidationException("Field SupplyId is empty");
|
||||
|
||||
if (!SupplyId.IsGuid())
|
||||
throw new ValidationException("The value in the field SupplyId is not a unique identifier");
|
||||
}
|
||||
}
|
15
SeniorPomidorContracts/Enums/DiscountType.cs
Normal file
15
SeniorPomidorContracts/Enums/DiscountType.cs
Normal file
@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SeniorPomidorContracts.Enums;
|
||||
[Flags]
|
||||
public enum DiscountType
|
||||
{
|
||||
None = 0,
|
||||
OnSale = 1,
|
||||
RegularSupplier = 2,
|
||||
Certificate = 4
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user