Pibd-21 Nekrasov A.A. Первая лабораторная работа #1

Closed
alhimek17 wants to merge 2 commits from Task_1_Models into main
15 changed files with 445 additions and 0 deletions
Showing only changes of commit 4ffd1dcb56 - Show all commits

View File

@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.13.35806.99 d17.13
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WingsOfTheWorldContratcs", "WingsOfTheWorldContratcs\WingsOfTheWorldContratcs.csproj", "{BEAC542F-7E06-4942-A37D-583E87FAE7FF}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{BEAC542F-7E06-4942-A37D-583E87FAE7FF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BEAC542F-7E06-4942-A37D-583E87FAE7FF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BEAC542F-7E06-4942-A37D-583E87FAE7FF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BEAC542F-7E06-4942-A37D-583E87FAE7FF}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {FDD9A46D-B6D6-40D9-AE18-3DF8480C20EB}
EndGlobalSection
EndGlobal

View File

@ -0,0 +1,36 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WingsOfTheWorldContratcs.Enums;
using WingsOfTheWorldContratcs.Exceptions;
using WingsOfTheWorldContratcs.Exstensions;
using WingsOfTheWorldContratcs.Infrastructure;
namespace WingsOfTheWorldContratcs.DataModels;
public class AccessoriesDataModel(string id, string name, AccessoriesType accessoriesType) : IValidation
{
public string Id { get; private set; } = id;
public string Name { get; private set; } = name;
public AccessoriesType AccessoriesType { get; private set; } = accessoriesType;
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 PostName is empty");
if (AccessoriesType == AccessoriesType.None)
throw new ValidationException("Field PostType is empty");
}
}

View File

@ -0,0 +1,35 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using WingsOfTheWorldContratcs.Exceptions;
using WingsOfTheWorldContratcs.Exstensions;
using WingsOfTheWorldContratcs.Infrastructure;
namespace WingsOfTheWorldContratcs.DataModels;
public class AirplaneDataModel(string id, string model) : IValidation
{
public string Id { get; private set; } = id;
public string Model { get; private set; } = model;
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 (Model.IsEmpty())
throw new ValidationException("Field Model is empty");
if (!Model.IsGuid())
throw new ValidationException("The value in the field Model is not a unique identifier");
}
}

View File

@ -0,0 +1,53 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
using WingsOfTheWorldContratcs.Exceptions;
using WingsOfTheWorldContratcs.Exstensions;
using WingsOfTheWorldContratcs.Infrastructure;
namespace WingsOfTheWorldContratcs.DataModels;
public class DeliveryDataModel(string id, string airPlaneId, string place, int count, int price) : IValidation
{
public string Id { get; private set; } = id;
public string AirPlaneId { get; private set; } = airPlaneId;
public string Place { get; private set; } = place;
public int Count { get; private set; } = count;
public int Price { get; private set; } = price;
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 (AirPlaneId.IsEmpty())
throw new ValidationException("Field AirPlaneId is empty");
if (!AirPlaneId.IsGuid())
throw new ValidationException("The value in the field AirPlaneId is not a unique identifier");
if (Place.IsEmpty())
throw new ValidationException("Field Place is empty");
if (!Place.IsGuid())
throw new ValidationException("The value in the field Place is not a unique identifier");
if (Count <= 0)
throw new ValidationException("Field Count is empty");
if (Price <= 0)
throw new ValidationException("Field Price is empty");
}
}

View File

@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WingsOfTheWorldContratcs.Exceptions;
using WingsOfTheWorldContratcs.Exstensions;
using WingsOfTheWorldContratcs.Infrastructure;
namespace WingsOfTheWorldContratcs.DataModels;
public class DeliveryHistoryDataModel(string airplaneid, double oldPrice) : IValidation
{
public string AirplaneId { get; private set; } = airplaneid;
public double OldPrice { get; private set; } = oldPrice;
public DateTime ChangeDate { get; private set; } = DateTime.UtcNow;
public void Validate()
{
if (AirplaneId.IsEmpty())
throw new ValidationException("Field ProductId is empty");
if (!AirplaneId.IsGuid())
throw new ValidationException("The value in the field ProductId is not a unique identifier");
if (OldPrice <= 0)
throw new ValidationException("Field OldPrice is less than or equal to 0");
}
}

View File

@ -0,0 +1,53 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WingsOfTheWorldContratcs.Enums;
using WingsOfTheWorldContratcs.Exceptions;
using WingsOfTheWorldContratcs.Exstensions;
using WingsOfTheWorldContratcs.Infrastructure;
namespace WingsOfTheWorldContratcs.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");
}
}

View File

@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WingsOfTheWorldContratcs.Exceptions;
using WingsOfTheWorldContratcs.Exstensions;
using WingsOfTheWorldContratcs.Infrastructure;
namespace WingsOfTheWorldContratcs.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");
}
}

View File

@ -0,0 +1,52 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WingsOfTheWorldContratcs.Exceptions;
using WingsOfTheWorldContratcs.Exstensions;
using WingsOfTheWorldContratcs.Infrastructure;
namespace WingsOfTheWorldContratcs.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 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) // EmploymentDate.Year - BirthDate.Year
throw new ValidationException($"Minors cannot be hired (EmploymentDate - {EmploymentDate.ToShortDateString()}, BirthDate - {BirthDate.ToShortDateString()})");
}
}

View File

@ -0,0 +1,47 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using WingsOfTheWorldContratcs.Exceptions;
using WingsOfTheWorldContratcs.Exstensions;
using WingsOfTheWorldContratcs.Infrastructure;
namespace WingsOfTheWorldContratcs.DataModels;
public class СarrierСompanyDataModel(string id, string name, string phoneNumber, int count, int price) : IValidation
{
public string Id { get; private set; } = id;
public string Name { get; private set; } = name;
public string PhoneNumber { get; private set; } = phoneNumber;
public int Count { get; private set; } = count;
public int Price { get; private set; } = price;
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 Name is empty");
if (PhoneNumber.IsEmpty())
throw new ValidationException("Field PhoneNumber is empty");
if (!Regex.IsMatch(PhoneNumber, @"^((8|\+7)[\- ]?)?(\(?\d{3}\)?[\- ]?)?[\d\- ]{7,10}$"))
throw new ValidationException("Field PhoneNumber is not a phone number");
if (Count <= 0)
throw new ValidationException("Field Count is empty");
if (Price <= 0)
throw new ValidationException("Field Price is empty");
}
}

View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WingsOfTheWorldContratcs.Enums;
public enum AccessoriesType
{
None = 0,
Accessories = 1,
Salon = 2,
BodyWork = 3
}

View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WingsOfTheWorldContratcs.Enums;
public enum PostType
{
None = 0,
Supervisor = 1,
Master = 2,
Assistent = 3
}

View File

@ -0,0 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WingsOfTheWorldContratcs.Exceptions;
public class ValidationException(string message) : Exception(message)
{
}

View File

@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WingsOfTheWorldContratcs.Exstensions;
public static class StringExstensions
{
public static bool IsEmpty(this string str)
{
return string.IsNullOrWhiteSpace(str);
}
public static bool IsGuid(this string str)
{
return Guid.TryParse(str, out _);
}
}

View File

@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WingsOfTheWorldContratcs.Infrastructure;
public interface IValidation
{
void Validate();
}

View File

@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>