gehgassi_backend/gehGassi.Core/Services/AppUserReportService.cs

119 lines
4.3 KiB
C#

using gehGassi.Core.Interfaces;
using gehGassi.Domain.Feedback;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using gehGassi.Domain.Reporting;
using gehGassi.Domain.Advertisements;
using gehGassi.Domain.Common;
namespace gehGassi.Core.Services
{
/// <summary>
/// Service der die Verwaltung von App-User-Reports ermöglicht
/// </summary>
public class AppUserReportService : ServiceBase<AppUserReport>, IAppUserReportService
{
private readonly IRepository<AppUserReportWithNames> _namesRepository;
/// <summary>
/// Erstellt eine Instanz
/// </summary>
/// <param name="unitOfWork">Instanz eines IUnitOfWork</param>
public AppUserReportService(IUnitOfWork unitOfWork) : base(unitOfWork)
{
_namesRepository = unitOfWork.GetRepository<AppUserReportWithNames>();
}
/// <summary>
/// Erstellen einer Meldung
/// </summary>
/// <returns>AppFeedback</returns>
public AppUserReport Create()
{
var item = new AppUserReport
{
Created = DateTimeOffset.UtcNow
};
return item;
}
/// <summary>
/// Gibt eine gefilterte Liste von Meldungen zurück
/// </summary>
/// <param name="filter">Filterbegriff der in bestimmten Feldern gesucht wird</param>
/// <returns>List betroffener Feedbacks</returns>
public IQueryable<AppUserReport> Filter(string filter)
{
return Repository.Query(c => c.Email.Contains(filter) || c.UpdatedBy.Contains(filter));
}
/// <summary>
/// Gibt eine gefilterte Liste von Meldungen zurück
/// </summary>
/// <param name="filter">Filterbegriff der in bestimmten Feldern gesucht wird</param>
/// <returns>List betroffener Feedbacks</returns>
public IQueryable<AppUserReportWithNames> FilterWithNames(string filter)
{
return _namesRepository.Query(c => c.ReportingAppUserName.Contains(filter) || c.ReportedAppUserName.Contains(filter) || c.ReportingAppUserEmail.Contains(filter) || c.ReportedAppUserEmail.Contains(filter));
}
/// <summary>
/// Gibt die Anzahl von Meldungen in einem bestimmten Status zurück
/// </summary>
/// <param name="status">Gesuchter Status</param>
/// <returns>Anzahl Meldungen im Status</returns>
public async Task<int> CountAsync(AppUserReportStatus status)
{
return await Repository.CountAsync(c => c.Status == status).ConfigureAwait(false);
}
/// <summary>
/// Gibt eine Meldung mit Namen aufgelöst zurück
/// </summary>
/// <param name="id">Id der Meldung</param>
/// <returns>AppUserReportWithNames oder null, wenn nicht gefunden</returns>
public async Task<AppUserReportWithNames> GetWithNamesAsync(long id)
{
return await _namesRepository.FirstOrDefaultAsync(c => c.Id == id).ConfigureAwait(false);
}
/// <summary>
/// Gibt zurück wie viele Meldungen ein App-User erstellt hat
/// </summary>
/// <param name="appUserId">Id des App-Users</param>
/// <returns>Anzahl Meldungen</returns>
public async Task<int> CountReportingAsync(string appUserId)
{
return await Repository.CountAsync(c => c.ReportingAppUserId == appUserId).ConfigureAwait(false);
}
/// <summary>
/// Gibt zurück wie viele Meldungen für ein App-User erstellt wurden
/// </summary>
/// <param name="appUserId">Id des App-Users</param>
/// <returns>Anzahl Meldungen erstellt</returns>
public async Task<int> CountReportedAsync(string appUserId)
{
return await Repository.CountAsync(c => c.ReportedAppUserId == appUserId).ConfigureAwait(false);
}
/// <summary>
/// Löscht alle Meldungen and denen ein AppUser beteiligt ist
/// </summary>
/// <param name="appUserId">Id des App-Users</param>
/// <returns>Anzahl Meldungen gelöscht</returns>
public async Task<int> DeleteAllForAppUserAsync(string appUserId)
{
var reports = await Repository.FindAsync(c => c.ReportedAppUserId == appUserId || c.ReportingAppUserId == appUserId).ConfigureAwait(false);
foreach (var report in reports)
{
Repository.Remove(report);
}
return reports.Count();
}
}
}