Example #1
0
        private async Task <Document> CreateDocument(DdDocumentExtension oldDocument)
        {
            var typeId = DictionaryHelper.GetNullableDictionaryIdByCode(nameof(DicDocumentType), oldDocument.DoctypeCode) ??
                         DictionaryHelper.GetNullableDictionaryIdByExternalId(nameof(DicDocumentType), oldDocument.DoctypeId);

            if (typeId == null || typeId == 0)
            {
                return(null);
            }

            var type  = DictionaryHelper.GetDictionaryById(nameof(DicDocumentType), typeId.Value);
            var route = DictionaryHelper.GetDictionaryById(nameof(DicRoute), type.RouteId);

            var documentType = GenerateHelper.GetDocumentType(route.Code);

            var customerId = GetObjectId <DicCustomer>(oldDocument.CustomerId);

            if ((customerId == null || customerId == 0) && oldDocument.CustomerId.HasValue)
            {
                customerId = await GetCustomer(oldDocument.CustomerId.Value);
            }

            var document = new Document
            {
                AddresseeId          = customerId,
                Barcode              = oldDocument.Id,
                DateCreate           = new DateTimeOffset(oldDocument.DateCreate.GetValueOrDefault(DateTime.Now)),
                DateUpdate           = new DateTimeOffset(oldDocument.Stamp.GetValueOrDefault(DateTime.Now)),
                DepartmentId         = GetObjectId <DicDepartment>(oldDocument.DepartmentId),
                DivisionId           = GetObjectId <DicDivision>(oldDocument.DivisionId),
                DocumentNum          = oldDocument.DocumNum,
                DocumentType         = documentType,
                ExternalId           = oldDocument.Id,
                IncomingNumber       = oldDocument.InoutNum,
                IncomingNumberFilial = oldDocument.InnumAdd,
                IsDeleted            = false,
                IsFinished           = GenerateHelper.StringToNullableBool(oldDocument.IsComplete),
                NameEn         = oldDocument.DescriptionMlEn,
                NameRu         = oldDocument.DescriptionMlRu,
                NameKz         = oldDocument.DescriptionMlKz,
                OutgoingNumber = oldDocument.Outnum,
                ReceiveTypeId  = GetObjectId <DicReceiveType>(oldDocument.SendType),
                SendingDate    = GetNullableDate(oldDocument.DocumDate),
                Timestamp      = BitConverter.GetBytes(DateTime.Now.Ticks),
                TypeId         = typeId.Value,
                PageCount      = oldDocument.PageCount,
                WasScanned     = false,
                StatusId       = DictionaryHelper.GetDictionaryIdByCode(nameof(DicDocumentStatus), DicDocumentStatusCodes.Completed)
            };

            return(document);
        }