Skip to content

Commit ca00967

Browse files
Added support for generic timetables, automatic website checker and fixed a lot of bugs.
1 parent 245a310 commit ca00967

File tree

148 files changed

+3201
-911
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

148 files changed

+3201
-911
lines changed

BusinessLayer/BusinessLogic.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
<Compile Include="Properties\AssemblyInfo.cs" />
4949
<Compile Include="MonitoredWebsitesBL.cs" />
5050
<Compile Include="TeacherRequestsBL.cs" />
51+
<Compile Include="TimetablesBL.cs" />
5152
<Compile Include="UsersBL.cs" />
5253
</ItemGroup>
5354
<ItemGroup>

BusinessLayer/FeedsBL.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,19 @@ public List<Feed> GetFeedsForUser(string username)
2222
return dal.GetFeedsForUser(username);
2323
}
2424

25-
public List<Feed> GetFeedsForGroup(Group group)
25+
public List<Feed> GetFeedsForGroup(string facultyId, string groupId)
2626
{
27-
return dal.GetFeedsForGroup(group);
27+
return dal.GetFeedsForGroup(facultyId, groupId);
2828
}
2929

3030
public void InsertFeed(Feed feed)
3131
{
3232
dal.InsertFeed(feed);
3333
}
34+
35+
public Feed GetFeed(string feedId)
36+
{
37+
return dal.GetFeed(feedId);
38+
}
3439
}
3540
}

BusinessLayer/FiiTimetableBL.cs

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using Objects;
66
using FIITimetableParser;
77
using DataAccessLayer;
8+
using FIITimetableParser.FiiObjects;
89

910
namespace BusinessLogic
1011
{
@@ -26,37 +27,26 @@ public Exporter _exporter
2627
}
2728
}
2829

29-
private FiiTimetableDAL dal
30-
{
31-
get
32-
{
33-
return new FiiTimetableDAL();
34-
}
35-
}
36-
37-
public List<TimetableItem> GetTimetableForBachelorYear(StudyYear year, HalfYear halfYear)
30+
public List<FiiTimetableItem> GetTimetableForBachelorYear(StudyYear year, HalfYear halfYear)
3831
{
3932
return _parser.GetTimetableForYear(year, halfYear);
4033
}
4134

42-
public List<TimetableItem> GetTimetableForMastersYear(StudyYear year)
35+
public List<FiiTimetableItem> GetTimetableForMastersYear(StudyYear year)
4336
{
4437
return _parser.GetTimetableForYear(year);
4538
}
4639

4740
public string GetXMLTimetableForBachelorYear(StudyYear year, HalfYear halfYear)
4841
{
49-
return _exporter.ConvertToXML(_parser.GetTimetableForYear(year, halfYear));
42+
var subjectsBL = new SubjectsBL();
43+
return _exporter.ConvertToXML(_parser.GetTimetableForYear(year, halfYear), subjectsBL.GetAllSubjects());
5044
}
5145

5246
public string GetXMLTimetableForMastersYear(StudyYear year)
5347
{
54-
return _exporter.ConvertToXML(_parser.GetTimetableForYear(year));
55-
}
56-
57-
public void RefreshTimetable()
58-
{
59-
dal.RefreshTimetable();
48+
var subjectsBL = new SubjectsBL();
49+
return _exporter.ConvertToXML(_parser.GetTimetableForYear(year), subjectsBL.GetAllSubjects());
6050
}
6151
}
6252
}

BusinessLayer/MonitoredWebsitesBL.cs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,17 @@ public List<MonitoredWebsite> GetAllSubscribedWebsites(string userName)
2424
return dal.GetAllMonitoredWebsites(userName);
2525
}
2626

27+
public string GetAllSubscribedWebsitesAsXml(string username)
28+
{
29+
return dal.GetAllSubscribedWebsitesAsXml(username);
30+
}
31+
2732
public List<MonitoredWebsite> GetAllModifiedWebsites(string userName)
2833
{
2934
List<MonitoredWebsite> list = dal.GetMonitoredWebsitesByUsername(userName);
3035
if(list != null)
3136
{
32-
Monitor monitor = new Monitor();
33-
list = monitor.FilterAllModifiedWebsites(list);
37+
list = Monitor.FilterAllModifiedWebsites(list);
3438
dal.SaveMonitoredWebsites(list);
3539
}
3640
return list;
@@ -46,5 +50,20 @@ public MonitoredWebsite GetWebsite(string website)
4650
{
4751
return dal.GetWebsite(website);
4852
}
53+
54+
public void InsertWebsite(MonitoredWebsite website)
55+
{
56+
dal.InsertWebsite(website);
57+
}
58+
59+
public List<MonitoredWebsite> GetAllWebsites()
60+
{
61+
return dal.GetAllWebsites();
62+
}
63+
64+
public void SaveMonitoredWebsites(List<MonitoredWebsite> filterAllModifiedWebsites)
65+
{
66+
dal.SaveMonitoredWebsites(filterAllModifiedWebsites);
67+
}
4968
}
5069
}

BusinessLayer/NotificationsBL.cs

Lines changed: 116 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,16 @@
11
using System;
22
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
5-
using Objects;
3+
using System.Xml.Linq;
64
using DataAccessLayer;
5+
using Objects;
76

87
namespace BusinessLogic
98
{
109
public class NotificationsBL
1110
{
1211
public NotificationsDAL dal
1312
{
14-
get
15-
{
16-
return new NotificationsDAL();
17-
}
13+
get { return new NotificationsDAL(); }
1814
}
1915

2016
public void InsertNotification(Notification notification)
@@ -27,27 +23,128 @@ public void SolveNotification(string notificationId, string username)
2723
dal.SolveNotification(notificationId, username);
2824
}
2925

30-
public List<UserNotification> GetAllUserNotifications(string username)
26+
private List<UserNotification> GetAllStudentNotifications(string username)
3127
{
32-
UsersBL usersBL = new UsersBL();
33-
User user = usersBL.GetUser(username);
28+
var usersBL = new UsersBL();
29+
Student student = usersBL.GetStudent(username);
3430
List<UserNotification> list = null;
35-
if (user != null && user.UserType == UserTypes.Teacher)
31+
32+
if (student != null)
3633
{
37-
var teacher = user as Teacher;
38-
if (teacher != null) list = teacher.Notifications;
34+
list = student.Notifications;
3935
}
40-
if(user != null && user.UserType == UserTypes.Student)
36+
return list;
37+
}
38+
39+
private List<UserNotification> GetAllTeacherNotifications(string username)
40+
{
41+
var usersBL = new UsersBL();
42+
Teacher teacher = usersBL.GetTeacher(username);
43+
List<UserNotification> list = null;
44+
45+
if (teacher != null)
4146
{
42-
var student = user as Student;
43-
if (student != null) list = student.Notifications;
47+
list = teacher.Notifications;
4448
}
4549
return list;
4650
}
4751

48-
public Notification GetNotification(string notificationId)
52+
public Notification GetNotification(string notificationId, NotificationTypes notificationType)
53+
{
54+
return dal.GetNotification(notificationId, notificationType);
55+
}
56+
57+
public string GetUserNotificationsAsXml(string username, int count, UserTypes userType)
4958
{
50-
return dal.GetNotification(notificationId);
59+
List<UserNotification> list = null;
60+
if (userType == UserTypes.Student)
61+
list = GetAllStudentNotifications(username);
62+
else if (userType == UserTypes.Teacher)
63+
list = GetAllTeacherNotifications(username);
64+
65+
if (list != null)
66+
{
67+
if (count < list.Count)
68+
list = list.GetRange(list.Count - count, count);
69+
return GetXmlFromNotifications(list);
70+
}
71+
return String.Empty;
72+
}
73+
74+
private string GetXmlFromNotifications(List<UserNotification> list)
75+
{
76+
var document = new XDocument(new XDeclaration("1.0", "utf-8", "yes"));
77+
var notifications = new XElement("notifications");
78+
notifications.Add(new XAttribute("count", list.Count));
79+
var notificationsBL = new NotificationsBL();
80+
foreach (UserNotification userNotification in list)
81+
{
82+
var notificationElement = new XElement("notification");
83+
notificationElement.Add(new XElement("solved", userNotification.UserSolved));
84+
85+
var notificationDetails = new XElement("details");
86+
notificationDetails.Add(new XAttribute("type", userNotification.NotificationType));
87+
Notification notification = null;
88+
switch (userNotification.NotificationType)
89+
{
90+
case NotificationTypes.FeedNotification:
91+
92+
var feedNotification =
93+
(FeedNotification)
94+
notificationsBL.GetNotification(userNotification.NotificationId, NotificationTypes.FeedNotification);
95+
if (feedNotification != null)
96+
{
97+
var feedbl = new FeedsBL();
98+
Feed feed = feedbl.GetFeed(feedNotification.FeedId);
99+
if (feed != null)
100+
{
101+
notificationDetails.Add(new XElement("message", feed.Message));
102+
notificationDetails.Add(new XElement("sender", feed.Sender));
103+
}
104+
notification = feedNotification;
105+
}
106+
break;
107+
case NotificationTypes.TimetableNotification:
108+
var timetableNotification =
109+
(TimetableNotification)
110+
notificationsBL.GetNotification(userNotification.NotificationId, NotificationTypes.TimetableNotification);
111+
if (timetableNotification != null)
112+
{
113+
notificationDetails.Add(new XElement("timetableNotificationType",
114+
timetableNotification.TimetableNotificationType));
115+
notificationDetails.Add(new XElement("dayOfWeek", timetableNotification.Day));
116+
notificationDetails.Add(new XElement("typeOfClass",
117+
timetableNotification.ModifiedItem.TypeOfClass));
118+
notificationDetails.Add(new XElement("className",
119+
timetableNotification.ModifiedItem.ClassName));
120+
notificationDetails.Add(new XElement("startTime",
121+
timetableNotification.ModifiedItem.StartTime));
122+
notificationDetails.Add(new XElement("endTime",
123+
timetableNotification.ModifiedItem.EndTime));
124+
notification = timetableNotification;
125+
}
126+
break;
127+
case NotificationTypes.MonitoredWebsitesNotification:
128+
var websiteNotification =
129+
(MonitoredWebsiteNotification)notificationsBL.GetNotification(userNotification.NotificationId, NotificationTypes.MonitoredWebsitesNotification);
130+
if (websiteNotification != null)
131+
{
132+
notificationDetails.Add(new XElement("websiteLink", websiteNotification.WebsiteId));
133+
notification = websiteNotification;
134+
}
135+
break;
136+
}
137+
if (notification != null)
138+
{
139+
notificationElement.Add(new XElement("dateSent", notification.SentDate.ToString()));
140+
notificationElement.Add(new XElement("title", notification.Title));
141+
}
142+
notificationElement.Add(notificationDetails);
143+
144+
notifications.Add(notificationElement);
145+
}
146+
document.Add(notifications);
147+
return document.ToString();
51148
}
52149
}
53-
}
150+
}

0 commit comments

Comments
 (0)