Skip to content
This repository has been archived by the owner on Aug 30, 2019. It is now read-only.

Commit

Permalink
issue FritzAndFriends#8 inital commit
Browse files Browse the repository at this point in the history
  • Loading branch information
marblekirby committed Jul 13, 2019
1 parent 720ce65 commit 32f46bb
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 27 deletions.
39 changes: 29 additions & 10 deletions src/Fritz.ResourceManagement.Domain/Person.cs
Original file line number Diff line number Diff line change
@@ -1,30 +1,49 @@
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Text.RegularExpressions;
using System.Data;

namespace Fritz.ResourceManagement.Domain
{
public class Person
{

public int Id { get; set; }
public int Id { get; set; }

public string GivenName { get; set; }
public string GivenName { get; set; }

public string MiddleName { get; set; }
public string MiddleName { get; set; }

public string SurName { get; set; }
public string SurName { get; set; }

public IList<PersonPersonType> PersonPersonType { get; set; }
public IList<PersonPersonType> PersonPersonType { get; set; }

public string PhoneNumber { get; set; }
public string PhoneNumber { get; set; }

public Schedule Schedule { get; set; }
public Schedule Schedule { get; set; }

#region Foreign Keys
#region Foreign Keys

public int ScheduleId { get; set; }
public int ScheduleId { get; set; }

#endregion
#endregion

public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
{

var results = new List<ValidationResult>();

if (string.IsNullOrWhiteSpace(GivenName))
results.Add(new ValidationResult($"{nameof(GivenName)} cannot be null, empty or consist of whitespace only", new[] { nameof(GivenName) }));

if (string.IsNullOrEmpty(SurName))
results.Add(new ValidationResult($"{nameof(SurName)} cannot be null, empty or consist of whitespace only", new[] { nameof(GivenName) }));

if (string.IsNullOrWhiteSpace(PhoneNumber))
results.Add(new ValidationResult($"{nameof(PhoneNumber)} cannot be null, empty or consist of whitespace only", new[] { nameof(PhoneNumber) }));

return results;
}

}

Expand Down
2 changes: 1 addition & 1 deletion src/Fritz.ResourceManagement.Domain/PersonPersonType.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Fritz.ResourceManagement.Domain
namespace Fritz.ResourceManagement.Domain
{
public class PersonPersonType {

Expand Down
15 changes: 14 additions & 1 deletion src/Fritz.ResourceManagement.Domain/PersonType.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;

namespace Fritz.ResourceManagement.Domain
{
Expand All @@ -13,6 +14,18 @@ public class PersonType

public ICollection<PersonPersonType> PersonPersonTypes { 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) }));

return results;

}

}

}
22 changes: 21 additions & 1 deletion src/Fritz.ResourceManagement.Domain/RecurringSchedule.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Text.RegularExpressions;

namespace Fritz.ResourceManagement.Domain
{
Expand All @@ -24,6 +26,24 @@ public class RecurringSchedule {

public DateTime MaxEndDateTime { get; set; }

public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
{

var results = new List<ValidationResult>();

if(!Regex.IsMatch(CronPattern, @"^((\*|\?|\d+((\/|\-){0,1}(\d+))*)\s*){6}$"))
results.Add(new ValidationResult($"{nameof(CronPattern)} is not a valid cron pattern", new[] { nameof(CronPattern) }));

if (string.IsNullOrWhiteSpace(Name))
results.Add(new ValidationResult($"{nameof(Name)} cannot be null, empty or consist of only whitespace", new[] { nameof(Name) }));

if (MaxEndDateTime < MinStartDateTime)
results.Add(new ValidationResult($"{nameof(MaxEndDateTime)} cannot be before {nameof(MinStartDateTime)}", new[] { nameof(MaxEndDateTime), nameof(MinStartDateTime) }));

return results;

}

}


Expand Down
30 changes: 23 additions & 7 deletions src/Fritz.ResourceManagement.Domain/ScheduleException.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,33 @@
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) }));

return results;

}
}
}
2 changes: 1 addition & 1 deletion src/Fritz.ResourceManagement.Domain/ScheduleItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public IEnumerable<ValidationResult> Validate(ValidationContext validationContex
var results = new List<ValidationResult>();

if (EndDateTime < StartDateTime)
results.Add(new ValidationResult("EndDateTime cannot be before StartDateTime", new[] { nameof(StartDateTime), nameof(EndDateTime) }));
results.Add(new ValidationResult($"{nameof(EndDateTime)} cannot be before {nameof(StartDateTime)}", new[] { nameof(StartDateTime), nameof(EndDateTime) }));

return results;

Expand Down
27 changes: 21 additions & 6 deletions src/Fritz.ResourceManagement.Domain/TimeSlot.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,31 @@
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 is default(ScheduleStatus))
results.Add(new ValidationResult($"{nameof(Status)} cannot have the default value of {default(ScheduleStatus)}", new[] { nameof(Status) }));

if (EndDateTime < StartDateTime)
results.Add(new ValidationResult($"{nameof(EndDateTime)} cannot be before {nameof(StartDateTime)}", new[] { nameof(StartDateTime), nameof(EndDateTime) }));

return results;

}
}
}

0 comments on commit 32f46bb

Please sign in to comment.