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(); +}