예제 #1
0
        public async Task <IActionResult> CompleteContract([FromBody] IntellectualPropertyScannerDto dto)
        {
            if (!dto.Id.HasValue)
            {
                var newContract = Executor.GetHandler <CreateContractFromUploadedFileHandler>()
                                  .Process(h => h.Execute(dto));

                await Executor.GetCommand <CreateContractCommand>().Process(c => c.ExecuteAsync(newContract));

                // Executor.GetCommand<UpdateContractCommand>().Process(c => c.ExecuteAsync(newContract));
                await Executor.GetHandler <GenerateContractNumberHandler>().Process(c => c.ExecuteAsync(newContract));

                var initialWorkflow = await Executor.GetQuery <GetInitialContractWorkflowQuery>().Process(q =>
                                                                                                          q.ExecuteAsync(newContract, NiisAmbientContext.Current.User.Identity.UserId));

                if (initialWorkflow != null)
                {
                    await Executor.GetHandler <ProcessContractWorkflowHandler>().Process(h => h.Handle(initialWorkflow, newContract.Id));
                }

                dto.Id = newContract.Id;
            }

            var contract = await Executor.GetHandler <AddMainAttachToContractHandler>().Process(r => r.Execute(dto));

            var contractDto = Mapper.Map <IntellectualPropertyDto>(contract);

            return(Ok(contractDto));
        }
        public Contract Execute(IntellectualPropertyScannerDto dto)
        {
            var newContract = new Contract
            {
                ProtectionDocTypeId = dto.ProtectionDocTypeId,
                DepartmentId        = Executor.GetQuery <GetDicDepartmentByCodeQuery>().Process(q => q.Execute(DicDepartmentCodes.ExpertiseDepartment)).Id,
                DivisionId          = Executor.GetQuery <GetDicDivisionByCodeQuery>().Process(q => q.Execute(DicDivision.Niis)).Id,
                ReceiveTypeId       = Executor.GetQuery <GetReceiveTypeByCodeQuery>()
                                      .Process(q => q.Execute(DicReceiveType.Codes.Courier)).Id
            };

            Executor.GetHandler <GenerateBarcodeHandler>().Process(h => h.Execute(newContract));

            return(newContract);
        }
        public Request Execute(IntellectualPropertyScannerDto dto)
        {
            var newRequest = new Request {
                ProtectionDocTypeId = dto.ProtectionDocTypeId
            };

            Executor.GetHandler <GenerateBarcodeHandler>().Process(h => h.Execute(newRequest));
            newRequest.ReceiveTypeId = Executor.GetQuery <GetReceiveTypeByCodeQuery>()
                                       .Process(q => q.Execute(DicReceiveType.Codes.Courier)).Id;
            var user = Executor.GetQuery <GetUserByIdQuery>()
                       .Process(q => q.Execute(NiisAmbientContext.Current.User.Identity.UserId));

            newRequest.DepartmentId = user.DepartmentId;
            newRequest.DivisionId   = user.Department.DivisionId;

            return(newRequest);
        }
        public async Task <Request> Execute(IntellectualPropertyScannerDto data)
        {
            using (var fileStream = File.OpenRead(Path.Combine(Path.GetTempPath(),
                                                               data.Attachment.TempName)))
            {
                if (!data.Id.HasValue)
                {
                    throw new Exception("Request not Fount");
                }

                var request = await Executor.GetQuery <GetRequestByIdQuery>().Process(q => q.ExecuteAsync((int)data.Id));

                if (request == null)
                {
                    throw new Exception("Request not Fount");
                }

                var bucketName = "requests";
                var userId     = NiisAmbientContext.Current.User.Identity.UserId;
                var fileName   = $"{request.Barcode}_{request.ProtectionDocType.NameRu}{Path.GetExtension(data.Attachment.Name)}";
                //var originalName = $"current/{request.Id}/{fileName}";

                var extention    = Path.GetExtension(fileName);
                var originalName = $"current/{request.Id}/{Guid.NewGuid().ToString()}{extention}";

                var newAttachment = data.Attachment.ContentType.Equals(ContentType.Pdf)
                    ? _attachmentHelper.NewPdfObject(data.Attachment, userId, bucketName, fileStream, originalName, fileName, true)
                    : _attachmentHelper.NewFileObject(data.Attachment, userId, bucketName, fileStream, originalName, fileName, true);

                // TODO: Transaction with complex logic
                //using (var transaction = _context.Database.BeginTransaction())
                //{
                try
                {
                    await Executor.GetCommand <CreateAttachmentCommand>().Process(q => q.ExecuteAsync(newAttachment));

                    await _fileStorage.AddAsync(newAttachment.BucketName, newAttachment.OriginalName, fileStream, newAttachment.ContentType);

                    var oldAttachment = request.MainAttachment;

                    request.MainAttachment   = newAttachment;
                    request.MainAttachmentId = newAttachment.Id;
                    request.PageCount        = newAttachment.PageCount;
                    request.CopyCount        = newAttachment.CopyCount;
                    await Executor.GetCommand <UpdateRequestCommand>().Process(q => q.ExecuteAsync(request));

                    //transaction.Commit();

                    if (oldAttachment != null)
                    {
                        if (oldAttachment.ValidName != newAttachment.ValidName)
                        {
                            await _fileStorage.Remove(oldAttachment.BucketName, oldAttachment.OriginalName);
                        }

                        await Executor.GetCommand <DeleteAttachmentCommand>().Process(q => q.ExecuteAsync(oldAttachment));
                    }
                }
                catch
                {
                    //todo: log exception
                    throw;
                }

                return(request);
            }
        }
예제 #5
0
        public async Task <IActionResult> CompleteRequest([FromBody] IntellectualPropertyScannerDto dto)
        {
            if (!dto.Id.HasValue)
            {
                var newRequest = Executor.GetHandler <CreateRequestFromUploadedFileHandler>()
                                 .Process(h => h.Execute(dto));

                await Executor.GetCommand <CreateRequestCommand>()
                .Process(c => c.ExecuteAsync(newRequest));

                var initialWorkflow = await Executor.GetQuery <GetInitialRequestWorkflowQuery>().Process(q =>
                                                                                                         q.ExecuteAsync(newRequest, NiisAmbientContext.Current.User.Identity.UserId));

                if (initialWorkflow != null)
                {
                    await Executor.GetHandler <ProcessRequestWorkflowHandler>()
                    .Process(h => h.Handle(initialWorkflow, newRequest));
                }

                Executor.GetHandler <GenerateRequestIncomingNumberHandler>().Process(c => c.Execute(newRequest.Id));
                await Executor.GetCommand <UpdateRequestCommand>().Process(c => c.ExecuteAsync(newRequest));

                dto.Id = newRequest.Id;
            }

            //TODO! Перенести функционал в проект сканера, тот проект большой, долго разбираться, пока реализовал здесь
            var protectionDocType = Executor.GetQuery <GetDicProtectionDocTypeByIdQuery>()
                                    .Process(q => q.Execute(dto.ProtectionDocTypeId));
            string documentTypeCode;

            switch (protectionDocType.Code)
            {
            case DicProtectionDocTypeCodes.RequestTypeTrademarkCode:
                documentTypeCode = DicDocumentTypeCodes.RequestForTrademark;
                break;

            case DicProtectionDocTypeCodes.ProtectionDocTypeInternationalTrademarkCode:
                documentTypeCode = DicDocumentTypeCodes.RequestForInternationalTrademark;
                break;

            case DicProtectionDocTypeCodes.RequestTypeIndustrialSampleCode:
                documentTypeCode = DicDocumentTypeCodes.RequestForIndustrialSample;
                break;

            case DicProtectionDocTypeCodes.RequestTypeInventionCode:
                documentTypeCode = DicDocumentTypeCodes.RequestForInvention;
                break;

            case DicProtectionDocTypeCodes.RequestTypeNameOfOriginCode:
                documentTypeCode = DicDocumentTypeCodes.RequestForNmpt;
                break;

            case DicProtectionDocTypeCodes.RequestTypeSelectionAchieveCode:
                documentTypeCode = DicDocumentTypeCodes.RequestForSelectiveAchievement;
                break;

            case DicProtectionDocTypeCodes.RequestTypeUsefulModelCode:
                documentTypeCode = DicDocumentTypeCodes.RequestForUsefulModel;
                break;

            default:
                throw new NotImplementedException();
            }
            var dicDocumentType = Executor.GetQuery <GetDicDocumentTypeByCodeQuery>()
                                  .Process(q => q.Execute(documentTypeCode));
            var requestDocuments =
                await Executor.GetQuery <GetDocumentsByRequestIdQuery>().Process(q => q.ExecuteAsync(dto.Id.Value));

            var newDocument = requestDocuments.FirstOrDefault(d => d.TypeId == dicDocumentType.Id);

            if (newDocument == null)
            {
                var materialDto = new MaterialDetailDto
                {
                    TypeId       = dicDocumentType.Id,
                    DocumentType = DocumentType.Incoming,
                    Owners       = new[]
                    {
                        new MaterialOwnerDto
                        {
                            OwnerType           = Owner.Type.Request,
                            OwnerId             = dto.Id.Value,
                            ProtectionDocTypeId = dto.ProtectionDocTypeId
                        }
                    },
                    WasScanned = true
                };

                if (materialDto.DocumentType == DocumentType.DocumentRequest)
                {
                    materialDto.StatusId = Executor.GetQuery <GetDocumentStatusByCodeQuery>().Process(q => q.Execute(DicDocumentStatusCodes.Completed)).Id;
                }

                newDocument = Executor.GetHandler <CreateDocumentFromUploadedFileHandler>()
                              .Process(h => h.Execute(materialDto));

                var docId = await Executor.GetCommand <CreateDocumentCommand>()
                            .Process(c => c.ExecuteAsync(newDocument));

                var initialWorkflow = await Executor.GetQuery <GetInitialDocumentWorkflowQuery>()
                                      .Process(q => q.ExecuteAsync(docId, NiisAmbientContext.Current.User.Identity.UserId));

                await Executor.GetCommand <ApplyDocumentWorkflowCommand>().Process(c => c.ExecuteAsync(initialWorkflow));

                if (newDocument.DocumentType == DocumentType.Incoming)
                {
                    await Executor.GetHandler <GenerateDocumentIncomingNumberHandler>().Process(c => c.ExecuteAsync(docId));
                }
            }
            if (newDocument.MainAttachmentId.HasValue)
            {
                newDocument.MainAttachment   = null;
                newDocument.MainAttachmentId = null;
                await Executor.GetCommand <UpdateDocumentCommand>().Process(c => c.Execute(newDocument));
            }
            var request = await Executor.GetHandler <AddMainAttachToRequestHandler>().Process(r => r.Execute(dto));

            newDocument.MainAttachment   = request.MainAttachment;
            newDocument.MainAttachmentId = request.MainAttachmentId;
            newDocument.AddresseeId      = request.AddresseeId;
            await Executor.GetCommand <UpdateDocumentCommand>().Process(c => c.Execute(newDocument));

            var requestDto = Mapper.Map <IntellectualPropertyDto>(request);

            return(Ok(requestDto));
        }