Skip to content

Commit af4fc53

Browse files
Update projects
1 parent dae56da commit af4fc53

File tree

22 files changed

+697
-688
lines changed

22 files changed

+697
-688
lines changed

ASP.NET Core/Controllers/HomeController.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
using System.Linq;
44
using System.Threading.Tasks;
55
using Microsoft.AspNetCore.Mvc;
6+
using ASP_NET_Core.Models;
67

78
namespace ASP_NET_Core.Controllers;
89
public class HomeController: Controller {
910
public IActionResult Index() {
10-
return View();
11+
return View(AppointmentData.Appointments);
1112
}
1213

1314
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]

ASP.NET Core/Controllers/orig_SchedulerController.cs

Lines changed: 0 additions & 22 deletions
This file was deleted.

ASP.NET Core/Models/orig_Appoinment.cs renamed to ASP.NET Core/Models/Appointment.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@
33
using System.Linq;
44
using System.Text;
55
using System.Threading.Tasks;
6-
using Newtonsoft.Json;
76

87
namespace ASP_NET_Core.Models {
9-
public class Appoinment {
8+
public class Appointment {
109
public int Id { get; set; }
1110
public string Text { get; set; }
1211
public DateTime StartDate { get; set; }

ASP.NET Core/Models/orig_AppointmentData.cs renamed to ASP.NET Core/Models/AppointmentData.cs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,93 +8,93 @@ namespace ASP_NET_Core.Models
88
{
99
static class AppointmentData
1010
{
11-
public static List<Appoinment> Appointments = new List<Appoinment>()
11+
public static List<Appointment> Appointments = new List<Appointment>()
1212
{
13-
new Appoinment
13+
new Appointment
1414
{
1515
Id = 1,
1616
Text = "Website Re-Design Plan",
1717
StartDate = new DateTime(2021, 5, 5, 9, 30, 0),
1818
EndDate = new DateTime(2021, 5, 5, 11, 30, 0)
1919
},
20-
new Appoinment
20+
new Appointment
2121
{
2222
Id = 2,
2323
Text = "Install New Router in Dev Room",
2424
StartDate = new DateTime(2021, 5, 6, 13, 0, 0),
2525
EndDate = new DateTime(2021, 5, 6, 14, 0, 0)
2626
},
27-
new Appoinment
27+
new Appointment
2828
{
2929
Id = 3,
3030
Text = "Approve Personal Computer Upgrade Plan",
3131
StartDate = new DateTime(2021, 5, 3, 10, 0, 0),
3232
EndDate = new DateTime(2021, 5, 3, 11, 0, 0)
3333
},
34-
new Appoinment
34+
new Appointment
3535
{
3636
Id = 4,
3737
Text = "Final Budget Review",
3838
StartDate = new DateTime(2021, 5, 5, 13, 30, 0),
3939
EndDate = new DateTime(2021, 5, 5, 15, 0, 0)
4040
},
41-
new Appoinment
41+
new Appointment
4242
{
4343
Id = 5,
4444
Text = "New Brochures",
4545
StartDate = new DateTime(2021, 5, 6, 15, 0, 0),
4646
EndDate = new DateTime(2021, 5, 6, 16, 15, 0, 0)
4747
},
48-
new Appoinment
48+
new Appointment
4949
{
5050
Id = 6,
5151
Text = "Install New Database",
5252
StartDate = new DateTime(2021, 5, 3, 9, 45, 0),
5353
EndDate = new DateTime(2021, 5, 3, 12, 0, 0)
5454
},
55-
new Appoinment
55+
new Appointment
5656
{
5757
Id = 7,
5858
Text = "Approve New Online Marketing Strategy",
5959
StartDate = new DateTime(2021, 5, 3, 14, 30, 0),
6060
EndDate = new DateTime(2021, 5, 3, 16, 30, 0)
6161
},
62-
new Appoinment
62+
new Appointment
6363
{
6464
Id = 8,
6565
Text = "Upgrade Personal Computers",
6666
StartDate = new DateTime(2021, 5, 6, 15, 30, 0),
6767
EndDate = new DateTime(2021, 5, 6, 16, 45, 0)
6868
},
69-
new Appoinment
69+
new Appointment
7070
{
7171
Id = 9,
7272
Text = "Prepare 2021 Marketing Plan",
7373
StartDate = new DateTime(2021, 5, 3, 13, 0, 0),
7474
EndDate = new DateTime(2021, 5, 3, 15, 0, 0)
7575
},
76-
new Appoinment
76+
new Appointment
7777
{
7878
Id = 10,
7979
Text = "Brochure Design Review",
8080
StartDate = new DateTime(2021, 5, 1, 15, 30, 0),
8181
EndDate = new DateTime(2021, 5, 2, 0, 0, 0)
8282
},
83-
new Appoinment
83+
new Appointment
8484
{
8585
Id = 11,
8686
Text = "Create Icons for Website",
8787
StartDate = new DateTime(2021, 5, 5, 10, 0, 0),
8888
EndDate = new DateTime(2021, 5, 5, 11, 0, 0)
8989
},
90-
new Appoinment
90+
new Appointment
9191
{
9292
Id = 12,
9393
Text = "Upgrade Server Hardware",
9494
StartDate = new DateTime(2021, 5, 5, 16, 30, 0),
9595
EndDate = new DateTime(2021, 5, 5, 18, 0, 0)
9696
},
97-
new Appoinment
97+
new Appointment
9898
{
9999
Id = 13,
100100
Text = "Launch New Website",
Lines changed: 139 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,140 @@
1-
@using ASP_NET_Core.Models
2-
3-
<h2>Home</h2>
4-
5-
@(Html.DevExtreme().DataGrid<SampleOrder>()
6-
.ShowBorders(true)
7-
.DataSource(d => d.Mvc().Controller("SampleData").LoadAction("Get").Key("OrderID"))
8-
.Columns(columns => {
9-
columns.AddFor(m => m.OrderID);
10-
columns.AddFor(m => m.OrderDate);
11-
columns.AddFor(m => m.CustomerName);
12-
columns.AddFor(m => m.ShipCountry);
13-
columns.AddFor(m => m.ShipCity);
1+
@model IEnumerable<ASP_NET_Core.Models.Appointment>
2+
3+
@(Html.DevExtreme().Scheduler()
4+
.ID("scheduler")
5+
.DataSource(Model)
6+
.TextExpr("Text")
7+
.StartDateExpr("StartDate")
8+
.EndDateExpr("EndDate")
9+
.Views(views =>
10+
{
11+
views.Add()
12+
.Type(SchedulerViewType.TimelineDay)
13+
.IntervalCount(3);
1414
})
15-
.Paging(p => p.PageSize(10))
16-
.FilterRow(f => f.Visible(true))
17-
.HeaderFilter(f => f.Visible(true))
18-
.GroupPanel(p => p.Visible(true))
19-
.Grouping(g => g.AutoExpandAll(false))
20-
.RemoteOperations(true)
21-
.Summary(s => s
22-
.TotalItems(totalItems => {
23-
totalItems.AddFor(m => m.ShipCity).SummaryType(SummaryType.Count);
24-
})
25-
.GroupItems(groupItems => {
26-
groupItems.Add().SummaryType(SummaryType.Count);
27-
})
28-
)
29-
)
15+
.CurrentView(SchedulerViewType.TimelineDay)
16+
.CurrentDate(new DateTime(2021, 5, 3))
17+
.StartDayHour(9)
18+
.EndDayHour(19)
19+
.CellDuration(60)
20+
.Height(600)
21+
.DataCellTemplate(new JS("renderCellTemplate"))
22+
.OnAppointmentFormOpening("onAppointmentFormOpening")
23+
.OnAppointmentAdding("onAppointmentChanging")
24+
.OnAppointmentUpdating("onAppointmentChanging")
25+
)
26+
27+
<script>
28+
var dinnerTime = { start: 12, end: 13 };
29+
30+
var holiday = {
31+
date: new Date(2021, 4, 4),
32+
name: 'Star Wars Day'
33+
};
34+
35+
function renderCellTemplate(itemData, itemIndex, itemElement) {
36+
var startDate = itemData.startDate;
37+
var endDate = itemData.endDate;
38+
39+
var isHolidayCell = isHoliday(startDate, endDate);
40+
var isDinnerCell = isDinner(startDate, endDate);
41+
42+
var element = $(`<div>${getCellText(itemData)}</div>`);
43+
44+
if (isHolidayCell) {
45+
element.addClass('holiday');
46+
}
47+
48+
if (isDinnerCell) {
49+
element.addClass('dinner');
50+
}
51+
52+
return itemElement.append(element);
53+
}
54+
55+
function getCellText(itemData) {
56+
const startDate = itemData.startDate;
57+
const endDate = itemData.endDate;
58+
59+
const isHoliday = this.isHoliday(startDate, endDate);
60+
const isDinner = this.isDinner(startDate, endDate);
61+
62+
if (isHoliday) {
63+
return holiday.name;
64+
} else if (isDinner) {
65+
return "Dinner Time";
66+
}
67+
68+
return itemData.text;
69+
}
70+
71+
function isHoliday(startDate, endDate) {
72+
return holiday.date.toLocaleDateString() === startDate.toLocaleDateString() &&
73+
holiday.date.toLocaleDateString() === endDate.toLocaleDateString();
74+
}
75+
76+
function hasIntersection(startA, endA, startB, endB) {
77+
if ((startA <= startB && endB <= endA) ||
78+
(startB <= startA && endA <= endB)) {
79+
return true;
80+
}
81+
82+
return (startA < startB && startB < endA) ||
83+
(startA < endB && endB < endA);
84+
}
85+
86+
function isDinner(startDate, endDate) {
87+
var todayDinnerStart = new Date(startDate).setHours(dinnerTime.start, 0, 0, 0);
88+
var todayDinnerEnd = new Date(endDate).setHours(dinnerTime.end, 0, 0, 0);
89+
90+
return hasIntersection(
91+
todayDinnerStart, todayDinnerEnd,
92+
startDate.getTime(), endDate.getTime()
93+
);
94+
}
95+
96+
function onAppointmentChanging(e) {
97+
var startDate = e.appointmentData
98+
? new Date(e.appointmentData.StartDate)
99+
: new Date(e.newData.StartDate);
100+
101+
var endDate = e.appointmentData
102+
? new Date(e.appointmentData.EndDate)
103+
: new Date(e.newData.EndDate);
104+
105+
if (!isValidAppointmentDate(startDate, endDate)) {
106+
e.cancel = true;
107+
notifyDisableDate();
108+
}
109+
}
110+
111+
function onAppointmentFormOpening(e) {
112+
var startDate = new Date(e.appointmentData.StartDate || e.appointmentData.startDate);
113+
var endDate = new Date(e.appointmentData.EndDate || e.appointmentData.endDate);
114+
115+
if (!isValidAppointmentDate(startDate, endDate)) {
116+
e.cancel = true;
117+
notifyDisableDate();
118+
return;
119+
}
120+
applyDisableDatesToDateEditors(e.form);
121+
}
122+
123+
function isValidAppointmentDate(startDate, endDate) {
124+
return !isHoliday(startDate, endDate) && !isDinner(startDate, endDate);
125+
}
126+
127+
function applyDisableDatesToDateEditors(form) {
128+
var holidaysDate = holiday.date;
129+
130+
var startDateEditor = form.getEditor('StartDate');
131+
startDateEditor.option('disabledDates', [holidaysDate]);
132+
133+
var endDateEditor = form.getEditor('EndDate');
134+
endDateEditor.option('disabledDates', [holidaysDate]);
135+
}
136+
137+
function notifyDisableDate() {
138+
DevExpress.ui.notify("This date is disabled", "warning", 500);
139+
}
140+
</script>

0 commit comments

Comments
 (0)