public virtual int _GetUniqueIdentifier()
        {
            var hashCode = 399326290;

            hashCode = hashCode * -1521134295 + (Id?.GetHashCode() ?? 0);
            hashCode = hashCode * -1521134295 + (SupplierDocument?.GetHashCode() ?? 0);
            hashCode = hashCode * -1521134295 + (InvestorDocument?.GetHashCode() ?? 0);
            hashCode = hashCode * -1521134295 + (AdminDocument?.GetHashCode() ?? 0);
            return(hashCode);
        }
예제 #2
0
        private static async Task GenerateNestedDocuments(int investorId, int numberOfDocs)
        {
            var startDate = new DateTime(2018, 1, 1);
            var r         = new Random();

            var doc = new InvestorDocument()
            {
                InvestorId = investorId,
                id         = Guid.NewGuid(),
                Corro      = new List <DocumentDetails>()
            };

            for (int i = 1; i <= numberOfDocs; ++i)
            {
                int j = r.Next(0, 3);
                int y = r.Next(0, 2);

                var corro = new DocumentDetails()
                {
                    RefId       = investorId.ToString() + i.ToString("D4"),
                    AccountNo   = investorId.ToString() + r.Next(100, 999) + i.ToString("D4"),
                    Type        = _corroTypes[j],
                    Date        = startDate.AddMonths(i),
                    ProductCode = "",
                    ProductName = _prodNames[y]
                };
                doc.Corro.Add(corro);
            }

            try
            {
                ItemResponse <InvestorDocument> response = await _container.CreateItemAsync(doc, new PartitionKey(doc.InvestorId));

                Console.WriteLine("INFO: Investor documents {0} are registered", doc.Corro.Count);
            }
            catch (Exception ex)
            {
                Console.WriteLine("ERROR: {0}", ex.Message);
            }
        }
예제 #3
0
        public async Task <Guid> InsertUpdateDocument(InvestorDocumentFlat document)
        {
            using (var client = new CosmosClient(_functionSettings.CosmosDBEndpoint, _functionSettings.CosmosDBMasterKey))
            {
                var container = client.GetContainer(_functionSettings.CosmosDBName,
                                                    SQLStatements.InvestorDocuments.ContainerName);
                var sql   = SQLStatements.InvestorDocuments.ListInvestorDocs;
                var query = new QueryDefinition(sql);

                query.WithParameter("@InvestorId", document.InvestorId);
                var iterator = container
                               .GetItemQueryIterator <InvestorDocument>(query,
                                                                        requestOptions: new QueryRequestOptions()
                {
                    MaxConcurrency = 1
                });

                var docDetails = new DocumentDetails()
                {
                    RefId       = document.RefId,
                    Type        = document.Type,
                    AccountNo   = document.AccountNo,
                    Date        = document.Date,
                    ProductCode = document.ProductCode,
                    ProductName = document.ProductName,
                    Link        = document.Link
                };

                while (iterator.HasMoreResults)
                {
                    var task = iterator.ReadNextAsync();
                    task.Wait();
                    FeedResponse <InvestorDocument> response = task.Result;
                    if (response.Any())
                    {
                        var item = response.FirstOrDefault();
                        if (item != null)
                        {
                            var d = item.Corro.Where(x => x.RefId == document.RefId).FirstOrDefault();

                            if (d == null)
                            {
                                item.Corro.Add(docDetails);
                            }
                            else
                            {
                                //Only update the link to document
                                d.Link = document.Link;
                            }

                            await container.ReplaceItemAsync(item, item.id.ToString(), new PartitionKey(item.InvestorId));

                            return(item.id);
                        }
                    }
                    else
                    {
                        break;
                    }
                }

                var doc = new InvestorDocument()
                {
                    InvestorId = document.InvestorId,
                    id         = Guid.NewGuid(),
                    Corro      = new List <DocumentDetails>()
                };

                doc.Corro.Add(docDetails);

                var insertResponse = await container.CreateItemAsync(doc, new PartitionKey(doc.InvestorId));

                document.id = insertResponse.Resource.id;
            }

            return(document.id);
        }