Начало
This commit is contained in:
parent
792e7c7120
commit
4542a76661
33
PipingHot/PipingHot/DataModels/BuyerDataModel.cs
Normal file
33
PipingHot/PipingHot/DataModels/BuyerDataModel.cs
Normal file
@ -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");
|
||||||
|
}
|
||||||
|
}
|
12
PipingHot/PipingHot/DataModels/PostDataModel.cs
Normal file
12
PipingHot/PipingHot/DataModels/PostDataModel.cs
Normal file
@ -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
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
29
PipingHot/PipingHot/DataModels/RestaurantDataModel.cs
Normal file
29
PipingHot/PipingHot/DataModels/RestaurantDataModel.cs
Normal file
@ -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");
|
||||||
|
}
|
||||||
|
}
|
16
PipingHot/PipingHot/Enums/PostType.cs
Normal file
16
PipingHot/PipingHot/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 PipingHot.Enums;
|
||||||
|
|
||||||
|
public enum PostType
|
||||||
|
{
|
||||||
|
None = 0,
|
||||||
|
Operator = 1,
|
||||||
|
Aggregator = 2,
|
||||||
|
Deliveryman = 3
|
||||||
|
|
||||||
|
}
|
11
PipingHot/PipingHot/Exceptions/ValidationException.cs
Normal file
11
PipingHot/PipingHot/Exceptions/ValidationException.cs
Normal file
@ -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)
|
||||||
|
{
|
||||||
|
}
|
19
PipingHot/PipingHot/Extensions/StringExtensions.cs
Normal file
19
PipingHot/PipingHot/Extensions/StringExtensions.cs
Normal file
@ -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 _);
|
||||||
|
}
|
||||||
|
}
|
12
PipingHot/PipingHot/Infrastructure/IValidation.cs
Normal file
12
PipingHot/PipingHot/Infrastructure/IValidation.cs
Normal file
@ -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();
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user