public BulkScheduleViewModel(bool weekIsPublished) { WeekIsPublished = weekIsPublished; Shifts = new ObservableCollection <Shift>(); Tasks = new ObservableCollection <Task>(); Users = new ObservableCollection <User>(); this.LoadLookupsCommand = new Command(async() => await loadLookups()); this.SaveCommand = new Command(async() => await saveSchedules()); this.UpdateScheduleWeekCommand = new Command(() => { updateScheduleWeek(); }); ScheduleWeek = DateTime.Now; var user = LoginHelper.GetLoggedInUser().User; while ((int)ScheduleWeek.DayOfWeek != user.Company.WeekStartValue) { ScheduleWeek = ScheduleWeek.AddDays(-1); } updateScheduleWeek(); }
private async System.Threading.Tasks.Task saveSchedules() { if (Shift == null || Task == null || (!Monday && !Tuesday && !Wednesday && !Thursday && !Friday && !Saturday && !Sunday)) { MessageHelper.ShowMessage("Please fill in required fields and select at least one day!", "Validation"); return; } if (IsBusy) { return; } IsBusy = true; try { var schedules = new List <Schedule>(); var user = LoginHelper.GetLoggedInUser().User; var daysOfWeek = new List <int>(); if (Monday) { daysOfWeek.Add((int)DayOfWeek.Monday); } if (Tuesday) { daysOfWeek.Add((int)DayOfWeek.Tuesday); } if (Wednesday) { daysOfWeek.Add((int)DayOfWeek.Wednesday); } if (Thursday) { daysOfWeek.Add((int)DayOfWeek.Thursday); } if (Friday) { daysOfWeek.Add((int)DayOfWeek.Friday); } if (Saturday) { daysOfWeek.Add((int)DayOfWeek.Saturday); } if (Sunday) { daysOfWeek.Add((int)DayOfWeek.Sunday); } foreach (var d in daysOfWeek) { var schedule = new Schedule(); schedule.CompanyId = user.CompanyId; schedule.DayOfWeek = d; schedule.StartTimeTimezonedValue = (new DateTime(2000, 1, 1) + StartTime); schedule.EndTimeTimezoned = (new DateTime(2000, 1, 1) + EndTime); schedule.ShiftId = Shift.ShiftId; schedule.TaskId = Task.TaskId; if (User != null) { schedule.UserId = User.UserId; } var dow = d - user.Company.WeekStartValue; if (dow < 0) { dow += 7; } schedule.ScheduleDate = ScheduleWeek.AddDays(dow); if (User != null) { schedule.Published = WeekIsPublished; } else { schedule.Published = false; } schedules.Add(schedule); } await DataService.PostItemAsync <Schedule[]>("schedules", schedules.ToArray()); MessagingCenter.Send <BulkScheduleViewModel>(this, SUCCESS); IsBusy = false; } catch (Exception ex) { IsBusy = false; ExceptionHelper.ShowException(ex); } finally { IsBusy = false; } }