erp-platform/api/src/Kurs.Platform.Application/Intranet/IntranetAppService.cs

119 lines
4.6 KiB
C#
Raw Normal View History

2025-10-28 18:03:15 +00:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Kurs.Platform.Entities;
using Microsoft.AspNetCore.Authorization;
using Volo.Abp.Domain.Repositories;
namespace Kurs.Platform.Public;
[Authorize]
public class IntranetAppService : PlatformAppService, IIntranetAppService
{
private readonly IRepository<Event, Guid> _eventRepository;
private readonly IRepository<EventCategory, Guid> _eventCategoryRepository;
private readonly IRepository<EventType, Guid> _eventTypeRepository;
private readonly IRepository<EventPhoto, Guid> _eventPhotoRepository;
private readonly IRepository<EventComment, Guid> _eventCommentRepository;
private readonly IRepository<Employee, Guid> _employeeRepository;
public IntranetAppService(
IRepository<Event, Guid> eventRepository,
IRepository<EventCategory, Guid> eventCategoryRepository,
IRepository<EventType, Guid> eventTypeRepository,
IRepository<EventPhoto, Guid> eventPhotoRepository,
IRepository<EventComment, Guid> eventCommentRepository,
IRepository<Employee, Guid> employeeRepository)
{
_eventRepository = eventRepository;
_eventCategoryRepository = eventCategoryRepository;
_eventTypeRepository = eventTypeRepository;
_eventPhotoRepository = eventPhotoRepository;
_eventCommentRepository = eventCommentRepository;
_employeeRepository = employeeRepository;
}
public async Task<IntranetDashboardDto> GetIntranetDashboardAsync()
{
return new IntranetDashboardDto
{
Events = await GetUpcomingEventsAsync()
};
}
private async Task<List<EventDto>> GetUpcomingEventsAsync()
{
var events = await _eventRepository
.WithDetailsAsync(e => e.Category, e => e.Type, e => e.Category, e => e.Photos, e => e.Comments)
2025-10-28 18:03:15 +00:00
.ContinueWith(t => t.Result.ToList().Where(e => e.isPublished).OrderByDescending(e => e.CreationTime));
var result = new List<EventDto>();
foreach (var evt in events)
{
var employee = await _employeeRepository
.WithDetailsAsync(e => e.JobPosition)
2025-10-28 18:59:07 +00:00
.ContinueWith(t => t.Result.FirstOrDefault(e => e.Id == evt.EmployeeId));
2025-10-28 18:03:15 +00:00
if (employee != null)
{
var calendarEvent = new EventDto
{
Id = evt.Id.ToString(),
Name = evt.Name,
2025-10-28 18:03:15 +00:00
Description = evt.Description,
TypeName = evt.Type?.Name,
CategoryName = evt.Category?.Name,
Date = evt.Date,
Place = evt.Place,
2025-10-28 18:03:15 +00:00
Organizer = new EventOrganizerDto
{
Id = employee.Id,
Name = employee.FullName,
Position = employee.JobPosition.Name,
Avatar = employee.Avatar
},
Participants = evt.ParticipantsCount,
Photos = [],
2025-10-28 18:03:15 +00:00
Comments = [],
Likes = evt.Likes,
IsPublished = evt.isPublished
};
// Comment'lerin author bilgilerini doldur
if (evt.Comments != null && evt.Comments.Any())
{
foreach (var comment in evt.Comments)
{
var commentAuthor = await _employeeRepository
.WithDetailsAsync(e => e.JobPosition)
2025-10-28 18:59:07 +00:00
.ContinueWith(t => t.Result.FirstOrDefault(e => e.Id == comment.EmployeeId));
2025-10-28 18:03:15 +00:00
if (commentAuthor != null)
{
calendarEvent.Comments.Add(new EventCommentDto
{
Id = comment.Id.ToString(),
Author = new EventOrganizerDto
{
Id = commentAuthor.Id,
Name = commentAuthor.FullName,
Position = commentAuthor.JobPosition.Name,
Avatar = commentAuthor.Avatar
},
2025-10-28 18:59:07 +00:00
Content = comment.Content,
2025-10-28 18:03:15 +00:00
CreationTime = comment.CreationTime,
Likes = comment.Likes
});
}
}
}
result.Add(calendarEvent);
}
}
return result;
}
}