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); }
public async Task SendInvitationAsync(EventJoinValidationDto @event, IEnumerable <string> userIds, int orgId) { var emails = await _usersDbSet .Where(u => userIds.Contains(u.Id)) .Select(u => u.Email) .ToListAsync(); var calendarEvent = MapToCalendarEvent(@event); await AddEventLinkToDescriptionAsync(calendarEvent, @event.Id, orgId); var calendar = new Ical.Net.Calendar(); calendar.Events.Add(calendarEvent); var serializedCalendar = new CalendarSerializer().SerializeToString(calendar); var calByteArray = Encoding.UTF8.GetBytes(serializedCalendar); var emailDto = new EmailDto(emails, $"Invitation: {@event.Name} @ {@event.StartDate.ToString("d")}", ""); using (var stream = new MemoryStream(calByteArray)) { emailDto.Attachment = new MailAttachment(stream, "invite.ics"); await _mailingService.SendEmailAsync(emailDto); } }
public void CheckIfAttendOptionIsAllowed(int attendStatus, EventJoinValidationDto @event) { if (attendStatus == (int)AttendingStatus.MaybeAttending && [email protected]) { throw new EventException(PremiumErrorCodes.EventAttendTypeIsNotAllowed); } if (attendStatus == (int)AttendingStatus.NotAttending && [email protected]) { throw new EventException(PremiumErrorCodes.EventAttendTypeIsNotAllowed); } }
MapToUserEventAttendStatusChangeEmailDto(ApplicationUser user, EventJoinValidationDto eventJoinValidationDto, string managerEmail) { return(new UserEventAttendStatusChangeEmailDto { FirstName = user.FirstName, LastName = user.LastName, ManagerEmail = managerEmail, ManagerId = user.ManagerId, EventName = eventJoinValidationDto.Name, EventId = eventJoinValidationDto.Id, OrganizationId = user.OrganizationId, EventStartDate = eventJoinValidationDto.StartDate, EventEndDate = eventJoinValidationDto.EndDate }); }
private static CalendarEvent MapToCalendarEvent(EventJoinValidationDto @event) { var calEvent = new CalendarEvent { Uid = @event.Id.ToString(), Location = @event.Location, Summary = @event.Name, Description = @event.Description, Organizer = new Organizer { CommonName = BusinessLayerConstants.DefaultEmailLinkName, Value = new Uri($"mailto:{BusinessLayerConstants.FromEmailAddress}") }, Start = new CalDateTime(@event.StartDate, "UTC"), End = new CalDateTime(@event.EndDate, "UTC"), Status = EventStatus.Confirmed }; return(calEvent); }
private async Task NotifyManagersAsync(EventJoinDto joinDto, EventJoinValidationDto eventJoinValidationDto) { var users = await _usersDbSet .Where(user => joinDto.ParticipantIds .Contains(user.Id) && joinDto.OrganizationId == user.OrganizationId) .ToListAsync(); var managerIds = users.Select(user => user.ManagerId).ToHashSet(); var managers = await _usersDbSet .Where(manager => managerIds.Contains(manager.Id)) .ToDictionaryAsync(manager => manager.Id, manager => manager.Email); if (!managers.Any()) { return; } foreach (var user in users) { if (user.ManagerId == null) { return; } if (!managers.TryGetValue(user.ManagerId, out var managerEmail)) { continue; } var userAttendStatusDto = MapToUserEventAttendStatusChangeEmailDto(user, eventJoinValidationDto, managerEmail); _asyncRunner.Run <IEventNotificationService>( async notifier => await notifier.NotifyManagerAboutEventAsync(userAttendStatusDto, true), _uow.ConnectionName); } }
private async Task AddParticipantWithStatusAsync(string userId, int attendingStatus, string attendComment, EventJoinValidationDto eventDto) { var timeStamp = _systemClock.UtcNow; var participant = await _eventParticipantsDbSet.FirstOrDefaultAsync(p => p.EventId == eventDto.Id && p.ApplicationUserId == userId); if (participant != null) { participant.AttendStatus = attendingStatus; participant.AttendComment = attendComment; participant.Modified = timeStamp; participant.ModifiedBy = userId; } else { var newParticipant = new EventParticipant { ApplicationUserId = userId, Created = timeStamp, CreatedBy = userId, EventId = eventDto.Id, Modified = timeStamp, ModifiedBy = userId, AttendComment = attendComment, AttendStatus = attendingStatus }; _eventParticipantsDbSet.Add(newParticipant); } }