public bool UpdateDocument(DocumentDto dto, int userId)
        {
            if (userId <= 0)
            {
                throw new ArgumentOutOfRangeException("Invalid User Id");
            }
            if (dto == null)
            {
                throw new ArgumentNullException("Document cannot be null");
            }

            Document loaded = _documentRepository.FindById(dto.DocId);

            if (loaded == null)
            {
                throw new ArgumentOutOfRangeException("Invalid Document Id");
            }

            DocumentDto existingDto = new DocumentDto(loaded);
            bool        updated     = existingDto.Set(dto);

            if (updated)
            {
                _documentRepository.Update(existingDto.MapToEntity(), userId);
            }

            return(updated);
        }
        public DocumentDto AddDocument(DocumentDto document, int userId)
        {
            if (userId <= 0)
            {
                throw new ArgumentOutOfRangeException("Invalid User Id");
            }
            if (document == null)
            {
                throw new ArgumentNullException("Document cannot be null");
            }

            Document created = _documentRepository.Insert(document.MapToEntity(), userId);

            document.DocId = created.DocId;

            return(document);
        }
        public bool SetDocumentStatus(int docId, DocumentStatusEnum newStatus, int userId)
        {
            if (userId <= 0)
            {
                throw new ArgumentOutOfRangeException("Invalid User Id");
            }

            Document loaded = _documentRepository.FindById(docId);

            if (loaded == null)
            {
                throw new ArgumentOutOfRangeException("Invalid Document Id");
            }

            DocumentDto existingDto = new DocumentDto(loaded);
            bool        updated     = existingDto.SetStatus(newStatus);

            if (updated)
            {
                _documentRepository.Update(existingDto.MapToEntity(), userId);
            }

            return(updated);
        }