/// <inheritdoc /> public override void OnOpen() { WeekDayModel weekDay = _dayOfWeekMapper.ToModel(DateTime.Now.DayOfWeek); WeekDaySelect(weekDay); _updateColorWorker = _workerController.StartWorker(UpdateScheduleColors, _updateColorInterval, false); }
public ShiftModel ConvertToModel(Shift dataModel) { if (dataModel == null) { return(null); } var model = new ShiftModel(); model.Id = dataModel.Id; model.Name = dataModel.Name; model.ShiftDetails = new List <WeekDayModel>(); if (dataModel.ShiftDetails.Count > 0) { foreach (var day in dataModel.ShiftDetails) { var shiftDetail = new WeekDayModel(); shiftDetail.IsWorkingDay = day.IsWorkingDay; shiftDetail.DayOfWeek = (DayOfWeek)day.DayOfWeek; shiftDetail.DayOfWeekName = ((DayOfWeek)day.DayOfWeek).ToString(); shiftDetail.StartTime = day.StartTime; shiftDetail.EndTime = day.EndTime; shiftDetail.BreakHours = day.BreakHours; shiftDetail.WorkingHours = day.WorkingHours; model.ShiftDetails.Add(shiftDetail); } } return(model); }
/// <summary> /// Обновляет цвета в расписании. /// </summary> /// <remarks>Дополнительно должен происходить раз в N секунд.</remarks> private void UpdateScheduleColors() { DateTime now = DateTime.Now; WeekDayModel currentWeekDay = _dayOfWeekMapper.ToModel(now.DayOfWeek); foreach (var item in ScheduleItems) { if (_selectedWeekDay != currentWeekDay) { item.ItemColor = ScheduleSubjectColor.Gray; continue; } if (now.TimeOfDay < item.Item.StartTime) { item.ItemColor = ScheduleSubjectColor.Green; } else if (now.TimeOfDay >= item.Item.StartTime && now.TimeOfDay < item.Item.StartTime + TimeSpan.FromHours(1)) { item.ItemColor = ScheduleSubjectColor.Yellow; } else { item.ItemColor = ScheduleSubjectColor.Red; } } }
public ScheduleViewModel( IModelMapper <ScheduleSubject, ScheduleSubjectItemModel> scheduleItemsMapper, IModelMapper <WeekDayCore, WeekDayModel> weekDaysMapper, IModelMapper <DayOfWeek, WeekDayModel> dayOfWeekMapper, IScheduleRepository scheduleRepository, IWorkerController workerManager, IDisplayService displayService) { _scheduleItemsMapper = scheduleItemsMapper ?? throw new ArgumentNullException(nameof(scheduleItemsMapper)); _scheduleRepository = scheduleRepository ?? throw new ArgumentNullException(nameof(scheduleRepository)); _dayOfWeekMapper = dayOfWeekMapper ?? throw new ArgumentNullException(nameof(dayOfWeekMapper)); _weekDaysMapper = weekDaysMapper ?? throw new ArgumentNullException(nameof(weekDaysMapper)); _workerController = workerManager ?? throw new ArgumentNullException(nameof(workerManager)); _displayService = displayService ?? throw new ArgumentNullException(nameof(displayService)); ScheduleItems = new ObservableCollection <ScheduleSubjectItemModel>(); _selectedWeekDay = WeekDayModel.Undefined; WeekDaySelectCommand = new RelayCommand(o => WeekDaySelect((WeekDayModel)o)); ScheduleItemClickedCommand = new RelayCommand(o => { if ((ScheduleSubjectItemModel)o != null) { var selectedScheduleItem = (ScheduleSubjectItemModel)o; _displayService.ShowDialog <RegistrationWindowViewModel, ScheduleSubjectModel, object>(selectedScheduleItem.Item); } }); }
/// <summary> /// Меняет текущий день недели. /// </summary> /// <param name="weekDay">День недели.</param> private void WeekDaySelect(WeekDayModel weekDay) { if (weekDay == WeekDayModel.Undefined) { return; } if (weekDay != _selectedWeekDay) { _selectedWeekDay = weekDay; // Обновляем расписание. ScheduleSubject[] schedueItems = _scheduleRepository.GetSchedulePerWeekDay(_weekDaysMapper.ToCore(weekDay)); ScheduleSubjectItemModel[] items = schedueItems.Select(x => _scheduleItemsMapper.ToModel(x)).OrderBy(x => x.Item.StartTime).ToArray(); SetScheduleItems(items); } }
public ActionResult EditWeekDay(int?id) { WeekDayModel model = null; List <TimeModel> times = null; using (IUnitOfWork uow = new UnitOfWork(new DbContextWrap())) { model = _repository.GetByKey <WeekDayModel>(uow, id); times = _repository.GetAll <TimeModel>(uow).ToList(); } var view = new WeekDaysView(model.Id, model.Name) { StartTimeValue = times.Where(x => x.Id == model.StartTime).First().StartTime, EndTimeValue = times.Where(x => x.Id == model.EndTime).First().StartTime, IsCancelled = model.IsCancelled, Times = times }; return(PartialView("_EditWeekDayPartialView", view)); }
public static string GetWeekDayCaption(WeekDayModel weekDay) { if (weekDay == WeekDayModel.Undefined) { return(Resources.WeekDayCaption_Short_Never); } List <string> days = new List <string>(7); if (weekDay.HasFlag(WeekDayModel.Monday)) { days.Add(Resources.WeekDayCaption_Short_Monday); } if (weekDay.HasFlag(WeekDayModel.Tuesday)) { days.Add(Resources.WeekDayCaption_Short_Tuesday); } if (weekDay.HasFlag(WeekDayModel.Wednesday)) { days.Add(Resources.WeekDayCaption_Short_Wednesday); } if (weekDay.HasFlag(WeekDayModel.Thursday)) { days.Add(Resources.WeekDayCaption_Short_Thursday); } if (weekDay.HasFlag(WeekDayModel.Friday)) { days.Add(Resources.WeekDayCaption_Short_Friday); } if (weekDay.HasFlag(WeekDayModel.Saturday)) { days.Add(Resources.WeekDayCaption_Short_Saturday); } if (weekDay.HasFlag(WeekDayModel.Sunday)) { days.Add(Resources.WeekDayCaption_Short_Sunday); } return(string.Join(",", days)); }
private static void OnDayOfWeekChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e) { DaysOfWeekControl control = obj as DaysOfWeekControl; WeekDayModel weekDayModel = WeekDayModel.Undefined; if (control.Monday) { weekDayModel |= WeekDayModel.Monday; } if (control.Tuesday) { weekDayModel |= WeekDayModel.Tuesday; } if (control.Wednesday) { weekDayModel |= WeekDayModel.Wednesday; } if (control.Thursday) { weekDayModel |= WeekDayModel.Thursday; } if (control.Friday) { weekDayModel |= WeekDayModel.Friday; } if (control.Saturday) { weekDayModel |= WeekDayModel.Saturday; } if (control.Sunday) { weekDayModel |= WeekDayModel.Sunday; } control.Value = weekDayModel; }
[HttpPost] // this action takes the viewModel from the modal public ActionResult EditWeekDay(WeekDayModel model, string startTime, string endTime, bool cancelledDay) { using (IUnitOfWork uow = new UnitOfWork(new DbContextWrap())) { var m = _repository.GetByKey <WeekDayModel>(uow, model.Id); var times = _repository.GetAll <TimeModel>(uow); if (!string.IsNullOrEmpty(startTime)) { m.StartTime = times.First(x => x.StartTime.ToString().Equals(startTime)).Id; } if (!string.IsNullOrEmpty(endTime)) { m.EndTime = times.First(x => x.StartTime.ToString().Equals(endTime)).Id; } m.IsCancelled = cancelledDay; _repository.Update(uow, m); uow.SaveChanges(); } return(RedirectToAction("Settings")); }
private void MakeDaysOfWeekForDateRange(IUnitOfWork uow, int dateRangeId, TimeModel t1800, TimeModel t2100, TimeModel t2000, TimeModel t1830, TimeModel t2130) { var monday = new WeekDayModel() { Name = DayOfWeek.Monday.ToString(), StartTimeKey = t1800, StartTime = t1800.Id, EndTimeKey = t2100, EndTime = t2100.Id, IsCancelled = false, DateRange = dateRangeId }; var tuesday = new WeekDayModel() { Name = DayOfWeek.Tuesday.ToString(), StartTimeKey = t1800, StartTime = t1800.Id, EndTimeKey = t2100, EndTime = t2100.Id, IsCancelled = false, DateRange = dateRangeId }; var wednesday = new WeekDayModel() { Name = DayOfWeek.Wednesday.ToString(), StartTimeKey = t1800, StartTime = t1800.Id, EndTimeKey = t2000, EndTime = t2000.Id, IsCancelled = false, DateRange = dateRangeId }; var thursday = new WeekDayModel() { Name = DayOfWeek.Thursday.ToString(), StartTimeKey = t1830, StartTime = t1830.Id, EndTimeKey = t2130, EndTime = t2130.Id, IsCancelled = false, DateRange = dateRangeId }; var friday = new WeekDayModel() { Name = DayOfWeek.Friday.ToString(), StartTimeKey = t1800, StartTime = t1800.Id, EndTimeKey = t2100, EndTime = t2100.Id, IsCancelled = true, DateRange = dateRangeId }; _repository.Add(uow, monday); _repository.Add(uow, tuesday); _repository.Add(uow, wednesday); _repository.Add(uow, thursday); _repository.Add(uow, friday); }
protected override void Seed(ReservationSystem.Models.DbContextWrap context) { if (!context.DateRanges.Any()) { var def = new DateRangeModel() { Name = "Default", StartDate = new DateTime(2000, 9, 1), EndTime = new DateTime(2000, 3, 31), IsActive = true }; context.DateRanges.Add(def); context.SaveChanges(); var id = context.DateRanges.First().Id; foreach (var day in context.WeekDays) { day.DateRange = id; } context.SaveChanges(); } if (!context.WeekDays.Any()) { var t1800 = context.Times.Where(item => item.StartTime == new TimeSpan(18, 0, 0)).First(); var t2100 = context.Times.Where(item => item.StartTime == new TimeSpan(21, 0, 0)).First(); var t2000 = context.Times.Where(item => item.StartTime == new TimeSpan(20, 0, 0)).First(); var t1830 = context.Times.Where(item => item.StartTime == new TimeSpan(18, 30, 0)).First(); var t2130 = context.Times.Where(item => item.StartTime == new TimeSpan(21, 30, 0)).First(); var monday = new WeekDayModel() { Name = DayOfWeek.Monday.ToString(), StartTimeKey = t1800, StartTime = t1800.Id, EndTimeKey = t2100, EndTime = t2100.Id, IsCancelled = false }; var tuesday = new WeekDayModel() { Name = DayOfWeek.Tuesday.ToString(), StartTimeKey = t1800, StartTime = t1800.Id, EndTimeKey = t2100, EndTime = t2100.Id, IsCancelled = false }; var wednesday = new WeekDayModel() { Name = DayOfWeek.Wednesday.ToString(), StartTimeKey = t1800, StartTime = t1800.Id, EndTimeKey = t2000, EndTime = t2000.Id, IsCancelled = false }; var thursday = new WeekDayModel() { Name = DayOfWeek.Thursday.ToString(), StartTimeKey = t1830, StartTime = t1830.Id, EndTimeKey = t2130, EndTime = t2130.Id, IsCancelled = false }; var friday = new WeekDayModel() { Name = DayOfWeek.Friday.ToString(), StartTimeKey = t1800, StartTime = t1800.Id, EndTimeKey = t2100, EndTime = t2100.Id, IsCancelled = true }; context.WeekDays.Add(monday); context.WeekDays.Add(tuesday); context.WeekDays.Add(wednesday); context.WeekDays.Add(thursday); context.WeekDays.Add(friday); context.SaveChanges(); } }