Пример #1
0
        public SignDocumentsResponse Execute(SignDocumentsRequest request)
        {
            var user = _repository.GetUser(request.UserLogin);

            if (user == null)
            {
                return(new SignDocumentsResponse()
                {
                    Error = "user not found", Success = false
                });
            }

            if (!user.IsDirector())
            {
                throw new UnauthorizedAccessException($"User {request.UserLogin} unauthorized call this method");
            }

            var documentIds           = request.DocumentIds;
            var processingDocuments   = _repository.GetDocumentsForSigning(user.CompanyId);
            var processingDocumentIds = new HashSet <Guid>(processingDocuments.Select(d => d.Id));

            if (documentIds.Any(id => !processingDocumentIds.Contains(id)))
            {
                return(new SignDocumentsResponse()
                {
                    Success = false, Error = "Invalid documentIds list"
                });
            }

            _repository.SignDocuments(request.DocumentIds);
            return(new SignDocumentsResponse()
            {
                Success = true
            });
        }
Пример #2
0
        public UserInfoResponse Execute(UserInfoRequest request)
        {
            var user = _repository.GetUser(request.UserLogin);

            if (user == null)
            {
                return(new UserInfoResponse()
                {
                    Success = false, Error = $"Cannot find user {request.UserLogin}"
                });
            }

            var response = new UserInfoResponse()
            {
                Login      = user.Login,
                Role       = user.Role,
                Name       = user.Name,
                Surname    = user.Surname,
                Patronymic = user.Patronymic,
                CompanyId  = user.CompanyId,
                Success    = true
            };

            return(response);
        }
Пример #3
0
        public UploadResponse Execute(UploadRequest request)
        {
            var user = _repository.GetUser(request.UserLogin);

            var documentModels = request.Files.Select(i =>
            {
                var doc = _documentParser.Parse(i);

                return(new DocumentModel
                {
                    CompanyId = user.CompanyId,
                    CreateDate = DateTime.Now,
                    CreatorId = user.Id,
                    Id = Guid.NewGuid(),
                    SignDate = null,
                    StatusTyped = DocumentStatus.New,

                    Data = JsonConvert.SerializeObject(doc)
                });
            }).ToList();

            _repository.AddDocuments(documentModels);
            var documents = documentModels.Select(i =>
            {
                var doc = i.DocumentParsed;
                return(new Document
                {
                    Id = i.Id,
                    CompanyId = i.CompanyId,
                    CreatorId = i.CreatorId,
                    CreateDate = i.CreateDate,
                    Name = doc.CstmrCdtTrfInitn.GrpHdr.MsgId,
                    SignDate = i.SignDate,
                    Status = i.StatusTyped.ToString(),
                    Details = i.DocumentParsed
                });
            }).ToList();

            return(new UploadResponse()
            {
                Success = true, UploadedDocuments = documents
            });
        }
Пример #4
0
        public GetDocumentsResponse Execute(GetDocumentsRequest request)
        {
            var user = _repository.GetUser(request.UserLogin);

            if (user == null)
            {
                return(new GetDocumentsResponse()
                {
                    Error = $"Cannot find user {request.UserLogin}"
                });
            }

            var documentsRows = user.IsOperator() ?
                                _repository.GetUserDocuments(user.Id) :
                                _repository.GetDocumentsForSigning(user.CompanyId);
            var documents = documentsRows.Select(doc => _documentMapper.Map(doc)).ToList();

            return(new GetDocumentsResponse()
            {
                Success = true,
                Documents = documents
            });
        }