72 lines
2.0 KiB
C#
72 lines
2.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using YAPContracts.Exceptions;
|
|
using YAPContracts.Extentions;
|
|
using YAPContracts.Infrastructure;
|
|
|
|
namespace YAPContracts.DataModels
|
|
{
|
|
public class CommentDataModel : IValidation
|
|
{
|
|
public string Id { get; private set; }
|
|
public string ProductSetId { get; private set; }
|
|
public string UserId { get; private set; }
|
|
public string Text { get; private set; }
|
|
public DateTime Date { get; private set; }
|
|
|
|
public CommentDataModel(string id, string productSetId, string userId, string text, DateTime date)
|
|
{
|
|
Id = id;
|
|
ProductSetId = productSetId;
|
|
UserId = userId;
|
|
Text = text;
|
|
Date = date;
|
|
}
|
|
|
|
public CommentDataModel()
|
|
{
|
|
Id = Guid.NewGuid().ToString();
|
|
ProductSetId = string.Empty;
|
|
UserId = string.Empty;
|
|
Text = string.Empty;
|
|
Date = DateTime.UtcNow;
|
|
}
|
|
|
|
public void Validate()
|
|
{
|
|
if (Id.IsEmpty())
|
|
{
|
|
throw new ValidationException("Id is empty");
|
|
}
|
|
if (!Id.IsGuid())
|
|
{
|
|
throw new ValidationException("Id value is not valid");
|
|
}
|
|
if (ProductSetId.IsEmpty())
|
|
{
|
|
throw new ValidationException("ProductSetId is empty");
|
|
}
|
|
if (!ProductSetId.IsGuid())
|
|
{
|
|
throw new ValidationException("ProductSetId value is not valid");
|
|
}
|
|
if (UserId.IsEmpty())
|
|
{
|
|
throw new ValidationException("UserId is empty");
|
|
}
|
|
if (!UserId.IsGuid())
|
|
{
|
|
throw new ValidationException("UserId value is not valid");
|
|
}
|
|
if (Text.IsEmpty())
|
|
{
|
|
throw new ValidationException("Text is empty");
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|