Пример #1
0
        private async Task ValidateSingleJoinAsync(EventJoinValidationDto validationDto, int orgId, string userId)
        {
            if (validationDto.SelectedOptions.All(x => x.Rule == OptionRules.IgnoreSingleJoin) &&
                validationDto.SelectedOptions.Count != 0 ||
                !validationDto.IsSingleJoin)
            {
                return;
            }

            var query = _eventsDbSet
                        .Include(e => e.EventParticipants.Select(x => x.EventOptions))
                        .Include(e => e.EventType)
                        .Where(e =>
                               e.OrganizationId == orgId &&
                               e.Id != validationDto.Id &&
                               SqlFunctions.DatePart(WeekOfYear, e.StartDate) == SqlFunctions.DatePart(WeekOfYear, validationDto.StartDate) &&
                               e.StartDate.Year == validationDto.StartDate.Year &&
                               e.EventParticipants.Any(p => p.ApplicationUserId == userId &&
                                                       p.AttendStatus == (int)AttendingStatus.Attending));

            query = string.IsNullOrEmpty(validationDto.SingleJoinGroupName)
                ? query.Where(x => x.EventType.Id == validationDto.EventTypeId)
                : query.Where(x => x.EventType.SingleJoinGroupName == validationDto.SingleJoinGroupName);

            var anyEventsAlreadyJoined = await query.AnyAsync(x => !x.EventParticipants.Any(y =>
                                                                                            y.ApplicationUserId == userId &&
                                                                                            y.EventOptions.All(z => z.Rule == OptionRules.IgnoreSingleJoin) &&
                                                                                            y.EventOptions.Count > 0));

            _eventValidationService.CheckIfUserExistsInOtherSingleJoinEvent(anyEventsAlreadyJoined);
        }