Ejemplo n.º 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
            });
        }
Ejemplo n.º 2
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
            });
        }