public async Task <IActionResult> OnPost([FromQuery] int year, [FromQuery] int month, [FromQuery] int day)
        {
            if (!ModelState.IsValid)
            {
                ErrorMessage = "入力に誤りがあります。";
                return(PageResult(year, month, day));
            }
            if (!SelectedDates.Any())
            {
                ErrorMessage = "対象の日を1日以上は設定してください。";
                return(PageResult(year, month, day));
            }
            var startTime = LocalTimePattern.Create("HH:mm", CultureInfo.CurrentCulture).Parse(StartTime !);

            if (!startTime.Success)
            {
                ErrorMessage = "入力に誤りがあります。";
                return(PageResult(year, month, day));
            }

            var dates = SelectedDates
                        .Select(str => LocalDatePattern.CreateWithInvariantCulture("yyyy-MM-dd").Parse(str))
                        .ToList();

            if (dates.Any(r => !r.Success))
            {
                ErrorMessage = "入力に誤りがあります。";
                return(PageResult(year, month, day));
            }
            var result = await _service.CreateMultipleAppointmentSlotsAsync(dates.Select(d => d.Value).OrderBy(d => d).ToList(), startTime.Value, Period.FromMinutes(DurationMinutesForEachSlot !.Value), CountOfSlotForEachSlot !.Value, CountOfSlotsToCreate !.Value);

            if (!result.Succeeded)
            {
                ErrorMessage = result.ErrorMessage;
                return(PageResult(year, month, day));
            }

            return(RedirectToPage("Index", new { year, month, day }));
        }
Пример #2
0
        protected void ChangeCalendar(CalandarChanges changes)
        {
            Device.BeginInvokeOnMainThread(() =>
            {
                Content = null;
                if (changes.HasFlag(CalandarChanges.StartDate))
                {
                    TitleLabel.Text = StartDate.ToString(TitleLabelFormat);
                    if (TitleLabels != null)
                    {
                        var tls = StartDate.AddMonths(1);
                        foreach (var tl in TitleLabels)
                        {
                            (tl as Label).Text = tls.ToString(TitleLabelFormat);
                            tls = tls.AddMonths(1);
                        }
                    }
                }

                var start        = CalendarStartDate(StartDate).Date;
                var beginOfMonth = false;
                var endOfMonth   = false;
                for (int i = 0; i < buttons.Count; i++)
                {
                    endOfMonth   |= beginOfMonth && start.Day == 1;
                    beginOfMonth |= start.Day == 1;

                    if (i < dayLabels.Count && WeekdaysShow && changes.HasFlag(CalandarChanges.StartDay))
                    {
                        var day           = start.ToString(WeekdaysFormat);
                        string showDay    = char.ToUpper(day.First()) + day.Substring(1).ToLower();
                        dayLabels[i].Text = showDay;
                    }

                    ChangeWeekNumbers(start, i);

                    if (changes.HasFlag(CalandarChanges.All))
                    {
                        buttons[i].Text = string.Format("{0}", start.Day);
                    }
                    else
                    {
                        buttons[i].TextWithoutMeasure = string.Format("{0}", start.Day);
                    }
                    buttons[i].Date = start;

                    buttons[i].IsOutOfMonth = !(beginOfMonth && !endOfMonth);
                    buttons[i].IsEnabled    = ShowNumOfMonths == 1 || !buttons[i].IsOutOfMonth;

                    SpecialDate sd = null;
                    if (SpecialDates != null)
                    {
                        sd = SpecialDates.FirstOrDefault(s => s.Date.Date == start.Date);
                    }

                    SetButtonNormal(buttons[i]);

                    if ((MinDate.HasValue && start.Date < MinDate) || (MaxDate.HasValue && start.Date > MaxDate) || (DisableAllDates && sd == null))
                    {
                        SetButtonDisabled(buttons[i]);
                    }
                    else if (buttons[i].IsEnabled && (SelectedDates?.Select(d => d.Date)?.Contains(start.Date) ?? false))
                    {
                        SetButtonSelected(buttons[i], sd);
                    }
                    else if (sd != null)
                    {
                        SetButtonSpecial(buttons[i], sd);
                    }

                    start = start.AddDays(1);
                    if (i != 0 && (i + 1) % 42 == 0)
                    {
                        beginOfMonth = false;
                        endOfMonth   = false;
                        start        = CalendarStartDate(start);
                    }
                }
                if (DisableDatesLimitToMaxMinRange)
                {
                    TitleLeftArrow.IsEnabled  = !(MinDate.HasValue && CalendarStartDate(StartDate).Date < MinDate);
                    TitleRightArrow.IsEnabled = !(MaxDate.HasValue && start > MaxDate);
                }
                Content = MainView;
            });
        }
        protected void ChangeCalendar(CalendarChanges changes)
        {
            Device.BeginInvokeOnMainThread(() =>
            {
                OnStartRenderCalendar?.Invoke(this, EventArgs.Empty);
                Content = null;
                if (changes.HasFlag(CalendarChanges.StartDate))
                {
                    TitleLabel.Text = StartDate.ToString(TitleLabelFormat);
                    if (TitleLabels != null)
                    {
                        var tls = StartDate.AddMonths(1);
                        foreach (var tl in TitleLabels)
                        {
                            (tl as Label).Text = tls.ToString(TitleLabelFormat);
                            tls = tls.AddMonths(1);
                        }
                    }
                }

                var start        = CalendarStartDate(StartDate).Date;
                var beginOfMonth = false;
                var endOfMonth   = false;
                var hideLastRow  = false;
                for (int i = 0; i < buttons.Count; i++)
                {
                    endOfMonth   |= beginOfMonth && start.Day == 1;
                    beginOfMonth |= start.Day == 1;

                    if (i < dayLabels.Count && WeekdaysShow && changes.HasFlag(CalendarChanges.StartDay))
                    {
                        if (WeekdaysFormat.ToLower() == "d1")
                        {
                            dayLabels[i].Text = start.ToString("ddd").Substring(0, 1);
                        }
                        else if (WeekdaysFormat.ToLower() == "d2")
                        {
                            dayLabels[i].Text = start.ToString("ddd").Substring(0, 2);
                        }
                        else
                        {
                            dayLabels[i].Text = start.ToString(WeekdaysFormat);
                        }
                    }

                    ChangeWeekNumbers(start, i);

                    if (changes.HasFlag(CalendarChanges.All))
                    {
                        buttons[i].Text = string.Format("{0}", start.Day);
                    }
                    else
                    {
                        buttons[i].TextWithoutMeasure = string.Format("{0}", start.Day);
                    }
                    buttons[i].Date = start;

                    buttons[i].IsOutOfMonth = !(beginOfMonth && !endOfMonth);
                    buttons[i].IsEnabled    = ShowNumOfMonths == 1 || !buttons[i].IsOutOfMonth;

                    if (i == 35 && buttons[i].IsOutOfMonth)
                    {
                        // this means that we are on the bottom row and none of the dates
                        // in it belong to the current month we should hide this row
                        hideLastRow           = true;
                        rows.Last().IsVisible = false;
                    }

                    if (i >= 35 && hideLastRow)
                    {
                        buttons[i].IsVisible = false;
                    }
                    else
                    {
                        if (buttons[i].IsOutOfMonth)
                        {
                            buttons[i].IsVisible = ShowOutOfMonthDates;
                        }
                        else
                        {
                            buttons[i].IsVisible = true;
                        }
                        rows.Last().IsVisible = true;
                    }

                    SpecialDate sd = null;
                    if (SpecialDates != null)
                    {
                        sd = SpecialDates.FirstOrDefault(s => s.Date.Date == start.Date);
                    }

                    SetButtonNormal(buttons[i]);

                    if ((MinDate.HasValue && start < MinDate) || (MaxDate.HasValue && start > MaxDate) || (DisableAllDates && sd == null))
                    {
                        SetButtonDisabled(buttons[i]);
                    }
                    else if (buttons[i].IsEnabled && SelectedDates.Select(d => d.Date).Contains(start.Date))
                    {
                        SetButtonSelected(buttons[i], sd);
                    }
                    else if (sd != null)
                    {
                        SetButtonSpecial(buttons[i], sd);
                    }

                    start = start.AddDays(1);
                    if (i != 0 && (i + 1) % 42 == 0)
                    {
                        beginOfMonth = false;
                        endOfMonth   = false;
                        start        = CalendarStartDate(start);
                    }
                }
                if (DisableDatesLimitToMaxMinRange)
                {
                    TitleLeftArrow.IsEnabled  = !(MinDate.HasValue && CalendarStartDate(StartDate).Date < MinDate);
                    TitleRightArrow.IsEnabled = !(MaxDate.HasValue && start > MaxDate);
                }
                Content = MainView;
                OnEndRenderCalendar?.Invoke(this, EventArgs.Empty);
            });
        }
Пример #4
0
        protected void ChangeCalendar(CalandarChanges changes)
        {
            Device.BeginInvokeOnMainThread(() =>
            {
                Content = null;
                if (changes.HasFlag(CalandarChanges.StartDate))
                {
                    TitleLabel.Text = PersianDateInfo.MonthDic[StartDate.ToPersianDateTime().Month];
                    //if (TitleLabels != null)
                    //{
                    //    var tls = StartDate.AddMonths(1);
                    //    foreach (var tl in TitleLabels)
                    //    {
                    //        (tl as Label).Text = PersianDateInfo.MonthDic[tls.Month];
                    //        tls = tls.AddMonths(1);
                    //    }
                    //}
                }

                var pc           = new PersianCalendar();
                var start        = CalendarStartDate(StartDate.ToPersianDateTime());
                var end          = pc.GetDaysInMonth(start.Year, start.Month);
                var startEn      = start.ToDateTime();
                var beginOfMonth = false;
                var endOfMonth   = false;
                for (int i = 0; i < buttons.Count; i++)
                {
                    endOfMonth   |= i == end;
                    beginOfMonth |= start.Day == 1;
                    var ddd       = changes.HasFlag(CalandarChanges.StartDay);
                    //if (i < dayLabels.Count && WeekdaysShow && changes.HasFlag(CalandarChanges.StartDay))
                    if (i < dayLabels.Count && WeekdaysShow)
                    {
                        var day           = startEn.ToString(WeekdaysFormat);
                        string showDay    = PersianDateInfo.WeekDays[char.ToUpper(day.First()) + day.Substring(1).ToLower()];
                        dayLabels[i].Text = showDay;
                    }

                    //ChangeWeekNumbers(start, i);

                    if (changes.HasFlag(CalandarChanges.All))
                    {
                        buttons[i].Text = string.Format("{0}", start.Day);
                    }
                    else
                    {
                        buttons[i].TextWithoutMeasure = string.Format("{0}", start.Day);
                    }

                    buttons[i].Date         = startEn;
                    buttons[i].IsOutOfMonth = !(beginOfMonth && !endOfMonth);
                    buttons[i].IsEnabled    = ShowNumOfMonths == 1 || !buttons[i].IsOutOfMonth;

                    SpecialDate sd = null;
                    //if (SpecialDates != null)
                    //{
                    //	sd = SpecialDates.FirstOrDefault(s => s.Date.Date == start.Date);
                    //}

                    SetButtonNormal(buttons[i]);

                    if ((MinDate.HasValue && startEn.Date < MinDate) || (MaxDate.HasValue && startEn.Date > MaxDate) || (DisableAllDates && sd == null))
                    {
                        SetButtonDisabled(buttons[i]);
                    }
                    else if (buttons[i].IsEnabled && (SelectedDates?.Select(d => d.Date)?.Contains(startEn.Date) ?? false))
                    {
                        SetButtonSelected(buttons[i], sd);
                    }
                    else if (sd != null)
                    {
                        SetButtonSpecial(buttons[i], sd);
                    }

                    start.AddDay(1, end);
                    startEn = start.ToDateTime();
                    //               if (i != 0 && (i+1) % 42 == 0)
                    //{
                    //	beginOfMonth = false;
                    //	endOfMonth = false;
                    //	start = CalendarStartDate(start);
                    //}
                }
                if (DisableDatesLimitToMaxMinRange)
                {
                    TitleLeftArrow.IsEnabled  = !(MinDate.HasValue && CalendarStartDate(StartDate.ToPersianDateTime()).ToDateTime() < MinDate);
                    TitleRightArrow.IsEnabled = !(MaxDate.HasValue && start.ToDateTime() > MaxDate);
                }
                Content = MainView;
            });
        }