public void Schedule(IRoutineSchedule schedule) { var scheduledRoutine = new ScheduledRoutine(this); schedule.Add(scheduledRoutine); }
public bool scheduleNewRoutine(Int32 routineID, DateTime start, Int32 userID, bool notification) { bool rc = false; using (var context = new Layer2Container()) { LimitBreaker lb = context.LimitBreakers.Where(x => x.id == userID).FirstOrDefault(); if (lb != null) { List<scheduledItem> scheduledItemsForThatDay = new List<scheduledItem>(); ScheduledRoutine newScheduledRoutine = new ScheduledRoutine(); //This part is for validating if the exercise can be scheduled for a certain time /*scheduledItemsForThatDay = getScheduledItemsByDay(userID, start); foreach (var item in scheduledItemsForThatDay) { if (item != null && start.AddHours(-1) <= item.startTime && start.AddHours(1) >= item.startTime) { return false; } } */ Routine routine = context.Routines.Where(e => e.id == routineID).FirstOrDefault(); newScheduledRoutine.Routine = routine; newScheduledRoutine.startTime = start; newScheduledRoutine.LimitBreaker = lb; newScheduledRoutine.needEmailNotification = notification; context.ScheduledRoutines.AddObject(newScheduledRoutine); context.SaveChanges(); rc = true; } return rc; } }