Example #1
0
        public async Task <ShortContactInfoDto> GetSupportPersonByOrganizationTypeAsync(int organizationTypeId)
        {
            await using var context = ContextFactory.CreateDataContext(null);
            var items = context.SupportPersonOrgTypeDefaultMappings;

            var defaulSupportPersons = await items.Where(
                sup => sup.OrganizationTypeId == organizationTypeId)
                                       .Select(x => new ShortContactInfoDto
            {
                SupportPersonId = x.UserId,
                Name            = _aesCryptography.Decrypt(x.User.Name)
            }).ToListAsync()
                                       .ConfigureAwait(false);

            var defaulSupportPerson = defaulSupportPersons.OrderBy(sup => sup.Name).FirstOrDefault();

            if (defaulSupportPerson == null)
            {
                return(await items.Select(x =>
                                          new ShortContactInfoDto
                {
                    SupportPersonId = x.UserId,
                    Name = _aesCryptography.Decrypt(x.User.Name)
                })
                       .FirstAsync()
                       .ConfigureAwait(false));
            }

            return(defaulSupportPerson);
        }
Example #2
0
        public async Task <JWTokenUserDataDto> GenerateJwtUserDataAsync(Guid userId)
        {
            await using var context = ContextFactory.CreateDataContext(null);
            var userInfo = await context.Users
                           .Where(item => item.Id == userId)
                           .Select(x => new
            {
                LamaCompany    = x.LamaCompany,
                OrganizationId = x.OrganizationId,
                Organization   = x.Organization,
                Email          = _aESCryptography.Decrypt(x.Email),
                UserName       = _aESCryptography.Decrypt(x.Name)
            })
                           .FirstAsync()
                           .ConfigureAwait(false);

            var jwtUserData = new JWTokenUserDataDto {
                UserId = userId
            };

            if (userInfo.LamaCompany != null)
            {
                jwtUserData.RoleType = userInfo.LamaCompany.RoleType;
                jwtUserData.OrganizationOrCompanyId = userInfo.LamaCompany.Id;
                jwtUserData.Email    = userInfo.Email;
                jwtUserData.UserName = userInfo.UserName;
            }
            else
            {
                jwtUserData.RoleType = RoleType.Organization;
                jwtUserData.OrganizationOrCompanyId = userInfo.OrganizationId ?? Guid.Empty;
                jwtUserData.OrganizationTypeId      = userInfo.Organization?.OrganizationTypeId;
                jwtUserData.Email    = userInfo.Email;
                jwtUserData.UserName = userInfo.UserName;
            }

            return(jwtUserData);
        }
        public async Task <List <string> > GetDeletedUsersEmailsThatHaveAssignedOrganizationAsync(IEnumerable <Guid> usersIds, Guid lamaCompanyId)
        {
            if (usersIds == null)
            {
                throw new ArgumentNullException(nameof(usersIds));
            }

            await using var context = ContextFactory.CreateDataContext(null);

            var lamaCompanyUsersEmails = await context.LamaCompanies.AsNoTracking()
                                         .Include(x => x.Users)
                                         .ThenInclude(x => x.SupportOrganizations)
                                         .Where(item => item.Id == lamaCompanyId)
                                         .Select(item => item.Users
                                                 .Where(u => !usersIds.Contains(u.Id) && u.SupportOrganizations.Any())
                                                 .Select(u => _aESCryptography.Decrypt(u.Email)))
                                         .FirstOrDefaultAsync()
                                         .ConfigureAwait(false);

            return(lamaCompanyUsersEmails.ToList());
        }
        public async Task <TestingPersonnelAndInvitationDto> GetTestingPersonnelAndInvitationByConfirmationTokenAsync(string token)
        {
            await using var context = ContextFactory.CreateDataContext(null);
            var items = context.TestingPersonnelInvitationConfirmationTokens;
            var invitationConfToken = await items
                                      .Include(x => x.TestingPersonnel)
                                      .Include(x => x.TestingPersonnelInvitation)
                                      .FirstOrDefaultAsync(t => t.Token == token && !t.IsUsed)
                                      .ConfigureAwait(false);

            if (invitationConfToken == null)
            {
                return(null);
            }

            return(new TestingPersonnelAndInvitationDto
            {
                TestingPersonnelId = invitationConfToken.TestingPersonnelId,
                InvitationId = invitationConfToken.TestingPersonnelInvitationId,
                Email = _aesCryptography.Decrypt(invitationConfToken.TestingPersonnel?.Email),
                InvitationDate = invitationConfToken.TestingPersonnelInvitation.InvitationForDate
            });
        }
        public async Task <TestsDataWithIsEarliestDateDto> GetTestsDataDtoAsync(DateTime startDate, bool isForOneDate)
        {
            const int companyOrganizationId      = 82000;
            const int pharmacyOrganizationId     = 82001;
            const int nursingHomesOrganizationId = 82003;
            const int hospitalOrganizationId     = 82004;
            const int smeOrganizationId          = 99990;
            const int campOrganizationId         = 82006;

            startDate = startDate.Date;
            var endDate = startDate.AddDays(DaysPeriod);

            if (isForOneDate)
            {
                endDate = startDate.AddDays(OneDayPeriod);
            }

            await using var context = ContextFactory.CreateDataContext(null);
            var orgs = await context.Organizations
                       .Where(x => x.Status != OrganizationStatus.NotActive &&
                              x.OrganizationTypeId != campOrganizationId &&
                              ((x.FirstTestTimestamp.HasValue && x.FirstTestTimestamp.Value.Date < endDate.Date) ||
                               (x.SecondTestTimestamp.HasValue && x.SecondTestTimestamp.Value.Date < endDate.Date) ||
                               (x.ThirdTestTimestamp.HasValue && x.ThirdTestTimestamp.Value.Date < endDate.Date) ||
                               (x.FourthTestTimestamp.HasValue && x.FourthTestTimestamp.Value.Date < endDate.Date) ||
                               (x.FifthTestTimestamp.HasValue && x.FifthTestTimestamp.Value.Date < endDate.Date)))
                       .Select(x => new
            {
                TotalSamples        = x.NumberOfSamples,
                RegisteredEmployees = x.RegisteredEmployees,
                FirstDate           = x.FirstTestTimestamp,
                SecondDate          = x.SecondTestTimestamp,
                ThirdDate           = x.ThirdTestTimestamp,
                FourthDate          = x.FourthTestTimestamp,
                FifthDate           = x.FifthTestTimestamp,
                ExclusionStartDate  = x.ExclusionStartDate,
                ExclusionEndDate    = x.ExclusionEndDate,
                IsCompanyOrPharmacyOrNursingOrganization = x.OrganizationTypeId == companyOrganizationId || x.OrganizationTypeId == pharmacyOrganizationId ||
                                                           x.OrganizationTypeId == nursingHomesOrganizationId || x.OrganizationTypeId == hospitalOrganizationId ||
                                                           x.OrganizationTypeId == smeOrganizationId,
                IsNursery = x.OrganizationTypeId == nursingHomesOrganizationId
            })
                       .ToListAsync()
                       .ConfigureAwait(false);

            var invitations = await context.TestingPersonnelInvitations
                              .Where(x => x.InvitationForDate >= startDate.Date && x.InvitationForDate < endDate.Date)
                              .Include(x => x.TestingPersonnelConfirmations)
                              .ThenInclude(x => x.TestingPersonnel)
                              .Select(x => new
            {
                InvitationId   = x.Id,
                InvitationDate = x.InvitationForDate,
                Shift1         = new
                {
                    RequiredPersonnelCountShift = x.RequiredPersonnelCountShift1,
                    ShiftNumber = ShiftNumber.First,
                    ConfirmedNotCanceledEmployeesCount = x.TestingPersonnelConfirmations.Where(conf => conf.ShiftNumber == ShiftNumber.First && !conf.CanceledOn.HasValue).Count(),
                    ConfirmedEmployees = x.TestingPersonnelConfirmations.Where(conf => conf.ShiftNumber == ShiftNumber.First).OrderByDescending(conf => conf.CanceledOn)
                                         .Select(c => new TestingPersonnelTestDataDto
                    {
                        FirstName  = _aesCryptography.Decrypt(c.TestingPersonnel.FirstName),
                        LastName   = _aesCryptography.Decrypt(c.TestingPersonnel.LastName),
                        Email      = _aesCryptography.Decrypt(c.TestingPersonnel.Email),
                        IsCanceled = c.CanceledOn.HasValue
                    })
                },
                Shift2 = new
                {
                    RequiredPersonnelCountShift = x.RequiredPersonnelCountShift2,
                    ShiftNumber = ShiftNumber.Second,
                    ConfirmedNotCanceledEmployeesCount = x.TestingPersonnelConfirmations.Where(conf => conf.ShiftNumber == ShiftNumber.Second && !conf.CanceledOn.HasValue).Count(),
                    ConfirmedEmployees = x.TestingPersonnelConfirmations.Where(conf => conf.ShiftNumber == ShiftNumber.Second).OrderByDescending(conf => conf.CanceledOn)
                                         .Select(c => new TestingPersonnelTestDataDto
                    {
                        FirstName  = _aesCryptography.Decrypt(c.TestingPersonnel.FirstName),
                        LastName   = _aesCryptography.Decrypt(c.TestingPersonnel.LastName),
                        Email      = _aesCryptography.Decrypt(c.TestingPersonnel.Email),
                        IsCanceled = c.CanceledOn.HasValue
                    })
                }
            })
                              .ToListAsync()
                              .ConfigureAwait(false);

            var fixedPersonnel = await context.TestingPersonnels
                                 .Where(x => x.Type == TestingPersonnelType.Fixed && x.TestingPersonnelWorkingAreas.Any(wa => wa.Area == WorkingArea.Pooling))
                                 .Include(x => x.FixedTestingPersonnelCancelations)
                                 .ToListAsync()
                                 .ConfigureAwait(false);

            var cantonsWithWeekdaysSamples = await context.Cantons
                                             .Where(c => c.CantonWeekdaysSamples != null)
                                             .Include(c => c.CantonWeekdaysSamples)
                                             .OrderBy(c => c.Name)
                                             .ToListAsync()
                                             .ConfigureAwait(false);

            var confirmationsWithoutInvitation = await context.TestingPersonnelConfirmationsWithoutInvitation
                                                 .Where(c => c.Date >= startDate.Date && c.Date < endDate.Date)
                                                 .Include(c => c.TestingPersonnel)
                                                 .ToListAsync()
                                                 .ConfigureAwait(false);

            var testDatesValues = new List <TestsDataDto>();

            var currentDate = startDate;

            while (currentDate < endDate)
            {
                var invitation = invitations.FirstOrDefault(x => x.InvitationDate.Date == currentDate.Date);
                if (currentDate.DayOfWeek != DayOfWeek.Saturday && currentDate.DayOfWeek != DayOfWeek.Sunday)
                {
                    var testsDataValue = new TestsDataDto
                    {
                        InvitationId          = invitation?.InvitationId,
                        Date                  = currentDate,
                        InvitationAlreadySent = invitation != null,
                        Shifts                = new List <TestDataPerShiftDto>()
                        {
                            new TestDataPerShiftDto()
                            {
                                ShiftNumber = invitation == null ? ShiftNumber.First : invitation.Shift1.ShiftNumber,
                                RequiredPersonnelCountShift        = invitation == null ? 0 : invitation.Shift1.RequiredPersonnelCountShift,
                                ConfirmedNotCanceledEmployeesCount = invitation == null ? 0 : invitation.Shift1.ConfirmedNotCanceledEmployeesCount,
                                ConfirmedEmployees         = invitation == null ? new List <TestingPersonnelTestDataDto>() : invitation.Shift1.ConfirmedEmployees.DistinctBy(x => x.Email).ToList(),
                                FixedEmployees             = GetFixedTestingPersonnelForWeekday(fixedPersonnel, currentDate, Shift.First),
                                ConfirmedWithoutInvitation = GetConfirmedTestingPersonnelWithoutInvitationForDateAndShift(confirmationsWithoutInvitation, currentDate, ShiftNumber.First)
                            },
                            new TestDataPerShiftDto()
                            {
                                ShiftNumber = invitation == null ? ShiftNumber.Second : invitation.Shift2.ShiftNumber,
                                RequiredPersonnelCountShift        = invitation == null ? 0 : invitation.Shift2.RequiredPersonnelCountShift,
                                ConfirmedNotCanceledEmployeesCount = invitation == null ? 0 : invitation.Shift2.ConfirmedNotCanceledEmployeesCount,
                                ConfirmedEmployees         = invitation == null ? new List <TestingPersonnelTestDataDto>() : invitation.Shift2.ConfirmedEmployees.DistinctBy(x => x.Email).ToList(),
                                FixedEmployees             = GetFixedTestingPersonnelForWeekday(fixedPersonnel, currentDate, Shift.Second),
                                ConfirmedWithoutInvitation = GetConfirmedTestingPersonnelWithoutInvitationForDateAndShift(confirmationsWithoutInvitation, currentDate, ShiftNumber.Second)
                            }
                        },
                        CantonsSamplesData = GetTestDataPerCantonAndWeekday(cantonsWithWeekdaysSamples, currentDate)
                    };
                    testDatesValues.Add(testsDataValue);

                    foreach (var organization in orgs)
                    {
                        if ((CheckIfInTestDate(organization.FirstDate, currentDate) ||
                             CheckIfInTestDate(organization.SecondDate, currentDate) ||
                             CheckIfInTestDate(organization.ThirdDate, currentDate) ||
                             CheckIfInTestDate(organization.FourthDate, currentDate) ||
                             CheckIfInTestDate(organization.FifthDate, currentDate)) &&
                            !CheckIfDateIsExcluded(organization.ExclusionStartDate, organization.ExclusionEndDate, currentDate))
                        {
                            var allTestingDates = new List <DateTime?>();
                            allTestingDates.Add(organization.FirstDate);
                            allTestingDates.Add(organization.SecondDate);
                            allTestingDates.Add(organization.ThirdDate);
                            allTestingDates.Add(organization.FourthDate);
                            allTestingDates.Add(organization.FifthDate);

                            var countOfTestingDates = allTestingDates.Where(x => x.HasValue).Count();
                            var avgSample           = 0;
                            if (organization.IsCompanyOrPharmacyOrNursingOrganization)
                            {
                                avgSample = organization.RegisteredEmployees / countOfTestingDates ?? 0;
                                if (organization.IsNursery)
                                {
                                    avgSample = 2 * avgSample;
                                }
                            }
                            else
                            {
                                avgSample = organization.TotalSamples / countOfTestingDates;
                            }
                            testsDataValue.Samples += avgSample;
                        }
                    }

                    testsDataValue.CantonsSamples = testsDataValue.CantonsSamplesData.Sum(x => x.Samples);
                    testsDataValue.TotalSamples   = testsDataValue.Samples + testsDataValue.CantonsSamples;
                }

                currentDate = currentDate.AddDays(1);
            }

            var testsDataWithEarliestDate = new TestsDataWithIsEarliestDateDto()
            {
                IsEarliestDate = startDate == _testsHistoryEarliestDate,
                TestsData      = testDatesValues
            };

            return(testsDataWithEarliestDate);
        }
Example #6
0
#pragma warning disable CA1308 // Normalize strings to uppercase
        public AutoMapperProfile(IAESCryptography aESCryptography)
        {
            _aESCryptography = aESCryptography;

            CreateMap <User, UserDto>()
            .ForMember(opt => opt.Email,
                       src => src.MapFrom(x => _aESCryptography.Decrypt(x.Email)))
            .ForMember(opt => opt.Name,
                       src => src.MapFrom(x => _aESCryptography.Decrypt(x.Name)))
            .ForMember(opt => opt.PhoneNumber,
                       src => src.MapFrom(x => _aESCryptography.Decrypt(x.PhoneNumber)))
            .ForMember(opt => opt.LandLineNumber,
                       src => src.MapFrom(x => _aESCryptography.Decrypt(x.LandLineNumber)));
            CreateMap <UserDto, User>()
            .ForMember(opt => opt.Email,
                       src => src.MapFrom(x => _aESCryptography.Encrypt(x.Email.ToLower(CultureInfo.InvariantCulture))))
            .ForMember(opt => opt.Name,
                       src => src.MapFrom(x => _aESCryptography.Encrypt(x.Name)))
            .ForMember(opt => opt.PhoneNumber,
                       src => src.MapFrom(x => _aESCryptography.Encrypt(x.PhoneNumber)))
            .ForMember(opt => opt.LandLineNumber,
                       src => src.MapFrom(x => _aESCryptography.Encrypt(x.LandLineNumber)))
            .ForMember(opt => opt.LamaCompany, src => src.Ignore())
            .ForMember(opt => opt.LamaCompanyId, src => src.Ignore())
            .ForMember(opt => opt.Organization, src => src.Ignore())
            .ForMember(opt => opt.OrganizationId, src => src.Ignore())
            .ForMember(opt => opt.SupportOrganizations, src => src.Ignore())
            .ForMember(opt => opt.SupportPersonOrgTypeDefaults, src => src.Ignore())
            .ForMember(opt => opt.OrganizationNotes, src => src.Ignore())
            .ForMember(opt => opt.FixedTestingPersonnelCancelations, src => src.Ignore());

            CreateMap <UserSpecDto, User>()
            .ForMember(opt => opt.Email,
                       src => src.MapFrom(x => _aESCryptography.Encrypt(x.Email.ToLower(CultureInfo.InvariantCulture))))
            .ForMember(opt => opt.Name,
                       src => src.MapFrom(x => _aESCryptography.Encrypt(x.Name)))
            .ForMember(opt => opt.PhoneNumber,
                       src => src.MapFrom(x => _aESCryptography.Encrypt(x.PhoneNumber)))
            .ForMember(opt => opt.LandLineNumber,
                       src => src.MapFrom(x => _aESCryptography.Encrypt(x.LandLineNumber)))
            .ForMember(opt => opt.LamaCompany, src => src.Ignore())
            .ForMember(opt => opt.LamaCompanyId, src => src.Ignore())
            .ForMember(opt => opt.Organization, src => src.Ignore())
            .ForMember(opt => opt.OrganizationId, src => src.Ignore())
            .ForMember(opt => opt.SupportOrganizations, src => src.Ignore())
            .ForMember(opt => opt.SupportPersonOrgTypeDefaults, src => src.Ignore())
            .ForMember(opt => opt.Id, src => src.Ignore())
            .ForMember(opt => opt.OrganizationNotes, src => src.Ignore())
            .ForMember(opt => opt.FixedTestingPersonnelCancelations, src => src.Ignore());

            CreateMap <User, ShortContactInfoDto>()
            .ForMember(opt => opt.Name,
                       src => src.MapFrom(x => _aESCryptography.Decrypt(x.Name)))
            .ForMember(opt => opt.SupportPersonId,
                       src => src.MapFrom(x => x.Id));

            CreateMap <City, CityDto>();

            CreateMap <SubOrganization, SubOrganizationDto>();
            CreateMap <SubOrganizationDto, SubOrganization>()
            .ForMember(opt => opt.Organization, src => src.Ignore());

            CreateMap <OrganizationSpecDto, Organization>()
            .ForMember(opt => opt.OrganizationTypeId,
                       src => src.MapFrom(x => x.TypeId))
            .ForMember(opt => opt.Id, src => src.Ignore())
            .ForMember(opt => opt.OrganizationType, src => src.Ignore())
            .ForMember(opt => opt.EpaadId, src => src.Ignore())
            .ForMember(opt => opt.OrganizationShortcutName, src => src.Ignore())
            .ForMember(opt => opt.CreatedOn, src => src.Ignore())
            .ForMember(opt => opt.LastUpdatedOn, src => src.Ignore())
            .ForMember(opt => opt.OnboardingTimestamp, src => src.Ignore())
            .ForMember(opt => opt.TrainingTimestamp, src => src.Ignore())
            .ForMember(opt => opt.FirstTestTimestamp, src => src.Ignore())
            .ForMember(opt => opt.SecondTestTimestamp, src => src.Ignore())
            .ForMember(opt => opt.ThirdTestTimestamp, src => src.Ignore())
            .ForMember(opt => opt.FourthTestTimestamp, src => src.Ignore())
            .ForMember(opt => opt.FifthTestTimestamp, src => src.Ignore())
            .ForMember(opt => opt.ExclusionStartDate, src => src.Ignore())
            .ForMember(opt => opt.ExclusionEndDate, src => src.Ignore())
            .ForMember(opt => opt.City, src => src.Ignore())
            .ForMember(opt => opt.SupportPerson, src => src.Ignore())
            .ForMember(opt => opt.Status, src => src.Ignore())
            .ForMember(opt => opt.Manager, src => src.Ignore())
            .ForMember(opt => opt.StudentsCount, src => src.Ignore())
            .ForMember(opt => opt.EmployeesCount, src => src.Ignore())
            .ForMember(opt => opt.RegisteredEmployees, src => src.Ignore())
            .ForMember(opt => opt.Area, src => src.Ignore())
            .ForMember(opt => opt.County, src => src.Ignore())
            .ForMember(opt => opt.PrioLogistic, src => src.Ignore())
            .ForMember(opt => opt.SchoolType, src => src.Ignore())
            .ForMember(opt => opt.NumberOfBags, src => src.Ignore())
            .ForMember(opt => opt.NaclLosing, src => src.Ignore())
            .ForMember(opt => opt.AdditionalTestTubes, src => src.Ignore())
            .ForMember(opt => opt.NumberOfRakoBoxes, src => src.Ignore())
            .ForMember(opt => opt.PickupLocation, src => src.Ignore())
            .ForMember(opt => opt.County, src => src.Ignore())
            .ForMember(opt => opt.SubOrganizations, src => src.Ignore())
            .ForMember(opt => opt.Notes, src => src.Ignore())
            .ForMember(opt => opt.InfoSessionFollowUp, src => src.Ignore())
            .ForMember(opt => opt.IsOnboardingEmailSent, src => src.Ignore())
            .ForMember(opt => opt.PlannedNumberOfSamples, src => src.Ignore())
            .ForMember(opt => opt.IsStaticPooling, src => src.Ignore())
            .ForMember(opt => opt.IsContractReceived, src => src.Ignore())
            .ForMember(opt => opt.ReportingContact, src => src.Ignore())
            .ForMember(opt => opt.ReportingEmail, src => src.Ignore());

            CreateMap <OrganizationProfileSpecDto, Organization>()
            .ForMember(opt => opt.OrganizationTypeId,
                       src => src.MapFrom(x => x.TypeId))
            .ForMember(opt => opt.OrganizationType, src => src.Ignore())
            .ForMember(opt => opt.EpaadId, src => src.Ignore())
            .ForMember(opt => opt.OrganizationShortcutName, src => src.Ignore())
            .ForMember(opt => opt.CreatedOn, src => src.Ignore())
            .ForMember(opt => opt.LastUpdatedOn, src => src.Ignore())
            .ForMember(opt => opt.OnboardingTimestamp, src => src.Ignore())
            .ForMember(opt => opt.TrainingTimestamp, src => src.Ignore())
            .ForMember(opt => opt.FirstTestTimestamp, src => src.Ignore())
            .ForMember(opt => opt.SecondTestTimestamp, src => src.Ignore())
            .ForMember(opt => opt.ThirdTestTimestamp, src => src.Ignore())
            .ForMember(opt => opt.FourthTestTimestamp, src => src.Ignore())
            .ForMember(opt => opt.FifthTestTimestamp, src => src.Ignore())
            .ForMember(opt => opt.ExclusionStartDate, src => src.Ignore())
            .ForMember(opt => opt.ExclusionEndDate, src => src.Ignore())
            .ForMember(opt => opt.City, src => src.Ignore())
            .ForMember(opt => opt.Status, src => src.Ignore())
            .ForMember(opt => opt.SupportPerson, src => src.Ignore())
            .ForMember(opt => opt.Manager, src => src.Ignore())
            .ForMember(opt => opt.StudentsCount, src => src.Ignore())
            .ForMember(opt => opt.EmployeesCount, src => src.Ignore())
            .ForMember(opt => opt.RegisteredEmployees, src => src.Ignore())
            .ForMember(opt => opt.Area, src => src.Ignore())
            .ForMember(opt => opt.County, src => src.Ignore())
            .ForMember(opt => opt.PrioLogistic, src => src.Ignore())
            .ForMember(opt => opt.SchoolType, src => src.Ignore())
            .ForMember(opt => opt.NumberOfBags, src => src.Ignore())
            .ForMember(opt => opt.NaclLosing, src => src.Ignore())
            .ForMember(opt => opt.AdditionalTestTubes, src => src.Ignore())
            .ForMember(opt => opt.NumberOfRakoBoxes, src => src.Ignore())
            .ForMember(opt => opt.PickupLocation, src => src.Ignore())
            .ForMember(opt => opt.County, src => src.Ignore())
            .ForMember(opt => opt.SubOrganizations, src => src.Ignore())
            .ForMember(opt => opt.Notes, src => src.Ignore())
            .ForMember(opt => opt.InfoSessionFollowUp, src => src.Ignore())
            .ForMember(opt => opt.IsOnboardingEmailSent, src => src.Ignore())
            .ForMember(opt => opt.PlannedNumberOfSamples, src => src.Ignore())
            .ForMember(opt => opt.IsStaticPooling, src => src.Ignore())
            .ForMember(opt => opt.IsContractReceived, src => src.Ignore())
            .ForMember(opt => opt.ReportingContact, src => src.Ignore())
            .ForMember(opt => opt.ReportingEmail, src => src.Ignore());


            CreateMap <OrganizationDto, Organization>()
            .ForMember(opt => opt.Manager,
                       src => src.MapFrom(x => _aESCryptography.Encrypt(x.Manager)))
            .ForMember(opt => opt.City, src => src.Ignore())
            .ForMember(opt => opt.CreatedOn, src => src.Ignore())
            .ForMember(opt => opt.LastUpdatedOn, src => src.Ignore())
            .ForMember(opt => opt.EpaadId, src => src.Ignore())
            .ForMember(opt => opt.Status, src => src.Ignore())
            .ForMember(opt => opt.RegisteredEmployees, src => src.Ignore())
            .ForMember(opt => opt.OrganizationType, src => src.Ignore())
            .ForMember(opt => opt.Notes, src => src.Ignore())
            .ForMember(opt => opt.InfoSessionFollowUp, src => src.Ignore())
            .ForMember(opt => opt.IsOnboardingEmailSent, src => src.Ignore())
            .ForMember(opt => opt.PlannedNumberOfSamples, src => src.Ignore())
            .ForMember(opt => opt.IsStaticPooling, src => src.Ignore())
            .ForMember(opt => opt.IsContractReceived, src => src.Ignore());

            CreateMap <Organization, OrganizationDto>()
            .ForMember(opt => opt.Manager,
                       src => src.MapFrom(x => _aESCryptography.Decrypt(x.Manager)))
            .ForMember(opt => opt.FollowUpStatus,
                       src => src.MapFrom(x => x.InfoSessionFollowUp != null ?
                                          x.InfoSessionFollowUp.Status :
                                          InfoSessionFollowUpStatus.NotSent));

            CreateMap <Organization, OrganizationProfileDto>();
            CreateMap <Organization, OrganizationDashboardDto>()
            .ForMember(opt => opt.TestDate1,
                       src => src.MapFrom(x => x.FirstTestTimestamp))
            .ForMember(opt => opt.TestDate2,
                       src => src.MapFrom(x => x.SecondTestTimestamp))
            .ForMember(opt => opt.TestDate3,
                       src => src.MapFrom(x => x.ThirdTestTimestamp))
            .ForMember(opt => opt.TestDate4,
                       src => src.MapFrom(x => x.FourthTestTimestamp))
            .ForMember(opt => opt.TestDate5,
                       src => src.MapFrom(x => x.FifthTestTimestamp))
            .ForMember(opt => opt.OnboardingDate,
                       src => src.MapFrom(x => x.OnboardingTimestamp));

            CreateMap <Organization, OrganizationEpaadInfoDto>();

            CreateMap <OrganizationType, OrganizationTypeDto>();

            CreateMap <Organization, OrganizationOnboardingEventDto>()
            .ForMember(opt => opt.SupportPersonName,
                       src => src.MapFrom(x => _aESCryptography.Decrypt(x.SupportPerson.Name)))
            .ForMember(opt => opt.SupportPersonEmail,
                       src => src.MapFrom(x => _aESCryptography.Decrypt(x.SupportPerson.Email)))
            .ForMember(opt => opt.City,
                       src => src.MapFrom(x => x.City.Name));

            CreateMap <TestingPersonnel, TestingPersonnelDto>()
            .ForMember(opt => opt.Email,
                       src => src.MapFrom(x => _aESCryptography.Decrypt(x.Email)))
            .ForMember(opt => opt.FirstName,
                       src => src.MapFrom(x => _aESCryptography.Decrypt(x.FirstName)))
            .ForMember(opt => opt.LastName,
                       src => src.MapFrom(x => _aESCryptography.Decrypt(x.LastName)))
            .ForMember(opt => opt.WorkingAreas,
                       src => src.MapFrom(x => x.TestingPersonnelWorkingAreas));

            CreateMap <TestingPersonnelSpecDto, TestingPersonnel>()
            .ForMember(opt => opt.Email,
                       src => src.MapFrom(x => _aESCryptography.Encrypt(x.Email.ToLower(CultureInfo.InvariantCulture))))
            .ForMember(opt => opt.FirstName,
                       src => src.MapFrom(x => _aESCryptography.Encrypt(x.FirstName)))
            .ForMember(opt => opt.LastName,
                       src => src.MapFrom(x => _aESCryptography.Encrypt(x.LastName)))
            .ForMember(opt => opt.CreatedOn, src => src.Ignore())
            .ForMember(opt => opt.LastUpdatedOn, src => src.Ignore())
            .ForMember(opt => opt.Id, src => src.Ignore())
            .ForMember(opt => opt.Status, src => src.Ignore())
            .ForMember(opt => opt.TestingPersonnelConfirmations, src => src.Ignore())
            .ForMember(opt => opt.FixedTestingPersonnelCancelations, src => src.Ignore())
            .ForMember(opt => opt.TestingPersonnelWorkingAreas,
                       src => src.MapFrom(x => x.WorkingAreas))
            .ForMember(opt => opt.HasFixedWorkingDays, src => src.Ignore())
            .ForMember(opt => opt.TestingPersonnelConfirmationsWithoutInvitations, src => src.Ignore());

            CreateMap <TestingPersonnelWorkingAreaSpecDto, TestingPersonnelWorkingArea>()
            .ForMember(opt => opt.Area,
                       src => src.MapFrom(x => x.WorkingArea))
            .ForMember(opt => opt.Id, src => src.Ignore())
            .ForMember(opt => opt.TestingPersonnelId, src => src.Ignore())
            .ForMember(opt => opt.TestingPersonnel, src => src.Ignore());

            CreateMap <TestingPersonnelWorkingArea, TestingPersonnelWorkingAreaDto>();

            CreateMap <TestingPersonnelInvitationSpecDto, TestingPersonnelInvitation>()
            .ForMember(opt => opt.InvitationForDate,
                       src => src.MapFrom(x => x.Date))
            .ForMember(opt => opt.Id, src => src.Ignore())
            .ForMember(opt => opt.CreatedOn, src => src.Ignore())
            .ForMember(opt => opt.TestingPersonnelConfirmations, src => src.Ignore())
            .ForMember(opt => opt.SentByUser, src => src.Ignore());

            CreateMap <TestingPersonnelInvitation, TestingPersonnelInvitationDto>();
            CreateMap <TestingPersonnelConfirmationSpecDto, TestingPersonnelConfirmation>()
            .ForMember(opt => opt.TestingPersonnelInvitationId,
                       src => src.MapFrom(x => x.InvitationId))
            .ForMember(opt => opt.TestingPersonnelId,
                       src => src.MapFrom(x => x.PersonnelId))
            .ForMember(opt => opt.Id, src => src.Ignore())
            .ForMember(opt => opt.ShiftNumber, src => src.Ignore())
            .ForMember(opt => opt.AcceptedOn, src => src.Ignore())
            .ForMember(opt => opt.TestingPersonnelInvitation, src => src.Ignore())
            .ForMember(opt => opt.TestingPersonnel, src => src.Ignore())
            .ForMember(opt => opt.CanceledByUserId, src => src.Ignore())
            .ForMember(opt => opt.CanceledOn, src => src.Ignore());

            CreateMap <LamaCompany, LamaCompanyProfileDto>();
            CreateMap <User, LamaUserDto>()
            .ForMember(opt => opt.Email,
                       src => src.MapFrom(x => _aESCryptography.Decrypt(x.Email)))
            .ForMember(opt => opt.Name,
                       src => src.MapFrom(x => _aESCryptography.Decrypt(x.Name)))
            .ForMember(opt => opt.PhoneNumber,
                       src => src.MapFrom(x => _aESCryptography.Decrypt(x.PhoneNumber)))
            .ForMember(opt => opt.LandLineNumber,
                       src => src.MapFrom(x => _aESCryptography.Decrypt(x.LandLineNumber)))
            .ForMember(opt => opt.SupportDefaultOrganizationTypes,
                       src => src.MapFrom(x => x.SupportPersonOrgTypeDefaults));

            CreateMap <SupportPersonOrgTypeDefaultMapping, SupportOrganizationTypeDto>()
            .ForMember(opt => opt.OrganizationTypeId,
                       src => src.MapFrom(x => x.OrganizationTypeId))
            .ForMember(opt => opt.OrganizationTypeName,
                       src => src.MapFrom(x => x.OrganizationType.Name))
            .ForMember(opt => opt.Id,
                       src => src.MapFrom(x => x.Id));
            CreateMap <SupportOrganizationTypeDto, SupportPersonOrgTypeDefaultMapping>()
            .ForMember(opt => opt.Id,
                       src => src.MapFrom(x => x.Id))
            .ForMember(opt => opt.OrganizationTypeId,
                       src => src.MapFrom(x => x.OrganizationTypeId))
            .ForMember(opt => opt.User,
                       src => src.Ignore())
            .ForMember(opt => opt.OrganizationType,
                       src => src.Ignore())
            .ForMember(opt => opt.OrganizationType,
                       src => src.Ignore())
            .ForMember(opt => opt.UserId,
                       src => src.Ignore());

            CreateMap <LamaCompanyProfileSpecDto, LamaCompany>()
            .ForMember(opt => opt.RoleType,
                       src => src.Ignore());

            CreateMap <LamaUserDto, User>()
            .ForMember(opt => opt.Email,
                       src => src.MapFrom(x => _aESCryptography.Encrypt(x.Email.ToLower(CultureInfo.InvariantCulture))))
            .ForMember(opt => opt.Name,
                       src => src.MapFrom(x => _aESCryptography.Encrypt(x.Name)))
            .ForMember(opt => opt.PhoneNumber,
                       src => src.MapFrom(x => _aESCryptography.Encrypt(x.PhoneNumber)))
            .ForMember(opt => opt.LandLineNumber,
                       src => src.MapFrom(x => _aESCryptography.Encrypt(x.LandLineNumber)))
            .ForMember(opt => opt.SupportPersonOrgTypeDefaults,
                       src => src.MapFrom(x => x.SupportDefaultOrganizationTypes))
            .ForMember(opt => opt.LamaCompany,
                       src => src.Ignore())
            .ForMember(opt => opt.LamaCompanyId,
                       src => src.Ignore())
            .ForMember(opt => opt.Organization,
                       src => src.Ignore())
            .ForMember(opt => opt.OrganizationId,
                       src => src.Ignore())
            .ForMember(opt => opt.SupportOrganizations,
                       src => src.Ignore())
            .ForMember(opt => opt.OrganizationNotes,
                       src => src.Ignore())
            .ForMember(opt => opt.FixedTestingPersonnelCancelations,
                       src => src.Ignore());

            CreateMap <OrganizationNoteDto, OrganizationNote>()
            .ForMember(opt => opt.CreatorName,
                       src => src.MapFrom(x => _aESCryptography.Encrypt(x.CreatorName)))
            .ForMember(opt => opt.Text,
                       src => src.MapFrom(x => _aESCryptography.Encrypt(x.Text)))
            .ForMember(opt => opt.Organization,
                       src => src.Ignore())
            .ForMember(opt => opt.User,
                       src => src.Ignore());

            CreateMap <OrganizationNote, OrganizationNoteDto>()
            .ForMember(opt => opt.CreatorName,
                       src => src.MapFrom(x => _aESCryptography.Decrypt(x.CreatorName)))
            .ForMember(opt => opt.Text,
                       src => src.MapFrom(x => _aESCryptography.Decrypt(x.Text)));

            CreateMap <CantonSpecDto, Canton>()
            .ForMember(opt => opt.Id,
                       src => src.Ignore())
            .ForMember(opt => opt.Country,
                       src => src.Ignore())
            .ForMember(opt => opt.Cities,
                       src => src.Ignore());
            CreateMap <CantonDto, Canton>()
            .ForMember(opt => opt.Country,
                       src => src.Ignore())
            .ForMember(opt => opt.Cities,
                       src => src.Ignore());
            CreateMap <Canton, CantonDto>();

            CreateMap <CantonWeekdaysSamplesSpecDto, CantonWeekdaysSamples>()
            .ForMember(opt => opt.Id,
                       src => src.Ignore())
            .ForMember(opt => opt.Canton,
                       src => src.Ignore())
            .ForMember(opt => opt.CantonId,
                       src => src.Ignore());
            CreateMap <CantonWeekdaysSamplesDto, CantonWeekdaysSamples>()
            .ForMember(opt => opt.Canton,
                       src => src.Ignore());
            CreateMap <CantonWeekdaysSamples, CantonWeekdaysSamplesDto>();
        }
Example #7
0
        public async Task <OrganizationDetailDto> GetOrganizationByIdAsync(Guid id)
        {
            await using var context = ContextFactory.CreateDataContext(null);
            var org = await context.Organizations.AsNoTracking()
                      .Include(x => x.Contacts)
                      .Include(x => x.SupportPerson)
                      .Include(x => x.OrganizationType)
                      .Include(x => x.SubOrganizations)
                      .Include(x => x.InfoSessionFollowUp)
                      .Include(x => x.City)
                      .FirstOrDefaultAsync(item => item.Id == id)
                      .ConfigureAwait(false);

            var orgDataDto = new OrganizationDetailDto();

            if (org != null)
            {
                if (org.OrganizationTypeId != 82002)
                {
                    orgDataDto.Id = org.Id;
                    if (org.OrganizationType != null)
                    {
                        orgDataDto.Type = org.OrganizationType.Name;
                    }
                    if (org.City != null)
                    {
                        orgDataDto.City = org.City.Name;
                    }
                    orgDataDto.TypeId           = org.OrganizationTypeId;
                    orgDataDto.Zip              = org.Zip;
                    orgDataDto.Name             = org.Name;
                    orgDataDto.ShortcutName     = org.OrganizationShortcutName;
                    orgDataDto.ReportingContact = org.ReportingContact;
                    orgDataDto.ReportingEmail   = org.ReportingEmail;

                    orgDataDto.Contacts = new List <UserDto>();
                    if (org.Contacts != null)
                    {
                        foreach (var contact in org.Contacts)
                        {
                            var userDto = Mapper.Map <User, UserDto>(contact);
                            orgDataDto.Contacts.Add(userDto);
                        }
                    }
                    orgDataDto.SubOrganizations = new List <SubOrganizationDto>();
                    if (org.SubOrganizations != null)
                    {
                        foreach (var subOrganization in org.SubOrganizations)
                        {
                            var subOrganizationDto = Mapper.Map <SubOrganization, SubOrganizationDto>(subOrganization);
                            orgDataDto.SubOrganizations.Add(subOrganizationDto);
                        }
                    }
                    if (org.SupportPerson != null)
                    {
                        var supportPersonDto = Mapper.Map <User, UserDto>(org.SupportPerson);
                        orgDataDto.SupportPerson = supportPersonDto;
                    }
                    if (org.InfoSessionFollowUp != null)
                    {
                        orgDataDto.FollowUpStatus = org.InfoSessionFollowUp.Status;
                    }
                    orgDataDto.EpaadId             = org.EpaadId;
                    orgDataDto.CreatedOn           = org.CreatedOn;
                    orgDataDto.LastUpdatedOn       = org.LastUpdatedOn;
                    orgDataDto.Address             = org.Address;
                    orgDataDto.TrainingTimestamp   = org.TrainingTimestamp;
                    orgDataDto.OnboardingTimestamp = org.OnboardingTimestamp;
                    orgDataDto.FirstTestTimestamp  = org.FirstTestTimestamp;
                    orgDataDto.SecondTestTimestamp = org.SecondTestTimestamp;
                    orgDataDto.ThirdTestTimestamp  = org.ThirdTestTimestamp;
                    orgDataDto.FourthTestTimestamp = org.FourthTestTimestamp;
                    orgDataDto.FifthTestTimestamp  = org.FifthTestTimestamp;
                    orgDataDto.ExclusionStartDate  = org.ExclusionStartDate;
                    orgDataDto.ExclusionEndDate    = org.ExclusionEndDate;
                    orgDataDto.NumberOfSamples     = org.NumberOfSamples;
                    orgDataDto.NumberOfPools       = org.NumberOfPools;
                    orgDataDto.SupportPersonId     = org.SupportPersonId;
                    orgDataDto.Status = org.Status;
                    if (org.Manager != null)
                    {
                        orgDataDto.Manager = _aESCryptography.Decrypt(org.Manager);
                    }

                    orgDataDto.StudentsCount       = org.StudentsCount;
                    orgDataDto.EmployeesCount      = org.EmployeesCount;
                    orgDataDto.RegisteredEmployees = org.RegisteredEmployees;
                    orgDataDto.Area                  = org.Area;
                    orgDataDto.County                = org.County;
                    orgDataDto.PrioLogistic          = org.PrioLogistic;
                    orgDataDto.SchoolType            = org.SchoolType;
                    orgDataDto.NumberOfBags          = org.NumberOfBags;
                    orgDataDto.NaclLosing            = org.NaclLosing;
                    orgDataDto.AdditionalTestTubes   = org.AdditionalTestTubes;
                    orgDataDto.NumberOfRakoBoxes     = org.NumberOfRakoBoxes;
                    orgDataDto.PickupLocation        = org.PickupLocation;
                    orgDataDto.IsOnboardingEmailSent = org.IsOnboardingEmailSent;
                    orgDataDto.IsStaticPooling       = org.IsStaticPooling;
                    orgDataDto.IsContractReceived    = org.IsContractReceived;
                }
            }
            return(orgDataDto);
        }
Example #8
0
        public AutoMapperProfile(IAESCryptography aESCryptography)
        {
            _aESCryptography = aESCryptography;

            CreateMap <EmailTemplate, EmailTemplateDto>();
            CreateMap <EmailTemplateDto, EmailTemplate>()
            .ForMember(source => source.Emails, opt => opt.Ignore());

            CreateMap <InsertFileDto, Attachment>()
            .ForMember(dest => dest.Content, opt => opt.MapFrom(src => _aESCryptography.Encrypt(src.Content)));
            CreateMap <Attachment, FileInfoDto>()
            .ForMember(dest => dest.FileHash, opt => opt.MapFrom(src => src.OriginalXXHash))
            .ForMember(dest => dest.Content, opt => opt.MapFrom(src => Convert.ToBase64String(_aESCryptography.Decrypt(src.Content))));
        }