-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* issue #8 inital commit * Issue #8 Cron validation in RecurringSchedule.cs * more validation rules issue #8 * validation rules for default datetimes issue #8
- Loading branch information
1 parent
720ce65
commit 8f2af12
Showing
8 changed files
with
166 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,62 @@ | ||
using System; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.ComponentModel.DataAnnotations; | ||
using CronEspresso.NETCore.Utils; | ||
|
||
namespace Fritz.ResourceManagement.Domain | ||
{ | ||
/// <summary> | ||
/// An event that re-occurs on the schedule given a recurrence pattern defined in CronPattern | ||
/// </summary> | ||
public class RecurringSchedule { | ||
/// <summary> | ||
/// An event that re-occurs on the schedule given a recurrence pattern defined in CronPattern | ||
/// </summary> | ||
public class RecurringSchedule | ||
{ | ||
|
||
public int Id { get; set; } | ||
public int Id { get; set; } | ||
|
||
public int ScheduleId { get; set; } | ||
public int ScheduleId { get; set; } | ||
|
||
public ScheduleStatus Status { get; set; } | ||
public ScheduleStatus Status { get; set; } | ||
|
||
public string Name { get; set; } | ||
public string Name { get; set; } | ||
|
||
public string CronPattern { get; set; } | ||
public string CronPattern { get; set; } | ||
|
||
public TimeSpan Duration { get; set; } | ||
public TimeSpan Duration { get; set; } | ||
|
||
public DateTime MinStartDateTime { get; set; } | ||
public DateTime MinStartDateTime { get; set; } | ||
|
||
public DateTime MaxEndDateTime { get; set; } | ||
public DateTime MaxEndDateTime { get; set; } | ||
|
||
} | ||
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext) | ||
{ | ||
|
||
var results = new List<ValidationResult>(); | ||
|
||
if (string.IsNullOrWhiteSpace(Name)) | ||
results.Add(new ValidationResult($"{nameof(Name)} cannot be null, empty or consist of only whitespace", new[] { nameof(Name) })); | ||
|
||
if (string.IsNullOrWhiteSpace(CronPattern)) | ||
results.Add(new ValidationResult($"{nameof(CronPattern)} is required", new[] { nameof(CronPattern) })); | ||
else | ||
{ | ||
var cronValidationResult = CronHelpers.ValidateCron(CronPattern); | ||
if (!cronValidationResult.IsValidCron) | ||
results.Add(new ValidationResult($"{nameof(CronPattern) } is not a valid Cron pattern, {cronValidationResult.ValidationMessage}", new[] { nameof(CronPattern) })); | ||
} | ||
|
||
if (Duration.TotalMinutes < 30) | ||
results.Add(new ValidationResult($"{nameof(Duration)} must be atleast 30 minutes", new[] { nameof(Duration) })); | ||
|
||
if (MinStartDateTime == default) | ||
results.Add(new ValidationResult($"{nameof(MinStartDateTime)} is required", new[] { nameof(MinStartDateTime) })); | ||
|
||
if (MaxEndDateTime == default) | ||
results.Add(new ValidationResult($"{nameof(MaxEndDateTime)} is required", new[] { nameof(MaxEndDateTime) })); | ||
|
||
if (MaxEndDateTime < MinStartDateTime) | ||
results.Add(new ValidationResult($"{nameof(MaxEndDateTime)} cannot be before {nameof(MinStartDateTime)}", new[] { nameof(MaxEndDateTime), nameof(MinStartDateTime) })); | ||
|
||
return results; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,35 @@ | ||
using System; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.ComponentModel.DataAnnotations; | ||
|
||
namespace Fritz.ResourceManagement.Domain | ||
{ | ||
public class ScheduleException { | ||
public class ScheduleException | ||
{ | ||
|
||
public int Id { get; set; } | ||
public int Id { get; set; } | ||
|
||
public DateTime StartDateTime { get; set; } | ||
public DateTime StartDateTime { get; set; } | ||
|
||
public DateTime EndDateTime { get; set; } | ||
public DateTime EndDateTime { get; set; } | ||
|
||
public string Name { get; set; } | ||
public string Name { get; set; } | ||
|
||
} | ||
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext) | ||
{ | ||
|
||
var results = new List<ValidationResult>(); | ||
|
||
if (string.IsNullOrWhiteSpace(Name)) | ||
results.Add(new ValidationResult($"{nameof(Name)} cannot be null, empty or consist of only whitespace", new[] { nameof(Name) })); | ||
|
||
if (EndDateTime < StartDateTime) | ||
results.Add(new ValidationResult($"{nameof(EndDateTime)} cannot be before {nameof(StartDateTime)}", new[] { nameof(StartDateTime), nameof(EndDateTime) })); | ||
else if (EndDateTime < StartDateTime.AddDays(10)) | ||
results.Add(new ValidationResult($"{nameof(EndDateTime)} must be atleast 1 day after {nameof(StartDateTime)}", new[] { nameof(StartDateTime), nameof(EndDateTime) })); | ||
|
||
return results; | ||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,37 @@ | ||
using System; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.ComponentModel.DataAnnotations; | ||
|
||
namespace Fritz.ResourceManagement.Domain | ||
{ | ||
public class TimeSlot { | ||
public class TimeSlot | ||
{ | ||
|
||
public DateTime StartDateTime { get; set; } | ||
public DateTime StartDateTime { get; set; } | ||
|
||
public DateTime EndDateTime { get; set; } | ||
public DateTime EndDateTime { get; set; } | ||
|
||
public ScheduleStatus Status { get; set; } | ||
public ScheduleStatus Status { get; set; } | ||
|
||
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext) | ||
{ | ||
|
||
} | ||
var results = new List<ValidationResult>(); | ||
|
||
if (Status == default) | ||
results.Add(new ValidationResult($"{nameof(Status)} cannot have the default value of {default(ScheduleStatus)}", new[] { nameof(Status) })); | ||
|
||
if (StartDateTime == default) | ||
results.Add(new ValidationResult($"{nameof(StartDateTime)} is required", new[] { nameof(StartDateTime) })); | ||
|
||
if (EndDateTime == default) | ||
results.Add(new ValidationResult($"{nameof(EndDateTime)} is required", new[] { nameof(EndDateTime) })); | ||
|
||
if (EndDateTime < StartDateTime) | ||
results.Add(new ValidationResult($"{nameof(EndDateTime)} cannot be before {nameof(StartDateTime)}", new[] { nameof(StartDateTime), nameof(EndDateTime) })); | ||
|
||
return results; | ||
|
||
} | ||
} | ||
} |