public async Task <List <GetAppointmentsDto> > Handle(GetAppointmentsQuery request, CancellationToken cancellationToken) { List <GetAppointmentsDto> appointmentDtos = new List <GetAppointmentsDto>(); var appointmentRequests = await appointmentRequestRepository.GetAsync(cancellationToken); foreach (AppointmentRequest appointmentRequest in appointmentRequests) { DateTime?start = null; DateTime?end = null; if (appointmentRequest.AppointmentId != null) { var appointment = await appointmentRepository.GetByIdAsync(appointmentRequest.AppointmentId.Value, cancellationToken); start = appointment.Start; end = appointment.End; } appointmentDtos.Add(new GetAppointmentsDto { Id = appointmentRequest.Id, Title = appointmentRequest.Title, Description = appointmentRequest.Description, Latitude = appointmentRequest.Latitude, Longitude = appointmentRequest.Longitude, Duration = appointmentRequest.Duration, Date = appointmentRequest.Date, Start = start, End = end, ClientId = appointmentRequest.ClientId, TenantId = appointmentRequest.TenantId, Address = addressBook.GetAddress(appointmentRequest.Latitude, appointmentRequest.Longitude) }); } return(appointmentDtos); }
public List <AppointmentReadModel> Handle(GetAppointmentsQuery query) { var calendar = new CalendarReadModel(); calendar = _redisService.HashGet <CalendarReadModel>($"{calendar.RedisKey}", $"{query.Id}", CommandFlags.PreferMaster); return(calendar.Appointments.Where(x => x.StartingTime >= query.StartDate && x.StartingTime <= query.EndDate.AddHours(24).AddSeconds(-1)).ToList()); }
public async Task <IEnumerable <AppointmentDto> > Handle(GetAppointmentsQuery request, CancellationToken cancellationToken) { return(await _context.Appointments .AsNoTracking() .Select(_ => new AppointmentDto() { Id = _.Id, CompanyName = _.Company.Name, Date = _.Date, UserName = _.User.Name }).ToListAsync(cancellationToken: cancellationToken)); }
public async Task AppointmentHandler_Get_GetAllAsync() { //Arrange var dateTimeNow = DateTime.Now; var command = new GetAppointmentsQuery(); var mockAppointmentRepository = new Mock<AppointmentRepository>(null); //Act mockAppointmentRepository.Setup(x => x.GetAsync(It.IsAny<CancellationToken>())).ReturnsAsync(It.IsAny<List<Appointment>>); var sut = new GetAppointmentsQueryHandler(mockAppointmentRepository.Object, null); var result = await sut.Handle(command, CancellationToken.None); //Act mockAppointmentRepository.Verify(x => x.GetAsync(It.IsAny<CancellationToken>()), Times.Once); mockAppointmentRepository.VerifyNoOtherCalls(); }