Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @model KalenderTool.ViewModels.HomeViewModel
- @using System.Globalization
- @{
- CultureInfo myCI = CultureInfo.CurrentUICulture;
- Calendar myCal = myCI.Calendar;
- CalendarWeekRule myCWR = myCI.DateTimeFormat.CalendarWeekRule;
- DayOfWeek myFirstDOW = myCI.DateTimeFormat.FirstDayOfWeek;
- //Get current Week
- int week = Model.WeekNo;
- //Assign varWeek currentWeek to use as parameter in Page-navigation
- int VarWeek = week;
- }
- <h2>KalendarTool</h2>
- @* Table for Navigation *@
- <table class="table table-bordered " align="center" style="width:100%">
- <tr>
- <td style="text-align:center">
- <a href="@Url.Action("HomePage", "Home", new { @id = VarWeek-1 })" class="btn btn-outline-dark btn-sm"><i class="fas fa-arrow-circle-left"></i> Letzte Woche </a>
- </td>
- <th style="width:20%; text-align:center">
- Kalenderwoche @VarWeek
- </th>
- <td style="text-align:center">
- <a href="@Url.Action("HomePage", "Home", new { @id = VarWeek+1 })" class="btn btn-outline-dark btn-sm">Nächste Woche <i class="fas fa-arrow-circle-right"></i></a>
- </td>
- </tr>
- </table>
- <table class="table table-bordered justify-content-center" id="reservationCalendar" align="center" style="width:100%">
- <tr>
- @{
- //GetCurrentMonth
- int currentMonth = DateTime.Now.Month;
- //Loop through every Month
- for (int month = 0; month < 12; month++)
- {
- int currentYear = DateTime.Now.Year;
- DateTime firstDay = new DateTime(DateTime.Now.Year, currentMonth, 1);
- int daysInCurrentMonth = DateTime.DaysInMonth(firstDay.Year, firstDay.Month);
- DateTime lastDay = new DateTime(currentYear, currentMonth, daysInCurrentMonth);
- // Sunday casted to int gives 0 but that will not work for us, we need 7 to be able to calculate number of empty cells correctly
- int dayOfWeekFirst = ((int)firstDay.DayOfWeek > 0) ? (int)firstDay.DayOfWeek : 7;
- int dayOfWeekLast = ((int)lastDay.DayOfWeek > 0) ? (int)lastDay.DayOfWeek : 7;
- //Loop through every Day in current Month
- for (int i = 1; i <= daysInCurrentMonth; i++)
- {
- DateTime renderedDay = new DateTime(firstDay.Year, firstDay.Month, i);
- int week1 = myCal.GetWeekOfYear(renderedDay, myCWR, myFirstDOW);
- String DayDate = renderedDay.ToString("dd.MMM");
- //Checks if the current Week equals the Week of the currently looped through Day and takes care that only one Week is shown
- if (week == week1)
- {
- //Gets executed if the renderedDay is a Monday
- if (renderedDay.DayOfWeek == DayOfWeek.Monday)
- {
- if (renderedDay < DateTime.Now)
- {
- <td style="width:9%; text-align:center;padding-right:0px;padding-left:0px;">
- <table class="table table-bordered justify-content-center" id="reservationCalendar" align="center" style="width:100%; height:100%;">
- <tr style="text-align:center;">Uhrzeit</tr>
- @{
- for (int d = 0; d < Model.Times.Count; d++)
- {
- <tr>
- <td>
- <div style="height: 25px; overflow:hidden;">
- @Model.Times[d].Time1
- </div>
- </td>
- </tr>
- } }
- </table>
- </td>
- }
- }
- //Checks if current date is past or not
- if (renderedDay < DateTime.Now)
- {
- <td style="text-align:center;padding-right:0px;padding-left:0px;">
- @renderedDay.DayOfWeek, @DayDate
- <table class="table justify-content-center" style="width:100%; background-color:grey;">
- @{
- for (int s = 0; s < Model.Times.Count; s++)
- {
- <tr>
- <td>
- <div style="height: 25px; overflow:hidden;">
- Vergangenheit
- </div>
- </td>
- </tr>
- } }
- </table>
- </td>
- }
- //Gets executed if Date isnt past
- else
- {
- <td style="text-align:center;padding-right:0px;padding-left:0px;">
- @renderedDay.DayOfWeek, @DayDate
- <table class="table table-bordered justify-content-center" style="width:100%">
- @{
- for (int h = 0; h < Model.Times.Count; h++)
- {
- <tr>
- <td>
- <div style="height: 25px; overflow:hidden;">
- @{
- string DayTime = Model.Times[h].Time1;
- string DayTimeHours = DayTime.Substring(0, 2);
- string DayTimeMinutes = DayTime.Substring(DayTime.Length - 2);
- double HourDouble = Convert.ToDouble(DayTimeHours);
- double MinutesDouble = Convert.ToDouble(DayTimeMinutes);
- DateTime renderedDayWithTime = renderedDay;
- renderedDayWithTime = renderedDayWithTime.AddHours(HourDouble);
- renderedDayWithTime = renderedDayWithTime.AddMinutes(MinutesDouble);
- string ModalString = renderedDayWithTime.ToString("ddMMyyyyHHmm");
- }
- <!-- Button trigger modal -->
- <button style="margin:0px" type="button" class="btn btn-success" data-toggle="modal" data-target="#@ModalString">
- Reservieren
- </button>
- <!-- Modal -->
- <div class="modal fade" id="@ModalString" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
- <div class="modal-dialog modal-dialog-centered" role="document">
- <div class="modal-content">
- <div class="modal-header">
- <h5 class="modal-title" id="exampleModalLongTitle"> @ModalString</h5>
- <button type="button" class="close" data-dismiss="modal" aria-label="Close">
- <span aria-hidden="true">×</span>
- </button>
- </div>
- <div class="modal-footer">
- <button type="button" class="btn btn-secondary" data-dismiss="modal">Abbrechen</button>
- <button type="button" class="btn btn-primary">Reservieren</button>
- </div>
- </div>
- </div>
- </div>
- </div>
- </td>
- </tr>
- } }
- </table>
- </td>
- }
- if (renderedDay.DayOfWeek == DayOfWeek.Sunday)
- {
- @:</tr>
- @:</table>
- @:<table class="table table-bordered" id="reservationCalendar" align="center" frame="border" style="width:100%">
- @:<tr>
- }
- }
- }
- currentMonth = currentMonth + 1;
- }
- }
- </tr>
- </table>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement