Files
Check/MagicCarpetProject/MagicCarpetContracts/DataModels/TourDataModel.cs
2025-05-22 09:32:03 +04:00

43 lines
1.9 KiB
C#

using MagicCarpetContracts.Enums;
using MagicCarpetContracts.Exceptions;
using MagicCarpetContracts.Extensions;
using MagicCarpetContracts.Infrastructure;
using MagicCarpetContracts.Resources;
using Microsoft.Extensions.Localization;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
namespace MagicCarpetContracts.DataModels;
internal class TourDataModel(string id, string tourName, string tourCountry, double price, TourType tourType) : IValidation
{
public string Id { get; private set; } = id;
public string TourName { get; private set; } = tourName;
public string TourCountry { get; private set; } = tourCountry;
public double Price { get; private set; } = price;
public TourType TourType { get; private set; } = tourType;
public TourDataModel() : this(string.Empty, string.Empty, string.Empty, 0, TourType.None) { }
public void Validate(IStringLocalizer<Messages> localizer)
{
if (Id.IsEmpty())
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageEmptyField"], "Id"));
if (!Id.IsGuid())
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageNotAId"], "Id"));
if (TourName.IsEmpty())
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageEmptyField"], "TourName"));
if (TourCountry.IsEmpty())
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageEmptyField"], "TourCountry"));
if (Price <= 0)
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageLessOrEqualZero"], "Price"));
if (TourType == TourType.None)
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageEmptyField"], "TourType"));
}
}