init
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Kreta.Ellenorzo.Enums.VN;
|
||||
|
||||
namespace Kreta.Ellenorzo.Domain.VN.Common
|
||||
{
|
||||
public class DateTimeIntervalRequest : IValidatableObject
|
||||
{
|
||||
private DateTime? _toDate;
|
||||
|
||||
public DateTimeIntervalRequest(DefaultInterval defaultInterval)
|
||||
{
|
||||
switch (defaultInterval)
|
||||
{
|
||||
case DefaultInterval.AktivTanev:
|
||||
FromDate = null;
|
||||
_toDate = null;
|
||||
break;
|
||||
case DefaultInterval.None:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public DateTimeIntervalRequest(DefaultInterval defaultInterval, DateTime? fromDate, DateTime? toDate) : this(defaultInterval)
|
||||
{
|
||||
if (fromDate.HasValue || toDate.HasValue)
|
||||
{
|
||||
FromDate = fromDate;
|
||||
ToDate = toDate;
|
||||
}
|
||||
}
|
||||
|
||||
public DateTime? FromDate { get; private set; }
|
||||
|
||||
public DateTime? ToDate { get => _toDate?.Date.AddDays(1).AddSeconds(-1); private set => _toDate = value; }
|
||||
|
||||
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
|
||||
{
|
||||
if (FromDate > ToDate)
|
||||
{
|
||||
yield return new ValidationResult("ToDateMustBeGreaterOrEqualThanFromDate");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user