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 _eventRepository; private readonly IRepository _eventCategoryRepository; private readonly IRepository _eventTypeRepository; private readonly IRepository _eventPhotoRepository; private readonly IRepository _eventCommentRepository; private readonly IRepository _employeeRepository; public IntranetAppService( IRepository eventRepository, IRepository eventCategoryRepository, IRepository eventTypeRepository, IRepository eventPhotoRepository, IRepository eventCommentRepository, IRepository employeeRepository) { _eventRepository = eventRepository; _eventCategoryRepository = eventCategoryRepository; _eventTypeRepository = eventTypeRepository; _eventPhotoRepository = eventPhotoRepository; _eventCommentRepository = eventCommentRepository; _employeeRepository = employeeRepository; } public async Task GetIntranetDashboardAsync() { return new IntranetDashboardDto { Events = await GetUpcomingEventsAsync() }; } private async Task> GetUpcomingEventsAsync() { var events = await _eventRepository .WithDetailsAsync(e => e.Category, e => e.Type, e => e.Category, e => e.Photos, e => e.Comments) .ContinueWith(t => t.Result.ToList().Where(e => e.isPublished).OrderByDescending(e => e.CreationTime)); var result = new List(); foreach (var evt in events) { var employee = await _employeeRepository .WithDetailsAsync(e => e.JobPosition) .ContinueWith(t => t.Result.FirstOrDefault(e => e.Id == evt.EmployeeId)); if (employee != null) { var calendarEvent = new EventDto { Id = evt.Id.ToString(), Name = evt.Name, Description = evt.Description, TypeName = evt.Type?.Name, CategoryName = evt.Category?.Name, Date = evt.Date, Place = evt.Place, Organizer = new EventOrganizerDto { Id = employee.Id, Name = employee.FullName, Position = employee.JobPosition.Name, Avatar = employee.Avatar }, Participants = evt.ParticipantsCount, Photos = [], 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) .ContinueWith(t => t.Result.FirstOrDefault(e => e.Id == comment.EmployeeId)); 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 }, Content = comment.Content, CreationTime = comment.CreationTime, Likes = comment.Likes }); } } } result.Add(calendarEvent); } } return result; } }