From 4542a76661ca2df78cfa14c4aa8c864d1be2008b Mon Sep 17 00:00:00 2001 From: Adelina888 Date: Tue, 11 Feb 2025 21:16:09 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9D=D0=B0=D1=87=D0=B0=D0=BB=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../PipingHot/DataModels/BuyerDataModel.cs | 33 +++++++++++++++++++ .../PipingHot/DataModels/PostDataModel.cs | 12 +++++++ .../DataModels/RestaurantDataModel.cs | 29 ++++++++++++++++ PipingHot/PipingHot/Enums/PostType.cs | 16 +++++++++ .../Exceptions/ValidationException.cs | 11 +++++++ .../PipingHot/Extensions/StringExtensions.cs | 19 +++++++++++ .../PipingHot/Infrastructure/IValidation.cs | 12 +++++++ 7 files changed, 132 insertions(+) create mode 100644 PipingHot/PipingHot/DataModels/BuyerDataModel.cs create mode 100644 PipingHot/PipingHot/DataModels/PostDataModel.cs create mode 100644 PipingHot/PipingHot/DataModels/RestaurantDataModel.cs create mode 100644 PipingHot/PipingHot/Enums/PostType.cs create mode 100644 PipingHot/PipingHot/Exceptions/ValidationException.cs create mode 100644 PipingHot/PipingHot/Extensions/StringExtensions.cs create mode 100644 PipingHot/PipingHot/Infrastructure/IValidation.cs diff --git a/PipingHot/PipingHot/DataModels/BuyerDataModel.cs b/PipingHot/PipingHot/DataModels/BuyerDataModel.cs new file mode 100644 index 0000000..1fe5e47 --- /dev/null +++ b/PipingHot/PipingHot/DataModels/BuyerDataModel.cs @@ -0,0 +1,33 @@ +using PipingHot.Extensions; +using PipingHot.Infrastructure; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Text.RegularExpressions; +using System.Threading.Tasks; + +namespace PipingHot.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 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 (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"); + } +} diff --git a/PipingHot/PipingHot/DataModels/PostDataModel.cs b/PipingHot/PipingHot/DataModels/PostDataModel.cs new file mode 100644 index 0000000..528ec08 --- /dev/null +++ b/PipingHot/PipingHot/DataModels/PostDataModel.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PipingHot.DataModels; + +public class PostDataModel +{ + +} diff --git a/PipingHot/PipingHot/DataModels/RestaurantDataModel.cs b/PipingHot/PipingHot/DataModels/RestaurantDataModel.cs new file mode 100644 index 0000000..c1d62b5 --- /dev/null +++ b/PipingHot/PipingHot/DataModels/RestaurantDataModel.cs @@ -0,0 +1,29 @@ +using PipingHot.Extensions; +using PipingHot.Infrastructure; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PipingHot.DataModels; + +public class RestaurantDataModel(string id, string name, string adress): IValidation +{ + public string Id { get; private set; } = id; + public string Name { get; private set; } = name; + public string Adress { get; private set; } = adress; + + 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 (Adress.IsEmpty()) + throw new ValidationException("Field Adress is empty"); + } +} diff --git a/PipingHot/PipingHot/Enums/PostType.cs b/PipingHot/PipingHot/Enums/PostType.cs new file mode 100644 index 0000000..4a57049 --- /dev/null +++ b/PipingHot/PipingHot/Enums/PostType.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PipingHot.Enums; + +public enum PostType +{ + None = 0, + Operator = 1, + Aggregator = 2, + Deliveryman = 3 + +} diff --git a/PipingHot/PipingHot/Exceptions/ValidationException.cs b/PipingHot/PipingHot/Exceptions/ValidationException.cs new file mode 100644 index 0000000..8b5d172 --- /dev/null +++ b/PipingHot/PipingHot/Exceptions/ValidationException.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PipingHot.Exceptions; + +public class ValidationException(string message) : Exception(message) +{ +} diff --git a/PipingHot/PipingHot/Extensions/StringExtensions.cs b/PipingHot/PipingHot/Extensions/StringExtensions.cs new file mode 100644 index 0000000..b21c5d7 --- /dev/null +++ b/PipingHot/PipingHot/Extensions/StringExtensions.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PipingHot.Extensions; + +public static class StringExtensions +{ + public static bool IsEmpty(this string str) + { + return string.IsNullOrEmpty(str); + } + public static bool IsGuid(this string str) + { + return Guid.TryParse(str, out _); + } +} diff --git a/PipingHot/PipingHot/Infrastructure/IValidation.cs b/PipingHot/PipingHot/Infrastructure/IValidation.cs new file mode 100644 index 0000000..f13340d --- /dev/null +++ b/PipingHot/PipingHot/Infrastructure/IValidation.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PipingHot.Infrastructure; + +public interface IValidation +{ + void Validate(); +}