51 lines
1.6 KiB
C#
51 lines
1.6 KiB
C#
using Application.Endpoints.Appointments;
|
|
using Application.Services.Database.MongoDB;
|
|
using Core.Entities;
|
|
|
|
namespace Infrastructure.Services.MongoDB;
|
|
|
|
public class AppointmentsMongoDbService : MongoDbService, IAppointmentsMongoDbService
|
|
{
|
|
public AppointmentsMongoDbService(string connectionString, string databaseName, string collectionName)
|
|
: base(connectionString, databaseName, collectionName)
|
|
{
|
|
}
|
|
|
|
public async Task<bool> IsAppointmentUnique(AppointmentManagementDto dto)
|
|
{
|
|
var appointment = dto.Appointment.ToUniversalTime();
|
|
|
|
var criteria = new List<(string FieldName, string Value)>
|
|
{
|
|
("DoctorId", dto.DoctorId.ToString()),
|
|
("PatientId", dto.PatientId.ToString())
|
|
};
|
|
|
|
var appointments = await FindAsync<Appointment>(criteria);
|
|
|
|
foreach (var app in appointments)
|
|
if (app.AppointmentsList.Any(a => a.Date == appointment.Date))
|
|
return false;
|
|
|
|
return true;
|
|
}
|
|
|
|
public async Task<bool> DoesAppointmentExists(AppointmentManagementDto dto)
|
|
{
|
|
var appointment = dto.Appointment.ToUniversalTime();
|
|
|
|
var criteria = new List<(string FieldName, string Value)>
|
|
{
|
|
("DoctorId", dto.DoctorId.ToString()),
|
|
("PatientId", dto.PatientId.ToString())
|
|
};
|
|
|
|
var appointments = await FindAsync<Appointment>(criteria);
|
|
|
|
foreach (var app in appointments)
|
|
if (app.AppointmentsList.Any(a => a.Date == appointment.Date))
|
|
return true;
|
|
|
|
return false;
|
|
}
|
|
} |