Exemplo n.º 1
0
        public ServiceResult <TranslationDocumentDto> AddTranslationDocument(TranslationDocumentDto documentDto, int createdBy)
        {
            var serviceResult = new ServiceResult <TranslationDocumentDto>();

            try {
                documentDto.CreatedBy = createdBy;
                documentDto.Active    = true;
                var document = _customMapperConfiguration.GetMapEntity <TranslationDocument, TranslationDocumentDto>(documentDto);

                _model.TranslationDocuments.Add(document);
                if (_model.SaveChanges() <= 0)
                {
                    throw new BusinessException(ExceptionCodes.UnableToInsert);
                }
                var documentAudit = new DocumentAudit {
                    DocumentId = document.Id,
                    Message    = $"Document with id #{document.Id} and name {document.Name} added for translation.",
                    Status     = "Document Added",
                    Date       = DateTime.Now
                };

                AddDocumentAudit(documentAudit);

                serviceResult.ServiceResultType = ServiceResultType.Success;
                serviceResult.Data = _customMapperConfiguration.GetMapDto <TranslationDocumentDto, TranslationDocument>(document);
            } catch (Exception exc) {
                serviceResult.Exception         = exc;
                serviceResult.ServiceResultType = ServiceResultType.Fail;
                _logger.Error($"Error occured in {MethodBase.GetCurrentMethod().Name} with exception message {exc.Message} and inner exception {exc.InnerException?.Message}");
            }
            return(serviceResult);
        }
Exemplo n.º 2
0
        public ServiceResult <TranslationDocumentDto> EditTranslationDocument(TranslationDocumentDto documentDto, int createdBy)
        {
            var serviceResult = new ServiceResult <TranslationDocumentDto>();

            try {
                var document = _model.TranslationDocuments.FirstOrDefault(f => f.Id == documentDto.Id);
                if (document == null)
                {
                    throw new DbOperationException(ExceptionCodes.NoRelatedData);
                }

                document.Path   = documentDto.Path;
                document.Name   = documentDto.Name;
                document.Active = documentDto.Active;

                document.PageCount           = documentDto.PageCount;
                document.CharCount           = documentDto.CharCount;
                document.CharCountWithSpaces = documentDto.CharCountWithSpaces;

                document.UpdatedAt = DateTime.Now;
                document.UpdatedBy = createdBy;

                if (_model.SaveChanges() <= 0)
                {
                    throw new BusinessException(ExceptionCodes.UnableToUpdate);
                }

                var documentAudit = new DocumentAudit {
                    DocumentId = document.Id,
                    Message    = $"Document with id #{document.Id} and name {document.Name} updated.",
                    Status     = "Document Updated",
                    Date       = DateTime.Now
                };

                AddDocumentAudit(documentAudit);

                serviceResult.ServiceResultType = ServiceResultType.Success;
                serviceResult.Data = _customMapperConfiguration.GetMapDto <TranslationDocumentDto, TranslationDocument>(document);
            } catch (Exception exc) {
                serviceResult.Exception         = exc;
                serviceResult.ServiceResultType = ServiceResultType.Fail;
                _logger.Error($"Error occured in {MethodBase.GetCurrentMethod().Name} with exception message {exc.Message} and inner exception {exc.InnerException?.Message}");
            }
            return(serviceResult);
        }
Exemplo n.º 3
0
        private void AddDocumentAudit(DocumentAudit documentAudit)
        {
            var collection = _database.GetCollection <DocumentAudit>(ConfigurationManager.AppSettings["MongoAuditCollection"]);

            collection.InsertOneAsync(documentAudit);
        }
Exemplo n.º 4
0
        public ServiceResult <List <TranslationDocumentPartDto> > GetDocumentPartsNormalized(int translationDocumentId, int partCount, int createdBy)
        {
            var serviceResult = new ServiceResult <List <TranslationDocumentPartDto> >();

            try {
                var translationDocument = _model.TranslationDocuments.Find(translationDocumentId);
                if (translationDocument == null)
                {
                    throw new BusinessException(ExceptionCodes.NoRelatedData);
                }

                string content = string.Empty;

                if (translationDocument.Path.IsDocumentExtension())
                {
                    var parser = GetDocumentParser(translationDocument.Path);
                    content = parser.Parse().ToString();
                }
                else
                {
                    var parser = GetTextParser(translationDocument.Path);
                    content = parser.Parse();
                }

                var stringParser = new StringParser(content);
                var parts        = stringParser.SplitByCount(partCount);



                var documentParts = parts.Select(a => {
                    var tempStringParser   = new StringParser(a);
                    var charCOunt          = tempStringParser.GenerateCharacterCount(true);
                    var charCountWithSpace = tempStringParser.GenerateCharacterCount();
                    return(new TranslationDocumentPart()
                    {
                        TranslationDocumentId = translationDocumentId,
                        Path = translationDocument.Path,
                        Active = true,
                        Content = a,
                        CharCountWithSpaces = charCountWithSpace,
                        CharCount = charCOunt,
                        CreatedAt = DateTime.Now,
                        CreatedBy = createdBy
                    });
                }).ToList();

                _model.TranslationDocumentParts.AddRange(documentParts);

                if (_model.SaveChanges() <= 0)
                {
                    throw new BusinessException(ExceptionCodes.UnableToInsert);
                }

                var documentPartsFromDb = _model.TranslationDocumentParts
                                          .Where(x => x.TranslationDocumentId == translationDocumentId)
                                          .ToList();

                var documentAudit = new DocumentAudit {
                    DocumentId = translationDocument.Id,
                    Message    = $"Document with id #{translationDocument.Id} and name {translationDocument.Name} partitioned as {documentPartsFromDb.Count} part to translatrors.",
                    Status     = "Document Partitioned",
                    Date       = DateTime.Now
                };

                AddDocumentAudit(documentAudit);

                serviceResult.ServiceResultType = ServiceResultType.Success;
                serviceResult.Data = documentPartsFromDb.Select(x => _customMapperConfiguration.GetMapDto <TranslationDocumentPartDto, TranslationDocumentPart>(x)).ToList();
            } catch (Exception exc) {
                serviceResult.Exception         = exc;
                serviceResult.ServiceResultType = ServiceResultType.Fail;
                _logger.Error($"Error occured in {MethodBase.GetCurrentMethod().Name} with exception message {exc.Message} and inner exception {exc.InnerException?.Message}");
            }
            return(serviceResult);
        }