本篇议题如下:Transaction Scrip(前篇)Active Record前篇)Domain Model(中篇)Anemic Model(中篇)DDD(后篇)
{
public static bool BookHolidayFor(int employeeId, DateTime From, DateTime To)
{
bool booked = false;
TimeSpan numberOfDaysRequestedForHoliday = To - From;
if (numberOfDaysRequestedForHoliday.Days > 0)
{
if (RequestHolidayDoesNotClashWithExistingHoliday(employeeId, From, To))
{
int holidayAvailable = GetHolidayRemainingFor(employeeId);
if (holidayAvailable >= numberOfDaysRequestedForHoliday.Days)
{
SubmitHolidayBookingFor(employeeId, From, To);
booked = true;
}
}
}
return booked;
}
private static int GetHolidayRemainingFor(int employeeId)
{
// ...
}
public static List<EmployeeDTO> GetAllEmployeesOnLeaveBetween(
DateTime From, DateTime To)
{
// ...
}
public static List<EmployeeDTO> GetAllEmployeesWithHolidayRemaining()
{
// ...
}
}
public class Comment : ActiveRecordBase<Comment>
{
[PrimaryKey]
public int Id { get; set; }
[BelongsTo("ArticleID")]
public Article Post { get; set; }
[Property]
public string Subject { get; set; }
[Property]
public string Content { get; set; }
[Property]
public DateTime CreatedDate { get; set; }
[Property]
public string CreatedBy { get; set; }
[Property]
public DateTime UpdatedDate { get; set; }
}