beb
This commit is contained in:
parent
630bca6520
commit
9373ecbada
@ -3,10 +3,51 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using SweetBunsContracts.Extensions;
|
||||
using SweetBunsContracts.Infrastructure;
|
||||
using SweetBunsContracts.Exceptions;
|
||||
|
||||
namespace SweetBunsContracts.DataModels
|
||||
namespace SweetBunsContracts.DataModels;
|
||||
|
||||
public class EmployeeDataModel(string id, string fio, string postId, string previousPostId, DateTime birthDate, DateTime employmentDate, bool isDeleted) : IValidation
|
||||
{
|
||||
internal class EmployeeDataModel
|
||||
public string Id { get; private set; } = id;
|
||||
|
||||
public string FIO { get; private set; } = fio;
|
||||
|
||||
public string PostId { get; private set; } = postId;
|
||||
public string PreviousPostId { get; private set; } = previousPostId;
|
||||
|
||||
public DateTime BirthDate { get; private set; } = birthDate;
|
||||
|
||||
public DateTime EmploymentDate { get; private set; } = employmentDate;
|
||||
|
||||
public bool IsDeleted { get; private set; } = isDeleted;
|
||||
|
||||
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 (FIO.IsEmpty())
|
||||
throw new ValidationException("Field FIO is empty");
|
||||
|
||||
if (PostId.IsEmpty())
|
||||
throw new ValidationException("Field PostId is empty");
|
||||
|
||||
if (!PostId.IsGuid())
|
||||
throw new ValidationException("The value in the field PostId is not a unique identifier");
|
||||
|
||||
if (BirthDate.Date > DateTime.Now.AddYears(-16).Date)
|
||||
throw new ValidationException($"Minors cannot be hired (BirthDate = {BirthDate.ToShortDateString()})");
|
||||
|
||||
if (EmploymentDate.Date < BirthDate.Date)
|
||||
throw new ValidationException("The date of employment cannot be less than the date of birth");
|
||||
|
||||
if ((EmploymentDate - BirthDate).TotalDays / 365 < 16)
|
||||
throw new ValidationException($"Minors cannot be hired (EmploymentDate - {EmploymentDate.ToShortDateString()}, BirthDate - {BirthDate.ToShortDateString()})");
|
||||
}
|
||||
}
|
||||
|
@ -3,10 +3,25 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using SweetBunsContracts.Extensions;
|
||||
using SweetBunsContracts.Infrastructure;
|
||||
using SweetBunsContracts.Exceptions;
|
||||
|
||||
namespace SweetBunsContracts.DataModels
|
||||
namespace SweetBunsContracts.DataModels;
|
||||
|
||||
public class IngredientDataModel(string id, string name) : IValidation
|
||||
{
|
||||
internal class IngredientDataModel
|
||||
public string Id { get; private set; } = id;
|
||||
public string Name { get; private set; } = name;
|
||||
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 (Name.IsEmpty())
|
||||
throw new ValidationException("Field FIO is empty");
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ using SweetBunsContracts.Infrastructure;
|
||||
|
||||
namespace SweetBunsContracts.DataModels;
|
||||
|
||||
public class ProductDataModel(string id, string productName, ProductType productType, double price, bool isDeleted) : IValidation
|
||||
public class ProductDataModel(string id, string productName, ProductType productType, double price, bool isDeleted, List<ProductIngridientDataModel> ingredients) : IValidation
|
||||
{
|
||||
public string Id { get; private set; } = id;
|
||||
|
||||
@ -21,6 +21,7 @@ public class ProductDataModel(string id, string productName, ProductType product
|
||||
public double Price { get; private set; } = price;
|
||||
|
||||
public bool IsDeleted { get; private set; } = isDeleted;
|
||||
public List<ProductIngridientDataModel> Ingredients { get; private set; } = ingredients;-
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
|
@ -3,10 +3,33 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Linq;
|
||||
using SweetBunsContracts.Extensions;
|
||||
using SweetBunsContracts.Infrastructure;
|
||||
using SweetBunsContracts.Exceptions;
|
||||
|
||||
namespace SweetBunsContracts.DataModels
|
||||
namespace SweetBunsContracts.DataModels;
|
||||
|
||||
public class ProductIngridientDataModel(string ingredientId, string productId) : IValidation
|
||||
{
|
||||
internal class ProductIngridientDataModel
|
||||
public string IngredientId { get; private set; } = ingredientId;
|
||||
|
||||
public string ProductId { get; private set; } = productId;
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
if (IngredientId.IsEmpty())
|
||||
throw new ValidationException("Field IngredientId is empty");
|
||||
|
||||
if (!IngredientId.IsGuid())
|
||||
throw new ValidationException("The value in the field IngredientId is not a unique identifier");
|
||||
|
||||
if (ProductId.IsEmpty())
|
||||
throw new ValidationException("Field ProductId is empty");
|
||||
|
||||
if (!ProductId.IsGuid())
|
||||
throw new ValidationException("The value in the field ProductId is not a unique identifier");
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -3,10 +3,38 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using SweetBunsContracts.Extensions;
|
||||
using SweetBunsContracts.Infrastructure;
|
||||
using SweetBunsContracts.Exceptions;
|
||||
|
||||
namespace SweetBunsContracts.DataModels
|
||||
namespace SweetBunsContracts.DataModels;
|
||||
|
||||
public class SaleDataModel(string id, string employeeId, double sum, bool isCanceled) : IValidation
|
||||
{
|
||||
internal class SaleDataModel
|
||||
public string Id { get; private set; } = id;
|
||||
|
||||
public string EmployeeId { get; private set; } = employeeId;
|
||||
|
||||
public DateTime SaleDate { get; private set; } = DateTime.UtcNow;
|
||||
|
||||
public double Sum { get; private set; } = sum;
|
||||
public bool IsCanceled { get; private set; } = isCanceled;
|
||||
|
||||
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 (EmployeeId.IsEmpty())
|
||||
throw new ValidationException("Field EmployeeId is empty");
|
||||
|
||||
if (!EmployeeId.IsGuid())
|
||||
throw new ValidationException("The value in the field EmployeeId is not a unique identifier");
|
||||
|
||||
if (Sum <= 0)
|
||||
throw new ValidationException("Field Sum is less than or equal to 0");
|
||||
}
|
||||
}
|
||||
|
@ -9,8 +9,7 @@ namespace SweetBunsContracts.Enums;
|
||||
public enum PostType
|
||||
{
|
||||
None = 0,
|
||||
Confectioner = 1,
|
||||
Baker = 2,
|
||||
KitchenHelper = 3,
|
||||
Salesman = 4
|
||||
Basics = 1,
|
||||
Producer = 2,
|
||||
Packer = 3
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user