public IActionResult SelectGroupTraining(IFormCollection fc) { var idTrainer = int.Parse(fc["STrainer"].ToString()); var dayOfWeek = int.Parse(fc["SDayOfWeek"].ToString()); ViewData["Trainers"] = GetTrainerList(); ViewData["DayOfWeeks"] = DayOfWeeks.Select(x => new SelectListItem { Text = x.Text, Value = x.Value, Selected = int.Parse(x.Value) == dayOfWeek }); var clientId = context.Client.Single(x => x.Email == User.Identity.Name).Id; ViewData["GroupTrainings"] = context.GroupTrain.Include(x => x.IdTrainerNavigation) .Include(x => x.OrderGroup) .Where(gt => gt.DayOfWeek == dayOfWeek && (gt.IdTrainer == idTrainer || idTrainer == 0) && gt.Capacity > 0) .ToList() .Select(x => new GroupTrainingModel { ID = x.Id, Name = x.Name, Capacity = x.Capacity, DayOfWeek = DayOfWeekMap[x.DayOfWeek].Short, Time = x.Time.ToString(), TrainerName = x.IdTrainerNavigation.Fio, Recorded = x.OrderGroup.FirstOrDefault(x => x.IdClient == clientId) != null }) .TakeMany(3); return(View(Roles.Client)); }
public DateTime?GetNextTime(DateTime current) { if (SecondType == CronFieldType.Specified && !Seconds.Any()) { throw new ArgumentException("Seconds are Empty."); } if (MinuteType == CronFieldType.Specified && !Minutes.Any()) { throw new ArgumentException("Minutes are Empty."); } if (HourType == CronFieldType.Specified && !Hours.Any()) { throw new ArgumentException("Hours are Empty."); } if (DayType == CronFieldType.Specified && !Days.Any()) { throw new ArgumentException("Days are Empty."); } if (MonthType == CronFieldType.Specified && !Months.Any()) { throw new ArgumentException("Months are Empty."); } if (DayOfWeekType == CronFieldType.Specified && !DayOfWeeks.Any()) { throw new ArgumentException("DayOfWeeks are Empty."); } if (YearType == CronFieldType.Specified && !Years.Any()) { throw new ArgumentException("Years are Empty."); } return(NextSecond(current.Year, current.Month, current.Day, current.Hour, current.Minute, current.Second)); }
public ScheduleGroup(ViewItemSchedule[] schedules) { var s = schedules[0]; StartTime = s.StartTime.TimeOfDay; EndTime = s.EndTime.TimeOfDay; Room = s.Room; DayOfWeeks = schedules.Select(i => i.DayOfWeek).Distinct().OrderBy(i => i).ToArray(); DaysText = string.Join(", ", DayOfWeeks.Select(i => DateTools.ToLocalizedString(i))); TimeText = PowerPlannerResources.GetStringTimeToTime(DateTimeFormatterExtension.Current.FormatAsShortTime(s.StartTime), DateTimeFormatterExtension.Current.FormatAsShortTime(s.EndTime)); }
public static DateTime GetConregationDay(DateTime date, DayOfWeeks day) { Log.Info(nameof(GetConregationDay), $"date={date}"); if ((int)date.DayOfWeek != (int)day) { //berechnen des nächsten Sonntag date = date.AddDays(7 - (int)date.DayOfWeek); //Abziehen von Tagen, falls anderer Wochentag als Sonntag if (day != DayOfWeeks.Sonntag) { date = date.AddDays((int)Wochentag - 7); } } return(date); }
/// <summary> /// If the schedule has the same start time, end time, room, and week, the schedule's day will be added and it'll return true. Else returns false. /// </summary> /// <param name="s"></param> /// <returns></returns> public bool Add(ViewItemSchedule s) { if (this.Equals(s)) { if (!DayOfWeeks.Contains(s.DayOfWeek)) { DayOfWeeks.Add(s.DayOfWeek); } existingSchedules.Add(s); return(true); } return(false); }
/// <summary> /// Call this BEFORE GetDeletedSchedules() and GetUpdatedSchedules(). This will mutate the existingSchedules list, so that it only contains the deleted schedules after it's done. /// It also mutates DayOfWeeks, removing each DayOfWeek as it's found. /// </summary> /// <returns></returns> public List <DataItemSchedule> GetUpdatedSchedules() { List <DataItemSchedule> answer = new List <DataItemSchedule>(); for (int i = 0; i < DayOfWeeks.Count && existingSchedules.Count > 0; i++) { for (int x = 0; x < existingSchedules.Count; x++) { if (existingSchedules[x].DayOfWeek == DayOfWeeks[i]) { //if it was actually changed if (existingSchedules[x].StartTime.TimeOfDay != StartTime || existingSchedules[x].EndTime.TimeOfDay != EndTime || !existingSchedules[x].Room.Equals(Room) || existingSchedules[x].ScheduleWeek != Week) { DataItemSchedule schedule = new DataItemSchedule() { Identifier = existingSchedules[x].Identifier }; //copy in the new info InitializeInfo(schedule); answer.Add(schedule); } existingSchedules.RemoveAt(x); DayOfWeeks.RemoveAt(i); i--; break; } } } return(answer); }
public void Save() { TryStartDataOperationAndThenNavigate(async delegate { if (StartTime >= EndTime) { new PortableMessageDialog("Your end time must be greater than your start time.", "Invalid end time").Show(); return; } if (DayOfWeeks.Count == 0) { new PortableMessageDialog("You must select at least one day of week. If you want to delete this time, use the delete option in the menu.", "No day of weeks").Show(); return; } var updatedAndNewSchedules = new List <DataItemSchedule>(); Guid classId = AddParams != null ? AddParams.Class.Identifier : EditParams.GroupedSchedules.First().Class.Identifier; // Get the existing schedules List <ViewItemSchedule> existingSchedules = EditParams != null ? EditParams.GroupedSchedules.ToList() : new List <ViewItemSchedule>(); for (int i = 0; i < DayOfWeeks.Count; i++) { DayOfWeek dayOfWeek = DayOfWeeks[i]; // First try to find an existing schedule that already matches this day of week ViewItemSchedule existingSchedule = existingSchedules.FirstOrDefault(s => s.DayOfWeek == dayOfWeek); // If we couldn't find one, try picking a schedule that doesn't have any day of week matches if (existingSchedule == null) { existingSchedule = existingSchedules.FirstOrDefault(s => !DayOfWeeks.Contains(s.DayOfWeek)); } // Remove the schedule we added if (existingSchedule != null) { existingSchedules.Remove(existingSchedule); } DataItemSchedule dataItem = new DataItemSchedule() { Identifier = existingSchedule != null ? existingSchedule.Identifier : Guid.NewGuid(), UpperIdentifier = classId, StartTime = AsUtc(StartTime), EndTime = AsUtc(EndTime), Room = Room, DayOfWeek = dayOfWeek, ScheduleWeek = ScheduleWeek, ScheduleType = PowerPlannerSending.Schedule.Type.Normal }; updatedAndNewSchedules.Add(dataItem); } // Deleted schedules are any remaining existing schedules var deletedScheduleIds = existingSchedules.Select(i => i.Identifier).ToArray(); DataChanges changes = new DataChanges(); foreach (var s in updatedAndNewSchedules) { changes.Add(s); } foreach (var id in deletedScheduleIds) { changes.DeleteItem(id); } if (!changes.IsEmpty()) { await PowerPlannerApp.Current.SaveChanges(changes); } }, delegate { this.RemoveViewModel(); }); }