Добавил больше информации в ICS
All checks were successful
Create and publish a Docker image / Publish image (push) Successful in 7m9s
All checks were successful
Create and publish a Docker image / Publish image (push) Successful in 7m9s
This commit is contained in:
@@ -125,10 +125,102 @@ namespace SfeduSchedule.Services
|
||||
|
||||
foreach (var e in scheduleJson.Embedded.Events)
|
||||
{
|
||||
// Получение названия аудитории для события
|
||||
string? roomName = null;
|
||||
if (scheduleJson.Embedded.EventLocations != null && scheduleJson.Embedded.Rooms != null &&
|
||||
scheduleJson.Embedded.EventRooms != null)
|
||||
{
|
||||
var eventLocation = scheduleJson.Embedded.EventLocations.FirstOrDefault(el => el.EventId == e.Id);
|
||||
if (eventLocation != null
|
||||
&& eventLocation.Links != null
|
||||
&& eventLocation.Links.EventRooms != null
|
||||
&& eventLocation.Links.EventRooms.Href != null)
|
||||
{
|
||||
var eventRoomId = eventLocation.Links.EventRooms.Href.Split('/').Last();
|
||||
var EventRoom =
|
||||
scheduleJson.Embedded.EventRooms.FirstOrDefault(er =>
|
||||
er.Id.ToString().ToLower() == eventRoomId);
|
||||
if (EventRoom != null)
|
||||
{
|
||||
var roomId = EventRoom.Links.Room.Href.Split('/').Last();
|
||||
var room = scheduleJson.Embedded.Rooms.FirstOrDefault(r =>
|
||||
r.Id.ToString().ToLower() == roomId);
|
||||
if (room != null)
|
||||
roomName = room.Name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Получение преподавателей для события
|
||||
string teachersNames = "";
|
||||
if (scheduleJson.Embedded.EventOrganizers != null && scheduleJson.Embedded.EventAttendees != null &&
|
||||
scheduleJson.Embedded.Persons != null)
|
||||
{
|
||||
// Получаем eventOrganizer
|
||||
var eventOrganizers =
|
||||
scheduleJson.Embedded.EventOrganizers.FirstOrDefault(eo => eo.EventId == e.Id);
|
||||
if (eventOrganizers != null &&
|
||||
eventOrganizers.Links.EventAttendees != null)
|
||||
{
|
||||
// Получаем eventAttendee id
|
||||
// Тут может прийти массив или 1 объект
|
||||
Self[] eventAttendeeIds = Array.Empty<Self>();
|
||||
if (eventOrganizers.Links.EventAttendees.Value.Self != null)
|
||||
eventAttendeeIds = new[] { eventOrganizers.Links.EventAttendees.Value.Self };
|
||||
else if (eventOrganizers.Links.EventAttendees.Value.SelfArray != null)
|
||||
eventAttendeeIds = eventOrganizers.Links.EventAttendees.Value.SelfArray;
|
||||
|
||||
if (eventAttendeeIds.Length > 0)
|
||||
{
|
||||
foreach (var eventAttendeeId in eventAttendeeIds)
|
||||
{
|
||||
var attendeeId = eventAttendeeId.Href.Split('/').Last();
|
||||
// Получаем eventAttendee
|
||||
var eventAttendee =
|
||||
scheduleJson.Embedded.EventAttendees.FirstOrDefault(ea =>
|
||||
ea.Id.ToString().ToLower() == attendeeId);
|
||||
if (eventAttendee != null)
|
||||
{
|
||||
var personId = eventAttendee.Links.Person.Href.Split('/').Last();
|
||||
// Получаем person
|
||||
var teacher = scheduleJson.Embedded.Persons.FirstOrDefault(p =>
|
||||
p.Id.ToString().ToLower() == personId);
|
||||
if (teacher != null)
|
||||
teachersNames += (string.IsNullOrEmpty(teachersNames) ? "" : ", ") +
|
||||
teacher.FullName;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Получение короткого названия для события
|
||||
string shortNameCourse = "";
|
||||
if (scheduleJson.Embedded.CourseUnitRealizations != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
var courseUnitRealizationsLinks = e.Links["course-unit-realization"];
|
||||
var courseUnitRealizationId = courseUnitRealizationsLinks.Href.Split('/').Last();
|
||||
if (!string.IsNullOrEmpty(courseUnitRealizationId))
|
||||
{
|
||||
var courseUnitRealization = scheduleJson.Embedded.CourseUnitRealizations
|
||||
.FirstOrDefault(cu => cu.Id.ToString().ToLower() == courseUnitRealizationId);
|
||||
if (courseUnitRealization != null)
|
||||
shortNameCourse = courseUnitRealization.NameShort ?? "";
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// Ignored
|
||||
}
|
||||
}
|
||||
|
||||
calendar.Events.Add(new CalendarEvent
|
||||
{
|
||||
Summary = e.Name,
|
||||
Description = e.NameShort,
|
||||
Summary = (string.IsNullOrEmpty(shortNameCourse) ? "" : shortNameCourse + " / ") + e.Name,
|
||||
Description = e.NameShort + (string.IsNullOrEmpty(roomName) ? "" : $"\nАудитория: {roomName}") +
|
||||
(string.IsNullOrEmpty(teachersNames) ? "" : $"\nПреподаватели: {teachersNames}"),
|
||||
Start = new CalDateTime(e.StartsAtLocal, _configuration["TZ"]!),
|
||||
End = new CalDateTime(e.EndsAtLocal, _configuration["TZ"]!),
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user