118 lines
4.7 KiB
C#
118 lines
4.7 KiB
C#
|
|
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.Photos, e => e.Comments)
|
||
|
|
.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)
|
||
|
|
.ContinueWith(t => t.Result.FirstOrDefault(e => e.Id == evt.OrganizerId));
|
||
|
|
|
||
|
|
if (employee != null)
|
||
|
|
{
|
||
|
|
var calendarEvent = new EventDto
|
||
|
|
{
|
||
|
|
Id = evt.Id.ToString(),
|
||
|
|
Title = evt.Name,
|
||
|
|
Description = evt.Description,
|
||
|
|
Type = evt.Type?.Name?.ToLowerInvariant() ?? "social",
|
||
|
|
Date = evt.CreationTime,
|
||
|
|
Location = evt.Place,
|
||
|
|
Organizer = new EventOrganizerDto
|
||
|
|
{
|
||
|
|
Id = employee.Id,
|
||
|
|
Name = employee.FullName,
|
||
|
|
Position = employee.JobPosition.Name,
|
||
|
|
Avatar = employee.Avatar
|
||
|
|
},
|
||
|
|
Participants = evt.ParticipantsCount,
|
||
|
|
Photos = evt.Photos?.Select(p => p.Url).ToList() ?? new List<string>(),
|
||
|
|
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.UserId));
|
||
|
|
|
||
|
|
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.Comment,
|
||
|
|
CreationTime = comment.CreationTime,
|
||
|
|
Likes = comment.Likes
|
||
|
|
});
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
result.Add(calendarEvent);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
return result;
|
||
|
|
}
|
||
|
|
}
|