Начало

This commit is contained in:
Adelina888 2025-02-11 21:16:09 +04:00
parent 792e7c7120
commit 4542a76661
7 changed files with 132 additions and 0 deletions

View 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");
}
}

View 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
{
}

View 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");
}
}

View 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
}

View 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)
{
}

View 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 _);
}
}

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