Compare commits
2 Commits
main
...
Task_1_Mod
Author | SHA1 | Date | |
---|---|---|---|
630bca6520 | |||
f88a108f27 |
@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SweetBunsContracts.DataModels
|
||||
{
|
||||
internal class EmployeeDataModel
|
||||
{
|
||||
}
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SweetBunsContracts.DataModels
|
||||
{
|
||||
internal class IngredientDataModel
|
||||
{
|
||||
}
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using SweetBunsContracts.Enums;
|
||||
using SweetBunsContracts.Exceptions;
|
||||
using SweetBunsContracts.Extensions;
|
||||
using SweetBunsContracts.Infrastructure;
|
||||
|
||||
namespace SweetBunsContracts.DataModels;
|
||||
|
||||
public class PostDataModel(string id, string postId, string postName, PostType postType, double salary, bool isActual, DateTime changeDate) : IValidation
|
||||
{
|
||||
public string Id { get; private set; } = id;
|
||||
|
||||
public string PostId { get; private set; } = postId;
|
||||
|
||||
public string PostName { get; private set; } = postName;
|
||||
|
||||
public PostType PostType { get; private set; } = postType;
|
||||
|
||||
public double Salary { get; private set; } = salary;
|
||||
|
||||
public bool IsActual { get; private set; } = isActual;
|
||||
|
||||
public DateTime ChangeDate { get; private set; } = changeDate;
|
||||
|
||||
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 (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 (PostName.IsEmpty())
|
||||
throw new ValidationException("Field PostName is empty");
|
||||
|
||||
if (PostType == PostType.None)
|
||||
throw new ValidationException("Field PostType is empty");
|
||||
|
||||
if (Salary <= 0)
|
||||
throw new ValidationException("Field Salary is empty");
|
||||
}
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using SweetBunsContracts.Enums;
|
||||
using SweetBunsContracts.Exceptions;
|
||||
using SweetBunsContracts.Extensions;
|
||||
using SweetBunsContracts.Infrastructure;
|
||||
|
||||
namespace SweetBunsContracts.DataModels;
|
||||
|
||||
public class ProductDataModel(string id, string productName, ProductType productType, double price, bool isDeleted) : IValidation
|
||||
{
|
||||
public string Id { get; private set; } = id;
|
||||
|
||||
public string ProductName { get; private set; } = productName;
|
||||
|
||||
public ProductType ProductType { get; private set; } = productType;
|
||||
|
||||
public double Price { get; private set; } = price;
|
||||
|
||||
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 (ProductName.IsEmpty())
|
||||
throw new ValidationException("Field ProductName is empty");
|
||||
|
||||
if (ProductType == ProductType.None)
|
||||
throw new ValidationException("Field ProductType is empty");
|
||||
|
||||
if (Price <= 0)
|
||||
throw new ValidationException("Field Price is less than or equal to 0");
|
||||
}
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SweetBunsContracts.DataModels
|
||||
{
|
||||
internal class ProductIngridientDataModel
|
||||
{
|
||||
}
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using SweetBunsContracts.Exceptions;
|
||||
using SweetBunsContracts.Extensions;
|
||||
using SweetBunsContracts.Infrastructure;
|
||||
|
||||
namespace SweetBunsContracts.DataModels;
|
||||
|
||||
public class SalaryDataModel(string workerId, DateTime salaryDate, double workerSalary) : IValidation
|
||||
{
|
||||
public string WorkerId { get; private set; } = workerId;
|
||||
|
||||
public DateTime SalaryDate { get; private set; } = salaryDate;
|
||||
|
||||
public double Salary { get; private set; } = workerSalary;
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
if (WorkerId.IsEmpty())
|
||||
throw new ValidationException("Field WorkerId is empty");
|
||||
|
||||
if (!WorkerId.IsGuid())
|
||||
throw new ValidationException("The value in the field WorkerId is not a unique identifier");
|
||||
|
||||
if (Salary <= 0)
|
||||
throw new ValidationException("Field Salary is less than or equal to 0");
|
||||
}
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SweetBunsContracts.DataModels
|
||||
{
|
||||
internal class SaleDataModel
|
||||
{
|
||||
}
|
||||
}
|
16
SweetBunsContracts/SweetBunsContracts/Enums/PostType.cs
Normal file
16
SweetBunsContracts/SweetBunsContracts/Enums/PostType.cs
Normal file
@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SweetBunsContracts.Enums;
|
||||
|
||||
public enum PostType
|
||||
{
|
||||
None = 0,
|
||||
Confectioner = 1,
|
||||
Baker = 2,
|
||||
KitchenHelper = 3,
|
||||
Salesman = 4
|
||||
}
|
15
SweetBunsContracts/SweetBunsContracts/Enums/ProductType.cs
Normal file
15
SweetBunsContracts/SweetBunsContracts/Enums/ProductType.cs
Normal file
@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SweetBunsContracts.Enums;
|
||||
|
||||
public enum ProductType
|
||||
{
|
||||
None = 0,
|
||||
Bakery = 1,
|
||||
Sweet = 2,
|
||||
Blanks = 3,
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SweetBunsContracts.Exceptions;
|
||||
|
||||
public class ValidationException(string message) : Exception(message)
|
||||
{
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SweetBunsContracts.Extensions;
|
||||
|
||||
public static class StringExtensions
|
||||
{
|
||||
public static bool IsEmpty(this string str)
|
||||
{
|
||||
return string.IsNullOrWhiteSpace(str);
|
||||
}
|
||||
|
||||
public static bool IsGuid(this string str)
|
||||
{
|
||||
return Guid.TryParse(str, out _);
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SweetBunsContracts.Infrastructure;
|
||||
public class IValidation
|
||||
{
|
||||
void Validate();
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user