private void ValidateAppointmentInterval(DateTime initialDate, DateTime finalDate, int?id = null) { if (initialDate >= finalDate) { throw new DomainException("Appointment start must be before finish"); } var appointments = _repository .AppointmentsBetween(initialDate, finalDate); if (id.HasValue) { appointments = appointments.Where(a => a.Id != id); } if (appointments.Count() > 0) { throw new DomainException("Exists another appointment at selected interval"); } }