public async Task <IEnumerable <AbsenceExport> > Search(SearchQueryAbsenceExport searchQuery) { var hierarchyDown = await _unitQueries.GetHierarchyDown(searchQuery.UnitId); searchQuery.UnitIds = hierarchyDown.Select(u => u.Id).ToList(); return(await _repository.Search(searchQuery)); }
public async Task <IEnumerable <AbsenceExport> > Search(SearchQueryAbsenceExport searchQuery) { using (var context = await _contextFactory.CreateDbContext()) { var query = context.AbsenceExports.AsQueryable(); if (searchQuery.UnitId != 0 || searchQuery.UnitIds.Any()) { query = context.AbsenceExports.Where(x => (searchQuery.UnitId != 0 && x.UnitId == searchQuery.UnitId) || searchQuery.UnitIds.Contains(x.UnitId)); } if (searchQuery.LocalId != 0) { query = query.Where(x => x.LocalAbsenceId == searchQuery.LocalId); } if (!string.IsNullOrWhiteSpace(searchQuery.Id)) { query = query.Where(x => x.Id == searchQuery.Id); } var filterResult = await query.ToListAsync(); var mappedResult = _mapper.Map <IEnumerable <entities.AbsenceExport>, IEnumerable <AbsenceExport> >(filterResult); return(mappedResult); } }
private async Task <AbsenceExport> GetExistingAbsenceExport(int unitId, int localId) { var searchQueryAbsenceExport = new SearchQueryAbsenceExport(unitId) { LocalId = localId }; var existingAbsenceExports = await _absenceExportService.Search(searchQueryAbsenceExport); return(existingAbsenceExports.OrderByDescending(arg => arg.UpdateAt ?? arg.CreatedAt).FirstOrDefault()); }
public async Task Resend(string absenceExportId) { var query = new SearchQueryAbsenceExport() { Id = absenceExportId }; var absenceExport = (await _absenceExportService.Search(query)).FirstOrDefault(); if (absenceExport == null) { throw new NotFoundException("Absence doesn't exist"); } var absenceResult = JsonConvert.DeserializeObject <Absence>(absenceExport.AbsenceJson); var integration = await GetIntegrationRecursive(absenceResult.UnitId); var validationResult = await Validate(absenceResult, integration); var externalSystem = (ExternalEconomySystem)integration.ExternalSystem; var externalSystemAdapter = _externalSystemFactory.CreateSystemAdapter(externalSystem); try { if (!validationResult.IsValid) { absenceExport.Status = AbsenceExportStatus.Failed; absenceExport.Message = validationResult.Message; return; } absenceExport.Absence = await externalSystemAdapter.ResendAbsence(integration.UnitId, absenceResult); absenceExport.Status = AbsenceExportStatus.Success; absenceExport.Message = "Absence successfully exported"; }catch (ExternalSystemCommunicationException ex) { absenceExport.Status = AbsenceExportStatus.Failed; absenceExport.Message = $"Communication with external system failed: {ex.Message}"; } catch (Exception ex) { absenceExport.Status = AbsenceExportStatus.Failed; absenceExport.Message = ex.Message; } finally { await _absenceExportService.UpdateAbsenceExport(absenceExport); } }