public static ScheduleBlockManager Create(Guid providerId) { ScheduleBlockManager result = new ScheduleBlockManager(); result.ProviderId = providerId; // Step 1. Create DataContext result.DataContext = DataContext.Create(); // Step 2. Load Rules and Blocks result.ScheduleRuleList = result.DataContext .ScheduleRuleSet .Include("ScheduleBlockCollection") .Where(x => x.ProviderId == result.ProviderId && x.RuleEndDate < DateTime.UtcNow.Date.AddDays(-30)) // Only show rules that expired within the last 30 days .ToList(); // Step 3. Get employee list List <Employee> employeeList = new List <Employee>(); foreach (var item in result.ScheduleRuleList) { if (item.Employee != null) { employeeList.Add(item.Employee); } } // Step 4. Get Distinct and Order by Employee result.EmployeeList = employeeList.GroupBy(item => item.Id).Select(group => group.First()).OrderBy(e => e.FullName).ToList(); return(result); }
public static ScheduleBlockManager Create(Guid providerId) { ScheduleBlockManager result = new ScheduleBlockManager(); result.ProviderId = providerId; // Step 1. Create DataContext result.DataContext = DataContext.Create(); // Step 2. Load Blocks result.ScheduleBlockList = result.DataContext.ScheduleBlockSet.Where(x => x.ProviderId == result.ProviderId).ToList(); // Step 3. Load Rules result.ScheduleRuleList = result.DataContext.ScheduleRuleSet.Where(x => x.ProviderId == result.ProviderId).ToList(); // Step 3. Cache return(result); }