feature: add models
This commit is contained in:
parent
abdabd0ec3
commit
0d2982c770
@ -0,0 +1,41 @@
|
||||
using SoftwareInstallationContracts.Exceptions;
|
||||
using SoftwareInstallationContracts.Extensions;
|
||||
using SoftwareInstallationContracts.Infrastucture;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SoftwareInstallationContracts.DataModels;
|
||||
|
||||
public class BuyerDataModel(string id, string fio, string phoneNumber) : IValidation
|
||||
{
|
||||
public string Id { get; private set; } = id;
|
||||
|
||||
public string FIO { get; private set; } = fio;
|
||||
|
||||
public string PhoneNumber { get; private set; } = phoneNumber;
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
if (id.isEmpty())
|
||||
throw new ValidatonException("Field Id is empty");
|
||||
|
||||
if (!id.isGuid())
|
||||
throw new ValidatonException("The value in the field Id is not a unique identifier");
|
||||
|
||||
if (FIO.isEmpty())
|
||||
throw new ValidatonException("Field FIO is empty");
|
||||
|
||||
if (!Regex.IsMatch(FIO, @"/^([а-яa-zё\-]{2,})++([ ][а-яa-zё\-]{2,})++(?:[ ][а-яa-zё\-]{2,})?$"))
|
||||
throw new ValidatonException("Field FIO is not a fio");
|
||||
|
||||
if (PhoneNumber.isEmpty())
|
||||
throw new ValidatonException("Field PhoneNumber is empty");
|
||||
|
||||
if (!Regex.IsMatch(PhoneNumber, @"^((8|\+7)[\- ]?)?(\(?\d{3}\)?[\- ]?)?[\d\- ]{7,10}$"))
|
||||
throw new ValidatonException("Field PhoneNumber is not a phone number");
|
||||
}
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
using SoftwareInstallationContracts.Enums;
|
||||
using SoftwareInstallationContracts.Exceptions;
|
||||
using SoftwareInstallationContracts.Extensions;
|
||||
using SoftwareInstallationContracts.Infrastucture;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SoftwareInstallationContracts.DataModels;
|
||||
|
||||
public class PostDataModel(string id, string postId, string postName, PostType postType, int servicesCount, 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 ValidatonException("Field Id is empty");
|
||||
|
||||
if (!Id.isGuid())
|
||||
throw new ValidatonException("The value in the field Id is not a unique identifier");
|
||||
|
||||
if (PostId.isEmpty())
|
||||
throw new ValidatonException("Field PostId is empty");
|
||||
|
||||
if (!PostId.isGuid())
|
||||
throw new ValidatonException("The value in the field PostId is not a unique identifier");
|
||||
|
||||
if (Salary <= 0)
|
||||
throw new ValidatonException("Field Salary is empty");
|
||||
|
||||
if (PostType == PostType.None)
|
||||
throw new ValidatonException("Field PostType is empty");
|
||||
|
||||
if (PostName.isEmpty())
|
||||
throw new ValidatonException("Field PostName is empty");
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
using SoftwareInstallationContracts.Enums;
|
||||
using SoftwareInstallationContracts.Exceptions;
|
||||
using SoftwareInstallationContracts.Extensions;
|
||||
using SoftwareInstallationContracts.Infrastucture;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SoftwareInstallationContracts.DataModels;
|
||||
|
||||
public class ProgramDataModel(string id, string programName, ProgramType programType, string companyId, double price, bool isDeleted) : IValidation
|
||||
{
|
||||
public string Id { get; private set; } = id;
|
||||
|
||||
public string ProgramName { get; private set; } = programName;
|
||||
|
||||
public ProgramType ProgramType { get; private set; } = programType;
|
||||
|
||||
public string CompanyId { get; private set; } = companyId;
|
||||
|
||||
public double Price { get; private set; } = price;
|
||||
|
||||
public bool IsDeleted { get; private set; } = isDeleted;
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
if (Id.isEmpty())
|
||||
throw new ValidatonException("Field Id is empty");
|
||||
|
||||
if (!Id.isGuid())
|
||||
throw new ValidatonException("The value in the field Id is not a unique identifier");
|
||||
|
||||
if (ProgramName.isEmpty())
|
||||
throw new ValidatonException("Field ProgramName is empty");
|
||||
|
||||
if (ProgramType == ProgramType.None)
|
||||
throw new ValidatonException("Field ProgramType is empty");
|
||||
|
||||
if (CompanyId.isEmpty())
|
||||
throw new ValidatonException("Field CompanyId is empty");
|
||||
|
||||
if (!CompanyId.isGuid())
|
||||
throw new ValidatonException("The value in the field CompanyId is not a unique identifier");
|
||||
|
||||
if (Price <= 0)
|
||||
throw new ValidatonException("Field Price is less than or equal to 0");
|
||||
}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
using SoftwareInstallationContracts.Exceptions;
|
||||
using SoftwareInstallationContracts.Extensions;
|
||||
using SoftwareInstallationContracts.Infrastucture;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SoftwareInstallationContracts.DataModels;
|
||||
|
||||
public class ProgramHistoryDataModel(string programId, double oldPrice) : IValidation
|
||||
{
|
||||
public string ProgramId { get; private set; } = programId;
|
||||
|
||||
public double OldPrice { get; private set; } = oldPrice;
|
||||
|
||||
public DateTime ChangeUpdate { get; private set; } = DateTime.UtcNow;
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
if (ProgramId.isEmpty())
|
||||
throw new ValidatonException("Field ProgramId is empty");
|
||||
|
||||
if (!ProgramId.isGuid())
|
||||
throw new ValidatonException("The value in the field ProgramId is not a unique identifier");
|
||||
|
||||
if (OldPrice <= 0)
|
||||
throw new ValidatonException("Field OldPrice is less than or equal to 0");
|
||||
}
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
using SoftwareInstallationContracts.Exceptions;
|
||||
using SoftwareInstallationContracts.Extensions;
|
||||
using SoftwareInstallationContracts.Infrastucture;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SoftwareInstallationContracts.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 ValidatonException("Field WorkerId is empty");
|
||||
|
||||
if (!WorkerId.isGuid())
|
||||
throw new ValidatonException("The value in the field WorkerId is not a unique identifier");
|
||||
|
||||
if (Salary <= 0)
|
||||
throw new ValidatonException("Field Salary is less than or equal to 0");
|
||||
}
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
using SoftwareInstallationContracts.Exceptions;
|
||||
using SoftwareInstallationContracts.Extensions;
|
||||
using SoftwareInstallationContracts.Infrastucture;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SoftwareInstallationContracts.DataModels;
|
||||
|
||||
public class SaleDataModel(string id, string workerId, string buyerId, double sum, bool isCancel, List<SaleProgramDataModel> programs) : IValidation
|
||||
{
|
||||
public string Id { get; private set; } = id;
|
||||
|
||||
public string WorkerId { get; private set; } = workerId;
|
||||
|
||||
public string? BuyerId { get; private set; } = buyerId;
|
||||
|
||||
public DateTime SaleDate { get; private set; } = DateTime.UtcNow;
|
||||
|
||||
public double Sum { get; private set; } = sum;
|
||||
|
||||
public bool IsCancel { get; private set; } = isCancel;
|
||||
|
||||
public List<SaleProgramDataModel> Programs { get; private set; } = programs;
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
if (Id.isEmpty())
|
||||
throw new ValidatonException("Field Id is empty");
|
||||
|
||||
if (!Id.isGuid())
|
||||
throw new ValidatonException("The value in the field Id is not a unique identifier");
|
||||
|
||||
if (WorkerId.isEmpty())
|
||||
throw new ValidatonException("Field WorkerId is empty");
|
||||
|
||||
if (!WorkerId.isGuid())
|
||||
throw new ValidatonException("The value in the field WorkerId is not a unique identifier");
|
||||
|
||||
if (!BuyerId?.isGuid() ?? !BuyerId?.isEmpty() ?? false)
|
||||
throw new ValidatonException("The value in the field BuyerId is not a unique identifier");
|
||||
|
||||
if (Sum <= 0)
|
||||
throw new ValidatonException("Field Sum is less than or wqual to 0");
|
||||
|
||||
if ((Programs?.Count() ?? 0) == 0)
|
||||
throw new ValidatonException("The sale must include programs");
|
||||
}
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
using SoftwareInstallationContracts.Exceptions;
|
||||
using SoftwareInstallationContracts.Extensions;
|
||||
using SoftwareInstallationContracts.Infrastucture;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SoftwareInstallationContracts.DataModels;
|
||||
|
||||
public class SaleProgramDataModel(string programId, string saleId, int count) : IValidation
|
||||
{
|
||||
public string ProgramId { get; private set; } = programId;
|
||||
|
||||
public string SaleId { get; private set; } = saleId;
|
||||
|
||||
public int Count { get; private set; } = count;
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
if (ProgramId.isEmpty())
|
||||
throw new ValidatonException("Field ProgramId is empty");
|
||||
|
||||
if (!ProgramId.isGuid())
|
||||
throw new ValidatonException("The value in the field ProgramId is not a unique identifier");
|
||||
|
||||
if (SaleId.isEmpty())
|
||||
throw new ValidatonException("Field SaleId is empty");
|
||||
|
||||
if (!SaleId.isGuid())
|
||||
throw new ValidatonException("The value in the field SaleId is not a unique identifier");
|
||||
|
||||
if (Count <= 0)
|
||||
throw new ValidatonException("Field Count is less than or equal to 0");
|
||||
}
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
using SoftwareInstallationContracts.Exceptions;
|
||||
using SoftwareInstallationContracts.Extensions;
|
||||
using SoftwareInstallationContracts.Infrastucture;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SoftwareInstallationContracts.DataModels;
|
||||
|
||||
public class WorkerDataModel(string id, string fio, string postId, DateTime birthDate, DateTime employmentDate, bool isDeleted) : IValidation
|
||||
{
|
||||
public string Id { get; private set; } = id;
|
||||
public string FIO { get; private set; } = fio;
|
||||
public string PostId { get; private set; } = postId;
|
||||
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 ValidatonException("Field Id is empty");
|
||||
|
||||
if (!Id.isGuid())
|
||||
throw new ValidatonException("The value in the field Id is not a unique identifier");
|
||||
|
||||
if (FIO.isEmpty())
|
||||
throw new ValidatonException("Field FIO is empty");
|
||||
|
||||
if (PostId.isEmpty())
|
||||
throw new ValidatonException("Field PostId is empty");
|
||||
|
||||
if (!PostId.isGuid())
|
||||
throw new ValidatonException("The value in the field PostId is not a unique identifier");
|
||||
|
||||
if (BirthDate.Date > DateTime.Now.AddYears(-16).Date)
|
||||
throw new ValidatonException($"Minors cannot be hired (BirthDate = {BirthDate.ToShortDateString()}");
|
||||
|
||||
if (EmploymentDate.Date < BirthDate.Date)
|
||||
throw new ValidatonException("The date of employment cannot be less than the date of birth");
|
||||
|
||||
if ((EmploymentDate - BirthDate).TotalDays / 365 < 16)
|
||||
throw new ValidatonException($"Minors cannot be hired (EmploymentDate - {EmploymentDate.ToShortDateString()}, BirthDate - {BirthDate.ToShortDateString()}");
|
||||
}
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
using SoftwareInstallationContracts.Exceptions;
|
||||
using SoftwareInstallationContracts.Extensions;
|
||||
using SoftwareInstallationContracts.Infrastucture;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SoftwareInstallationContracts.DataModels;
|
||||
|
||||
public class СompanyDataModel(string id, string companyName, string prevCompanyName, string prevPrevCompanyName) : IValidation
|
||||
{
|
||||
public string Id { get; private set; } = id;
|
||||
public string СompanyName { get; private set; } = companyName;
|
||||
public string? PrevCompanyName { get; private set; } = prevCompanyName;
|
||||
public string? PrevPrevCompanyName { get; private set; } = prevPrevCompanyName;
|
||||
public void Validate()
|
||||
{
|
||||
if (Id.isEmpty())
|
||||
throw new ValidatonException("Field Id is empty");
|
||||
|
||||
if (!Id.isGuid())
|
||||
throw new ValidatonException("The value in the field Id is not a unique identifier");
|
||||
|
||||
if (СompanyName.isEmpty())
|
||||
throw new ValidatonException("Field СompanyName is empty");
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SoftwareInstallationContracts.Enums;
|
||||
|
||||
public enum PostType
|
||||
{
|
||||
None = 0,
|
||||
Supervisor = 1,
|
||||
Master = 2,
|
||||
Stuff = 3
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SoftwareInstallationContracts.Enums;
|
||||
|
||||
public enum ProgramType
|
||||
{
|
||||
None = 0,
|
||||
SystemSoftware = 1,
|
||||
ApplicationSoftware = 2,
|
||||
UtilitySoftware = 3,
|
||||
EnterpriseSoftware = 4,
|
||||
CloudServices = 5
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SoftwareInstallationContracts.Exceptions;
|
||||
|
||||
public class ValidatonException(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 SoftwareInstallationContracts.Extensions;
|
||||
|
||||
public static class StringExceptions
|
||||
{
|
||||
public static bool isEmpty(this string str)
|
||||
{
|
||||
return string.IsNullOrEmpty(str);
|
||||
}
|
||||
|
||||
public static bool isGuid(this string str)
|
||||
{
|
||||
return Guid.TryParse(str, out _);
|
||||
}
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SoftwareInstallationContracts.Infrastucture;
|
||||
|
||||
public interface IValidation
|
||||
{
|
||||
void Validate();
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user