コード例 #1
0
        public static void Initialize(LifeguardIdentityDbContext context)
        {
            DateTime lastShiftDate;

            if (context.Shift.Any())
            {
                lastShiftDate = context.Shift.Max(m => m.ShiftDate).Date; //find last shift date
            }
            else
            {
                lastShiftDate = DateTime.Now.Date;
            }
            //add shifts until the next 60 days' shifts are populated
            if (DateTime.Compare(lastShiftDate.Date, DateTime.Now.Date.AddDays(60)) < 0)
            {
                DateTime newDay = lastShiftDate.AddDays(1);
                while (DateTime.Compare(newDay.Date, DateTime.Now.Date.AddDays(60)) < 0)
                {
                    var newShifts = new ArrayList(); //empty ArrayList which is filled differently depending on the day
                    switch (newDay.DayOfWeek)
                    {
                    case DayOfWeek.Sunday:
                        newShifts.Add(new Shift {
                            ShiftDate = newDay, ShiftNum = ShiftType.From5To9am
                        });
                        newShifts.Add(new Shift {
                            ShiftDate = newDay, ShiftNum = ShiftType.From9To1pm
                        });
                        newShifts.Add(new Shift {
                            ShiftDate = newDay, ShiftNum = ShiftType.From1To4pm
                        });
                        newShifts.Add(new Shift {
                            ShiftDate = newDay, ShiftNum = ShiftType.From4To7pm
                        });
                        newShifts.Add(new Shift {
                            ShiftDate = newDay, ShiftNum = ShiftType.From7To10pm
                        });
                        break;

                    case DayOfWeek.Monday:
                        newShifts.Add(new Shift {
                            ShiftDate = newDay, ShiftNum = ShiftType.From5To8am
                        });
                        newShifts.Add(new Shift {
                            ShiftDate = newDay, ShiftNum = ShiftType.From8To12pm
                        });
                        newShifts.Add(new Shift {
                            ShiftDate = newDay, ShiftNum = ShiftType.From12To4pm
                        });
                        newShifts.Add(new Shift {
                            ShiftDate = newDay, ShiftNum = ShiftType.From4To7pm
                        });
                        newShifts.Add(new Shift {
                            ShiftDate = newDay, ShiftNum = ShiftType.From7To10pm
                        });
                        break;

                    case DayOfWeek.Tuesday:
                        newShifts.Add(new Shift {
                            ShiftDate = newDay, ShiftNum = ShiftType.From5To8am
                        });
                        newShifts.Add(new Shift {
                            ShiftDate = newDay, ShiftNum = ShiftType.From8To12pm
                        });
                        newShifts.Add(new Shift {
                            ShiftDate = newDay, ShiftNum = ShiftType.From12To4pm
                        });
                        newShifts.Add(new Shift {
                            ShiftDate = newDay, ShiftNum = ShiftType.From4To7pm
                        });
                        newShifts.Add(new Shift {
                            ShiftDate = newDay, ShiftNum = ShiftType.From430To7pm
                        });
                        newShifts.Add(new Shift {
                            ShiftDate = newDay, ShiftNum = ShiftType.From7To10pm
                        });
                        break;

                    case DayOfWeek.Wednesday:
                        newShifts.Add(new Shift {
                            ShiftDate = newDay, ShiftNum = ShiftType.From5To8am
                        });
                        newShifts.Add(new Shift {
                            ShiftDate = newDay, ShiftNum = ShiftType.From8To12pm
                        });
                        newShifts.Add(new Shift {
                            ShiftDate = newDay, ShiftNum = ShiftType.From12To4pm
                        });
                        newShifts.Add(new Shift {
                            ShiftDate = newDay, ShiftNum = ShiftType.From4To7pm
                        });
                        newShifts.Add(new Shift {
                            ShiftDate = newDay, ShiftNum = ShiftType.From7To10pm
                        });
                        break;

                    case DayOfWeek.Thursday:
                        newShifts.Add(new Shift {
                            ShiftDate = newDay, ShiftNum = ShiftType.From5To8am
                        });
                        newShifts.Add(new Shift {
                            ShiftDate = newDay, ShiftNum = ShiftType.From8To12pm
                        });
                        newShifts.Add(new Shift {
                            ShiftDate = newDay, ShiftNum = ShiftType.From12To4pm
                        });
                        newShifts.Add(new Shift {
                            ShiftDate = newDay, ShiftNum = ShiftType.From4To7pm
                        });
                        newShifts.Add(new Shift {
                            ShiftDate = newDay, ShiftNum = ShiftType.From430To7pm
                        });
                        newShifts.Add(new Shift {
                            ShiftDate = newDay, ShiftNum = ShiftType.From7To10pm
                        });
                        break;

                    case DayOfWeek.Friday:
                        newShifts.Add(new Shift {
                            ShiftDate = newDay, ShiftNum = ShiftType.From5To8am
                        });
                        newShifts.Add(new Shift {
                            ShiftDate = newDay, ShiftNum = ShiftType.From8To12pm
                        });
                        newShifts.Add(new Shift {
                            ShiftDate = newDay, ShiftNum = ShiftType.From12To4pm
                        });
                        newShifts.Add(new Shift {
                            ShiftDate = newDay, ShiftNum = ShiftType.From4To7pm
                        });
                        newShifts.Add(new Shift {
                            ShiftDate = newDay, ShiftNum = ShiftType.From7To10pm
                        });
                        break;

                    case DayOfWeek.Saturday:
                        newShifts.Add(new Shift {
                            ShiftDate = newDay, ShiftNum = ShiftType.From5To9am
                        });
                        newShifts.Add(new Shift {
                            ShiftDate = newDay, ShiftNum = ShiftType.From9To1pm
                        });
                        newShifts.Add(new Shift {
                            ShiftDate = newDay, ShiftNum = ShiftType.From1To4pm
                        });
                        newShifts.Add(new Shift {
                            ShiftDate = newDay, ShiftNum = ShiftType.From4To7pm
                        });
                        newShifts.Add(new Shift {
                            ShiftDate = newDay, ShiftNum = ShiftType.From7To10pm
                        });
                        break;
                    }
                    foreach (Shift s in newShifts)
                    {
                        context.Shift.Add(s);
                    }
                    context.SaveChanges();
                    newDay = newDay.AddDays(1);
                }
            }
        }
コード例 #2
0
 public DeleteModel(Lifeguard.Data.LifeguardIdentityDbContext context)
 {
     _context = context;
 }
コード例 #3
0
 public IndexModel(Lifeguard.Data.LifeguardIdentityDbContext context)
 {
     _context = context;
 }