Пример #1
0
        public async Task ExecuteAsync(ExportRecruitCommandParameters parameters)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException(nameof(parameters));
            }

            IEnumerable <RecruitInfo> recruitInfoes = _recruitInfoRepository.Get(parameters.RecruitIds);

            await Task.Run(() =>
            {
                var recruitCount = recruitInfoes.Count();

                for (int i = 0; i < recruitCount; i += 2)
                {
                    var firstRecruit  = recruitInfoes.ElementAt(i);
                    var secondRecruit = recruitInfoes.ElementAtOrDefault(i + 1);

                    var recruitExporter = CreateRecruitExporter(parameters,
                                                                firstRecruit, secondRecruit);

                    recruitExporter.ExportRecruitInfoesToExcel(firstRecruit, secondRecruit);
                }

                parameters.StateChanged.OnStateChanged(CommandSuccess, StateResult.Success);
            });
        }
        public async Task ExecuteAsync(TransmitRecruitCommandParameters parameters)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException(nameof(parameters));
            }

            var recruitInfoes = _recruitInfoRepository.Get(parameters.RecruitIds)
                                .ToList()
                                .OrderBy(r => r.Envelope.PassportInfo.PersonInfo.FullName.Surname)
                                .ToList();

            using (var firebirdUnitOfWork = _firebirdUnitOfWorkFactory.Create())
                using (var sqliteUnitOfWork = _sqliteUnitOfWorkFactory.Create())
                {
                    try
                    {
                        var regionalCollectionPoints = recruitInfoes.Select(r => r.ServiceInfo.RegionalCollectionPoint).Distinct().ToList();
                        var message = $"{CommandSuccess}. Военкоматы - {string.Join(SeparatorConstants.CommaSeparator, regionalCollectionPoints)}";

                        await _transmitService.MoveAsync(recruitInfoes);

                        foreach (var recruit in recruitInfoes)
                        {
                            ChangePhotoName(recruit);

                            _recruitInfoRepository.Change(recruit);
                        }

                        _eventService.Fire(message);

                        await firebirdUnitOfWork.CommitAsync();

                        await sqliteUnitOfWork.CommitAsync();

                        parameters.StateChanged.OnStateChanged(message, StateResult.Success);
                    }
                    catch (Exception ex)
                    {
                        firebirdUnitOfWork.Rollback();
                        sqliteUnitOfWork.Rollback();

                        throw ex;
                    }
                }
        }
        public void GetByRcpConscriptionDateRecruitInfoSQLiteTest()
        {
            var recruitInfo1 = MemoryData.Build(1, 1, _photoExtension);
            var recruitInfo2 = MemoryData.Build(2, 2, _photoExtension);

            using (var unitOfWork = _unitOfWorkFactory.Create())
            {
                _recruitInfoRepository.Add(recruitInfo1);
                _recruitInfoRepository.Add(recruitInfo2);

                unitOfWork.Commit();
            }

            var recruitInfos = _recruitInfoRepository.Get("Барабинский", new DateTime(2017, 1, 1), null);

            Assert.IsTrue(recruitInfos.Count() == 2);
        }
Пример #4
0
        public RecruitCardGroup Create(RecruitOperationEventArgs recruitOperationEventArgs)
        {
            switch (recruitOperationEventArgs.RecruitOperation)
            {
            case RecruitOperation.Import:
            {
                return(_recruitImporter.ImportRecruitCardGroup(recruitOperationEventArgs.RecruitShortUIModel));
            }

            case RecruitOperation.Add:
            {
                return(_recruitCardGroupByAdd);
            }

            case RecruitOperation.Edit:
            {
                if (recruitOperationEventArgs.RecruitShortUIModel != null &&
                    recruitOperationEventArgs.RecruitShortUIModel.SqliteId.HasValue)
                {
                    var id      = recruitOperationEventArgs.RecruitShortUIModel.SqliteId.Value;
                    var recruit = _recruitInfoRepository.Get(id);

                    if (recruit == null)
                    {
                        return(EmptyCard);
                    }

                    var cardGroupMapper = new CardGroupMapper(_personalPhotoDirectoryPath, recruit);
                    return(cardGroupMapper.Map());
                }
                else
                {
                    return(EmptyCard);
                }
            }
            }

            return(EmptyCard);
        }