Esempio n. 1
0
        public async Task UpdateRegisteredEmployeesAsync()
        {
            var organizationsWithEpaadId = await _organizationsRepository
                                           .GetOrganizationsWithEpaadIdAsync()
                                           .ConfigureAwait(false);

            if (organizationsWithEpaadId.Any())
            {
                var epaadAllOrganizations = await GetAllOrganizationsFromEpaadAsync().ConfigureAwait(false);

                if (epaadAllOrganizations.Any())
                {
                    var dbEpaadIds = organizationsWithEpaadId.Select(x => x.EpaadId.ToString(CultureInfo.InvariantCulture));
                    var epaadOrganizationsWithExisingEpaadId = epaadAllOrganizations.Where(x => dbEpaadIds.Contains(x.EpaadId));

                    foreach (var dbEpaadOrg in epaadOrganizationsWithExisingEpaadId)
                    {
                        var epaadOrgDto = new EpaadOrganizationDto
                        {
                            EpaadId                  = Convert.ToInt32(dbEpaadOrg.EpaadId, CultureInfo.InvariantCulture),
                            RegisteredEmployees      = dbEpaadOrg.RegisteredEmployees,
                            OrganizationShortcutName = dbEpaadOrg.OrganizationShortcutName
                        };

                        await _organizationsRepository
                        .UpdateRegisteredEmployeesAndShortNamePerOrganizationAsync(epaadOrgDto)
                        .ConfigureAwait(false);
                    }
                }
            }
        }
Esempio n. 2
0
        public async Task UpdateRegisteredEmployeesAndShortNamePerOrganizationAsync(EpaadOrganizationDto dto)
        {
            if (dto == null)
            {
                throw new ArgumentNullException(nameof(dto));
            }

            await using var context = ContextFactory.CreateDataContext(null);
            var organizations = context.Organizations;
            var entity        = await organizations.AsNoTracking()
                                .FirstAsync(t => t.EpaadId.HasValue && t.EpaadId.Value == dto.EpaadId)
                                .ConfigureAwait(false);

            entity.RegisteredEmployees      = dto.RegisteredEmployees;
            entity.OrganizationShortcutName = dto.OrganizationShortcutName;
            entity.LastUpdatedOn            = DateTime.UtcNow;
            context.Entry(entity).State     = EntityState.Modified;
            context.Organizations.Update(entity);

            await context.SaveChangesAsync()
            .ConfigureAwait(false);
        }