public async Task CancelFixedTestingPersonnelForDateAsync(CancelFixedTestingPersonnelForDateSpecDto specDto) { if (specDto == null) { throw new ArgumentNullException(nameof(specDto)); } Guid testingPersonnelId = await _testingPersonnelsRepository.GetTestingPersonnelIdByEmailAndTypeAsync(specDto.Email, TestingPersonnelType.Fixed) .ConfigureAwait(false); if (testingPersonnelId == Guid.Empty) { ValidationDictionary .AddModelError("Fixed testing personnel with email was not found", $"{specDto.Email}"); return; } var cancelationForDateExists = await _repository.DoesCancelationForTestingPersonnelAndDateExistAsync(testingPersonnelId, specDto.Date) .ConfigureAwait(false); if (cancelationForDateExists) { ValidationDictionary .AddModelError("Cancelation for testing personnel for date already exists", $"{specDto.Date.ToString(dateFormat, CultureInfo.InvariantCulture)}"); return; } await _repository.CancelFixedTestingPersonnelForDateAsync(testingPersonnelId, specDto.CanceledByUserId, specDto.Date.Date) .ConfigureAwait(false); }
public async Task CreateInvitationAsync(TestingPersonnelInvitationSpecDto specDto) { if (specDto == null) { throw new ArgumentNullException(nameof(specDto)); } var alreadySentInvitationForDate = await AnyAsync(x => x.InvitationForDate.Date == specDto.Date.Date) .ConfigureAwait(false); if (alreadySentInvitationForDate) { ValidationDictionary .AddModelError("Invitation for the date has already been sent", $"{specDto.Date.ToString(dateFormat, CultureInfo.InvariantCulture)}"); return; } var invitationDto = await AddAsync(specDto) .ConfigureAwait(false); var invitationReceivers = await _testingPersonnelsRepository .GetTestingPersonnelInvitationReceiversByWorkingAreaAsync(WorkingArea.Pooling, specDto.Date.DayOfWeek) .ConfigureAwait(false); foreach (var receiver in invitationReceivers) { var invitationConfirmationToken = await _invitationConfirmationTokensRepository .AddTestingPersonnelInvitationConfirmationTokenAsync(receiver.TestingPersonnelId, invitationDto.Id) .ConfigureAwait(false); await _mailSender.SendInvitationForPoolingAssignmentAsync(receiver.Email, invitationConfirmationToken, invitationDto.InvitationForDate) .ConfigureAwait(false); } }
public async Task <TestingPersonnelInvitationConfirmedShiftsDto> ConfirmInvitationAsync(TestingPersonnelInvitationConfirmDto confirmDto) { if (confirmDto == null) { throw new ArgumentNullException(nameof(confirmDto)); } var testingPersonnelAndInvitationData = await _invitationConfirmationTokensRepository .GetTestingPersonnelAndInvitationByConfirmationTokenAsync(confirmDto.Token) .ConfigureAwait(false); if (testingPersonnelAndInvitationData == null) { ValidationDictionary .AddModelError("The token is not valid", $"The provided token has been already used or doesn't exist."); return(null); } var doesConfirmationExist = await _testingPersonnelConfirmationsRepository .CheckIfConfirmationExistsForInvitationAndTestingPersonnelAsync(testingPersonnelAndInvitationData.InvitationId, testingPersonnelAndInvitationData.TestingPersonnelId) .ConfigureAwait(false); if (doesConfirmationExist) { ValidationDictionary .AddModelError("Confirmation already exists", $"Confirmation for this invitation already exists."); await _invitationConfirmationTokensRepository .DisposeInvitationConfirmationToken(confirmDto.Token) .ConfigureAwait(false); return(null); } var testingPersonnelConfirmSpecDto = new TestingPersonnelConfirmationSpecDto { InvitationId = testingPersonnelAndInvitationData.InvitationId, PersonnelId = testingPersonnelAndInvitationData.TestingPersonnelId, ShiftNumbers = confirmDto.Shifts }; var shiftsBooked = await _testingPersonnelConfirmationsRepository .AddConfirmationOfInvitationAsync(testingPersonnelConfirmSpecDto) .ConfigureAwait(false); await _invitationConfirmationTokensRepository .DisposeInvitationConfirmationToken(confirmDto.Token) .ConfigureAwait(false); if (shiftsBooked.ShiftsBooked.Any()) { await _mailSender .SendConfirmationForPoolingAssignmentAsync(testingPersonnelAndInvitationData.Email, testingPersonnelAndInvitationData.InvitationDate, shiftsBooked.ShiftsBooked) .ConfigureAwait(false); } return(shiftsBooked); }
public async Task <OrganizationDto> CreateOrganizationAsync(OrganizationSpecDto specDto) { if (specDto == null) { return(null); } _log.Info($"Creating new organization \"{specDto.Name}\"..."); var supportPerson = await _supportPersonOrgTypeDefaultRepository .GetSupportPersonByOrganizationTypeAsync(specDto.TypeId) .ConfigureAwait(false); specDto.SupportPersonId = supportPerson.SupportPersonId; var contactEmails = specDto.Contacts.Select(u => u.Email); var existingEmails = await GetExistingContactEmailsAsync(contactEmails, default) .ConfigureAwait(false); if (existingEmails.Any()) { ValidationDictionary.AddModelError("Already Existing Emails", string.Join(", ", existingEmails)); return(null); } var createdDto = await AddAsync <OrganizationSpecDto>(specDto) .ConfigureAwait(false); return(createdDto); }
public async Task CancelConfirmationAsync(TestingPersonnelCancelConfrimationSpecDto specDto) { if (specDto == null) { throw new ArgumentNullException(nameof(specDto)); } var invitationId = await _testingPersonnelInvitationsRepository.GetInvitationIdByDateAsync(specDto.Date.Date) .ConfigureAwait(false); if (invitationId == Guid.Empty) { ValidationDictionary .AddModelError("Invitation for date was not found", $"{specDto.Date.ToString(dateFormat, CultureInfo.InvariantCulture)}"); return; } var testingPersonnelId = await _testingPersonnelsRepository.GetTestingPersonnelIdByEmailAsync(specDto.Email) .ConfigureAwait(false); if (testingPersonnelId == Guid.Empty) { ValidationDictionary .AddModelError("Testing personnel with email was not found", $"{specDto.Email}"); return; } await _testingPersonnelConfirmationsRepository .CancelInvitationConfirmationAsync(invitationId, testingPersonnelId, specDto.CanceledByUserId) .ConfigureAwait(false); }
public async Task <CantonDto> CreateCantonWithSamplesCountAsync(CantonSpecDto cantonSpecDto) { if (cantonSpecDto == null) { throw new ArgumentNullException(nameof(cantonSpecDto)); } var doesCantonExist = await AnyAsync(c => c.Name == cantonSpecDto.Name || c.ShortName == cantonSpecDto.ShortName) .ConfigureAwait(false); if (doesCantonExist) { ValidationDictionary .AddModelError("Canton with this name or abbreviation already exists", $"{cantonSpecDto.Name}, {cantonSpecDto.ShortName}"); return(null); } Guid countryId = await _countriesRepository.GetCountryIdByNameAsync(CountryName) .ConfigureAwait(false); cantonSpecDto.CountryId = countryId; return(await AddAsync(cantonSpecDto) .ConfigureAwait(false)); }
private bool ValidateOrganizationForFollowUpUpdate(OrganizationDto organization, InfoSessionFollowUpStatus newStatus) { if (organization == default) { ValidationDictionary.AddModelError("OrganizationId", "Organization with specified Id does not exist"); return(false); } if (organization.FollowUpStatus == newStatus) { ValidationDictionary.AddModelError("No change", "Organization already has specified status"); return(false); } if (organization.FollowUpStatus == InfoSessionFollowUpStatus.NotSent) { ValidationDictionary.AddModelError("Follow up", "First send follow up in order to update it."); return(false); } return(true); }
public async Task <TestingPersonnelInvitationConfirmedShiftsDto> CreateConfirmationAsync(TestingPersonnelManuallyAddedConfirmationDto confirmDto) { if (confirmDto == null) { throw new ArgumentNullException(nameof(confirmDto)); } var invitationId = await _testingPersonnelInvitationsRepository.GetInvitationIdByDateAsync(confirmDto.Date.Date) .ConfigureAwait(false); if (invitationId == Guid.Empty) { ValidationDictionary .AddModelError("Invitation for date was not found", $"{confirmDto.Date.ToString(dateFormat, CultureInfo.InvariantCulture)}"); return(null); } var doesUserExist = await _testingPersonnelsRepository .AnyAsync(tp => tp.Id == confirmDto.TestingPersonnelId) .ConfigureAwait(false); if (!doesUserExist) { ValidationDictionary .AddModelError("Testing personnel was not found", $"Testing personnel was not found"); return(null); } var doesConfirmationExist = await _testingPersonnelConfirmationsRepository .CheckIfConfirmationExistsForSelectedShiftsAsync(invitationId, confirmDto.TestingPersonnelId, confirmDto.Shifts) .ConfigureAwait(false); if (doesConfirmationExist) { ValidationDictionary .AddModelError("Confirmation already exists for selected testing personnel", $"Confirmation already exists for selected testing personnel"); return(null); } var testingPersonnelConfirmSpecDto = new TestingPersonnelConfirmationSpecDto { InvitationId = invitationId, PersonnelId = confirmDto.TestingPersonnelId, ShiftNumbers = confirmDto.Shifts }; var confirmedShifts = await _testingPersonnelConfirmationsRepository .AddConfirmationOfInvitationAsync(testingPersonnelConfirmSpecDto) .ConfigureAwait(false); if (!confirmedShifts.ShiftsBooked.Any()) { ValidationDictionary .AddModelError("Shift capacity is already full", $"Shift capacity is already full"); return(null); } return(confirmedShifts); }
public async Task UpdateLamaCompanyProfileAsync(LamaCompanyProfileSpecDto lamaCompanyProfileDto, Guid loggedUserId) { if (lamaCompanyProfileDto == null) { throw new ArgumentNullException(nameof(lamaCompanyProfileDto)); } var userEmails = lamaCompanyProfileDto.Users.Select(u => u.Email); var userIds = lamaCompanyProfileDto.Users.Select(u => u.Id); var existingEmails = await GetExistingContactEmailsAsync(userEmails, lamaCompanyProfileDto.Id) .ConfigureAwait(false); if (existingEmails.Any()) { ValidationDictionary.AddModelError("Already existing emails", string.Join(", ", existingEmails)); return; } if (!userIds.Contains(loggedUserId)) { ValidationDictionary.AddModelError("Delete yourself", "You cannot delete yourself from the contact list of the organization"); return; } foreach (var lamaUser in lamaCompanyProfileDto.Users) { if (lamaUser.SupportDefaultOrganizationTypes != null) { var organizationTypeIds = lamaUser.SupportDefaultOrganizationTypes.Select(x => x.OrganizationTypeId); if (!CheckForDuplicates(organizationTypeIds)) { ValidationDictionary .AddModelError($"Cannot set duplicate organization types for one user", lamaUser.Id.ToString()); } } } var deletedUsersAssignedToOrganizationEmails = await GetDeletedUsersEmailsThatHaveAssignedOrganizationAsync(userIds, lamaCompanyProfileDto.Id) .ConfigureAwait(false); if (deletedUsersAssignedToOrganizationEmails.Any()) { ValidationDictionary .AddModelError("User that you want to delete is assigned to an Organization", string.Join(", ", deletedUsersAssignedToOrganizationEmails)); } if (!ValidationDictionary.IsValid()) { return; } await _lamaCompaniesRepository .UpdateLamaCompanyProfileAsync(lamaCompanyProfileDto) .ConfigureAwait(false); }
private bool ValidateOrganizationForOnboarding(OrganizationDto organization, Guid?organizationContactPersonId) { if (organization == null) { ValidationDictionary.AddModelError("Organization", "Organization with specified Id does not exist"); return(false); } var isValid = true; if (organization.OrganizationType.Id == _smeOrganizationTypeId) { if (!organization.FirstTestTimestamp.HasValue || organization.FirstTestTimestamp == default(DateTime)) { ValidationDictionary.AddModelError("First Test Date", "First Test is required."); isValid = false; } if (string.IsNullOrWhiteSpace(organization.Area)) { ValidationDictionary.AddModelError("Organization Area", "Organization Area is required."); isValid = false; } } else if (organization.OrganizationType.Id == _companyOrganizationTypeId) { if (organization.SupportPerson == null) { ValidationDictionary.AddModelError("Organization Support Person", "Organization Support Person is required."); isValid = false; } } else if (organization.OrganizationType.Id == _campOrganizationTypeId) { if (organization.SupportPerson == null) { ValidationDictionary.AddModelError("Organization Support Person", "Organization Support Person is required."); isValid = false; } if (!organization.Contacts.Any(c => c.Id == organizationContactPersonId)) { ValidationDictionary.AddModelError("Organization Contact Person not found", "Organization Contact Person not found."); isValid = false; } } return(isValid); }
public async Task SendEmailForEpaadAsync(OrganizationSendEmailForEpaadDto dto) { if (dto == null) { throw new ArgumentNullException(nameof(dto)); } var organizationDto = await _organizationsRepository .GetByIdAsync(dto.OrganizationId) .ConfigureAwait(false); if (organizationDto == null) { ValidationDictionary .AddModelError("Organization not found", $"Organization not found."); return; } if (organizationDto.OrganizationTypeId != campOrganizationTypeId && !organizationDto.IsStaticPooling) { ValidationDictionary .AddModelError("Organization type is not a Camp or organization is not with Static Pooling", $"Organization type is not a Camp or organization is not with Static Pooling."); return; } var city = await _citiesRepository .GetCityEpaadDtoAsync(organizationDto.CityId) .ConfigureAwait(false); var parameters = new Dictionary <string, string> { { "organizationName", organizationDto.Name }, { "country", city.CountryShortName }, { "canton", DefaultEpaadOrganizationState }, { "zip", organizationDto.Zip ?? city.ZipCode }, { "city", city.Name }, { "street", organizationDto.Address }, { "email", string.Join(", ", organizationDto.Contacts.Select(c => c.Email)) }, { "numberOfSamples", organizationDto.NumberOfSamples.ToString(CultureInfo.InvariantCulture) }, { "numberOfPools", organizationDto.NumberOfPools != null?organizationDto.NumberOfPools.ToString() : zeroNumberOfPools }, { "activeSince", organizationDto.CreatedOn.ToString("d", CultureInfo.CreateSpecificCulture("de-CH")) }, { "organizationType", organizationTypes[organizationDto.OrganizationType.Id] } }; foreach (var receiver in dto.Receivers) { await _mailSender.SendEmailForEpaadAsync(receiver, parameters).ConfigureAwait(false); } }
public async Task DeleteCantonAsync(Guid id) { var cantonToDelete = await GetByIdAsync(id) .ConfigureAwait(false); if (cantonToDelete.Name == BaselCantonName && cantonToDelete.ShortName == BaselCantonShortName) { ValidationDictionary .AddModelError("The default canton can not be deleted", $"{cantonToDelete.Name}, {cantonToDelete.ShortName}"); return; } await DeleteAsync(id) .ConfigureAwait(false); }
public async Task UpdateOrganizationProfileAsync(OrganizationProfileSpecDto dto, Guid userId) { if (dto == null) { throw new ArgumentNullException(nameof(dto)); } var contactEmails = dto.Contacts.Select(u => u.Email); var contactUserIds = dto.Contacts.Select(u => u.Id); var existingEmails = await GetExistingContactEmailsAsync(contactEmails, dto.Id) .ConfigureAwait(false); if (existingEmails.Any()) { ValidationDictionary.AddModelError("Already Existing Emails", string.Join(", ", existingEmails)); return; } var isLoggedUserPartOfOrganization = await _organizationsRepository .IsUserPartOfOrganizationAsync(dto.Id, userId) .ConfigureAwait(false); if (isLoggedUserPartOfOrganization && !contactUserIds.Contains(userId)) { ValidationDictionary .AddModelError("Delete yourself", "You cannot delete yourself from the contact list of the organization"); return; } await _organizationsRepository .UpdateOrganizationProfileAsync(dto) .ConfigureAwait(false); var orgStatusCalculationDto = await _organizationsRepository .GetOrganizationStatusCalculationDataAsync(dto.Id) .ConfigureAwait(false); var orgStatus = CalculateOrganizationStatus(orgStatusCalculationDto, true); await _organizationsRepository .UpdateOrganizationStatusAsync(dto.Id, orgStatus) .ConfigureAwait(false); }
public async Task CreateConfirmationWithoutInvitationAsync(TestingPersonnelConfirmationsWithoutInvitationSpecDto specDto) { if (specDto == null) { throw new ArgumentNullException(nameof(specDto)); } var invitationExists = await _testingPersonnelInvitationsRepository.AnyAsync(i => i.InvitationForDate.Date == specDto.Date.Date) .ConfigureAwait(false); if (invitationExists) { ValidationDictionary .AddModelError("Invitation for selected date already exists", $"{specDto.Date.ToString(dateFormat, CultureInfo.InvariantCulture)}"); return; } var testingPersonnelExists = await _testingPersonnelsRepository .AnyAsync(tp => tp.Id == specDto.TestingPersonnelId && tp.Type == TestingPersonnelType.Temporary) .ConfigureAwait(false); if (!testingPersonnelExists) { ValidationDictionary .AddModelError("Testing personnel does not exist or is not of Temporary type", $"Testing personnel does not exist or is not of Temporary type"); return; } bool confirmationForDateExists = await _repository.DoesConfirmationExistAsync(specDto.TestingPersonnelId, specDto.Date, specDto.ShiftNumber) .ConfigureAwait(false); if (confirmationForDateExists) { ValidationDictionary .AddModelError("Confirmation for testing personnel for date and shift already exists", $"Confirmation for testing personnel for date and shift already exists"); return; } await _repository.AddConfirmationAsync(specDto.TestingPersonnelId, specDto.Date, specDto.ShiftNumber) .ConfigureAwait(false); }
public async Task IncreaseShiftCountAsync(TestingPersonnelInvitationIncreaseShiftSpecDto specDto) { if (specDto == null) { throw new ArgumentNullException(nameof(specDto)); } var doesInvitationExist = await _testingPersonnelInvitationsRepository.AnyAsync(i => i.Id == specDto.InvitationId) .ConfigureAwait(false); if (!doesInvitationExist) { ValidationDictionary .AddModelError("The invitation was not found", $"The invitation was not found"); return; } await _testingPersonnelInvitationsRepository.IncreaseShiftCountAsync(specDto.InvitationId, specDto.ShiftNumber, capacityToAdd) .ConfigureAwait(false); }
private bool ValidateOrganizationForNewFollowUp(OrganizationDto organization) { if (organization == default) { ValidationDictionary.AddModelError("OrganizationId", "Organization with specified Id does not exist"); return(false); } if (organization.FollowUpStatus == InfoSessionFollowUpStatus.Accepted || organization.FollowUpStatus == InfoSessionFollowUpStatus.Declined) { ValidationDictionary.AddModelError("FollowUp Status", "Organization has already accepted or declined the follow up email"); return(false); } return(true); }
public async Task UpdateCantonWithSamplesCountAsync(CantonDto cantonDto) { if (cantonDto == null) { throw new ArgumentNullException(nameof(cantonDto)); } var cantonToUpdate = await GetByIdAsync(cantonDto.Id) .ConfigureAwait(false); if (cantonToUpdate == null) { ValidationDictionary .AddModelError("Canton with ID does not exist", $"{cantonDto.Id}"); return; } if (cantonToUpdate.Name == BaselCantonName && cantonToUpdate.ShortName == BaselCantonShortName) { ValidationDictionary .AddModelError("The default canton can not be updated", $"{cantonToUpdate.Name}, {cantonToUpdate.ShortName}"); return; } var doesCantonExist = await AnyAsync(c => (c.Name == cantonDto.Name || c.ShortName == cantonDto.ShortName) && c.Id != cantonDto.Id) .ConfigureAwait(false); if (doesCantonExist) { ValidationDictionary .AddModelError("Canton with this name or abbreviation already exists", $"{cantonDto.Name}, {cantonDto.ShortName}"); return; } await UpdateAsync(cantonDto) .ConfigureAwait(false); }
public async Task <TestingPersonnelDto> CreateTestingPersonnelAsync(TestingPersonnelSpecDto specDto) { if (specDto == null) { throw new ArgumentNullException(nameof(specDto)); } var existingTestingPersonnelId = await _testingPersonnelsRepository.GetTestingPersonnelIdByEmailAsync(specDto.Email) .ConfigureAwait(false); if (existingTestingPersonnelId != Guid.Empty) { ValidationDictionary .AddModelError("Testing personnel with this email already exists", $"{specDto.Email}"); return(null); } var testingPersonnel = await AddAsync(specDto) .ConfigureAwait(false); return(testingPersonnel); }
public async Task ChangeFollowUpStatusAsync(InfoSessionFollowUpResponseSpecDto specDto) { if (specDto == default) { throw new ArgumentNullException(nameof(specDto)); } var currentStatus = await _infoSessionFollowUpRepository.GetStatusByTokenAsync(specDto.Token) .ConfigureAwait(false); if (currentStatus == InfoSessionFollowUpStatus.Accepted || currentStatus == InfoSessionFollowUpStatus.Declined) { ValidationDictionary.AddModelError("FollowUp Status", "Organization has already accepted or declined the follow up email"); return; } await _infoSessionFollowUpRepository.UpdateStatusAsync(specDto.Token, specDto.IsAccepted? InfoSessionFollowUpStatus.Accepted : InfoSessionFollowUpStatus.Declined).ConfigureAwait(false); }
public async Task PushOrganizationToEPaadAsync(OrganizationDto dto) { if (dto == null) { throw new ArgumentNullException(nameof(dto)); } if (dto.OrganizationTypeId == campOrganizationTypeId) { ValidationDictionary .AddModelError("Camps can not be pushed to Epaad", $"Camps can not be pushed to Epaad."); return; } var existinOrganizationType = await _organizationTypesRepository .AnyOrganizationTypeAsync(x => x.Id == dto.OrganizationTypeId) .ConfigureAwait(false); if (!existinOrganizationType) { ValidationDictionary .AddModelError("Organization type not found", $"Organization type with that id doesn't exist."); return; } var city = await _citiesRepository .GetCityEpaadDtoAsync(dto.CityId) .ConfigureAwait(false); var organizationCreationDate = await _organizationsRepository .GetOrganizationCreationDateAsync(dto.Id) .ConfigureAwait(false); var epaadOrgDto = new PushEpaadOrganizationDto { ContactPersonEmail = dto.Contacts.First().Email, ContactPersonName = dto.Contacts.First().Name, ContactPersonPhone = dto.Contacts.First().PhoneNumber, OrganizationTypeId = dto.OrganizationTypeId == smeOrganizationTypeId ? companyOrganizationTypeId : dto.OrganizationTypeId, OrganizationName = dto.Name, City = city.Name, CountryShortName = city.CountryShortName, Zip = dto.Zip ?? city.ZipCode, FilterText = dto.OrganizationShortcutName, State = DefaultEpaadOrganizationState, ActiveSince = organizationCreationDate, Address = dto.Address, PoolLastname = dto.Name, PoolFirstName = dto.OrganizationTypeId == smeOrganizationTypeId ? smeOrgTypePoolFirstName : default }; var response = await _epaadService .PushOrganizationToEpaadAsync(epaadOrgDto) .ConfigureAwait(false); if (response == null || !response.EpaadId.HasValue) { #pragma warning disable CA2208 // Instantiate argument exceptions correctly throw new ArgumentNullException(paramName: "Epaad response"); #pragma warning restore CA2208 // Instantiate argument exceptions correctly } await _organizationsRepository .UpdateEpaadIdAsync(response.EpaadId.Value, dto.Id) .ConfigureAwait(false); }
public async Task UpdateOrganizationAsync(OrganizationDto dto, Guid loggedUserId) { if (dto == null) { throw new ArgumentNullException(nameof(dto)); } var organizationInDb = await _organizationsRepository .GetByIdAsync(dto.Id) .ConfigureAwait(false); if (organizationInDb.RegisteredEmployees > 0 && organizationInDb.OrganizationShortcutName != dto.OrganizationShortcutName) { ValidationDictionary.AddModelError("Organization shortcut name cannot be changed", "Organization shortcut name cannot be changed when registered employees are greater than 0."); return; } if ((dto.ExclusionStartDate.HasValue && !dto.ExclusionEndDate.HasValue) || (!dto.ExclusionStartDate.HasValue && dto.ExclusionEndDate.HasValue)) { ValidationDictionary.AddModelError("Both exclusion dates must have value", "One of the exclusion dates has value and the other does not."); return; } var existinOrganizationType = await _organizationTypesRepository .AnyOrganizationTypeAsync(x => x.Id == dto.OrganizationTypeId) .ConfigureAwait(false); if (!existinOrganizationType) { ValidationDictionary .AddModelError("Organization type not found", $"Organization type with that id doesn't exist."); return; } var contactEmails = dto.Contacts.Select(u => u.Email); var contactUserIds = dto.Contacts.Select(u => u.Id); var existingEmails = await GetExistingContactEmailsAsync(contactEmails, dto.Id) .ConfigureAwait(false); if (existingEmails.Any()) { ValidationDictionary.AddModelError("Already Existing Emails", string.Join(", ", existingEmails)); return; } var isLoggedUserPartOfOrganization = await _organizationsRepository .IsUserPartOfOrganizationAsync(dto.Id, loggedUserId) .ConfigureAwait(false); if (isLoggedUserPartOfOrganization && !contactUserIds.Contains(loggedUserId)) { ValidationDictionary .AddModelError("Delete yourself", "You cannot delete yourself from the contact list of the organization"); return; } dto.LastUpdatedOn = DateTime.UtcNow; await UpdateAsync(dto).ConfigureAwait(false); var orgStatusCalculationDto = await _organizationsRepository .GetOrganizationStatusCalculationDataAsync(dto.Id) .ConfigureAwait(false); dto.Status = CalculateOrganizationStatus(orgStatusCalculationDto, true); await _organizationsRepository .UpdateOrganizationStatusAsync(dto.Id, dto.Status) .ConfigureAwait(false); /*var organizationEpaadId = await _organizationsRepository * .GetOrganizationEpaadIdAsync(dto.Id) * .ConfigureAwait(false); * * if (organizationEpaadId.HasValue) * { * await UpdateOrganizationinEpaadAsync(organizationEpaadId.Value, dto) * .ConfigureAwait(false); * }*/ }
public async Task SendInfoSessionFollowUpEmailAsync(InfoSessionFollowUpSpecDto specDto) { if (specDto == default) { throw new ArgumentNullException(nameof(specDto)); } var organization = await _organizationsRepository .GetByIdAsync(specDto.OrganizationId).ConfigureAwait(false); if (organization.OrganizationTypeId == _smeOrganizationTypeId) { if (!ValidateOrganizationForOnboarding(organization, specDto.OrganizationContactPersonId)) { return; } await SendSMEOnboardingEmailAsync(specDto, organization).ConfigureAwait(false); await _organizationsRepository.UpdateIsOnboardingEmailSent(true, organization.Id).ConfigureAwait(false); } else if (organization.OrganizationTypeId == _companyOrganizationTypeId) { if (!ValidateOrganizationForOnboarding(organization, specDto.OrganizationContactPersonId)) { return; } await SendCompanyOnboardingEmailAsync(specDto, organization).ConfigureAwait(false); await _organizationsRepository.UpdateIsOnboardingEmailSent(true, organization.Id).ConfigureAwait(false); } else if (organization.OrganizationTypeId == _campOrganizationTypeId) { if (!ValidateOrganizationForOnboarding(organization, specDto.OrganizationContactPersonId)) { return; } await SendCampOnboardingEmailAsync(specDto, organization).ConfigureAwait(false); await _organizationsRepository.UpdateIsOnboardingEmailSent(true, organization.Id).ConfigureAwait(false); } else { if (string.IsNullOrEmpty(specDto.Message)) { ValidationDictionary.AddModelError("Message", "Message must not be null or empty space"); return; } if (!ValidateOrganizationForNewFollowUp(organization)) { return; } string generatedToken = await AddFollowUpAsync(organization).ConfigureAwait(false); await SendInfoSessionFollowUpEmailAsync(specDto, generatedToken).ConfigureAwait(false); } }