|
using FluentValidation;
using System;
namespace RIATasks.Web
{
// This validator will be used for all operations on the Tasks table
public class TaskValidator : AbstractValidator<Task>
{
// Thses rules ensure that you always have a Name and Description for a Task
public TaskValidator()
{
RuleFor(Task => Task.TaskName).NotEmpty()
.WithMessage("Please specify Task Name");
RuleFor(Task => Task.TaskDescription).NotEmpty()
.WithMessage("Please specify Task Description");
}
}
// This validator will only be used for Insert operations on the Tasks table
public class TaskInsertValidator : AbstractValidator<Task>
{
public TaskInsertValidator()
{
// When inserting the date must be null or in the future
RuleFor(Task => Task.DueDate).Must(BeADateInTheFuture)
.WithMessage("Please specify a date that has not already passed");
}
// If a non-null date is entered make sure it is in the future
private bool BeADateInTheFuture(DateTime? dtCurrentDate)
{
DateTime dtDateInTheFuture = DateTime.Now.AddDays(1);
return ((dtCurrentDate ?? dtDateInTheFuture) >= DateTime.Now.AddDays(-1));
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.