コード例 #1
0
ファイル: MinistryDocument.cs プロジェクト: timlem/Excavator
        /// <summary>
        /// Saves the files.
        /// </summary>
        /// <param name="newFileList">The new file list.</param>
        private static void SaveFiles(List <DocumentKeys> newFileList, ProviderComponent storageProvider)
        {
            if (storageProvider == null)
            {
                LogException("Binary File Import", string.Format("Could not load provider {0}.", storageProvider.ToString()));
                return;
            }

            if (newFileList.Any(f => f.File == null))
            {
                LogException("Binary File Import", string.Format("Could not load {0} files because they were null.", newFileList.Count(f => f.File == null)));
            }

            var rockContext = new RockContext();

            rockContext.WrapTransaction(() =>
            {
                foreach (var entry in newFileList)
                {
                    storageProvider.SaveContent(entry.File);
                    entry.File.Path = storageProvider.GetPath(entry.File);
                }

                var list = newFileList.Select(f => f.File).ToList();

                rockContext.BinaryFiles.AddRange(newFileList.Select(f => f.File));
                rockContext.SaveChanges();

                var currentPersonAttributes = new Dictionary <int, List <int> >();

                foreach (var entry in newFileList.OrderByDescending(f => f.File.CreatedDateTime))
                {
                    List <int> attributeList = null;

                    if (currentPersonAttributes.ContainsKey(entry.PersonId) && currentPersonAttributes[entry.PersonId] != null)
                    {
                        attributeList = currentPersonAttributes[entry.PersonId];
                    }
                    else
                    {
                        // first document for this person in the current zip file, start a list
                        attributeList = new List <int>();
                        currentPersonAttributes.Add(entry.PersonId, attributeList);
                    }

                    if (!attributeList.Contains(entry.AttributeId))
                    {
                        var attributeValue = rockContext.AttributeValues.FirstOrDefault(p => p.AttributeId == entry.AttributeId && p.EntityId == entry.PersonId);

                        // set person attribute value to this binary file guid
                        if (attributeValue == null)
                        {
                            attributeValue             = new AttributeValue();
                            attributeValue.IsSystem    = false;
                            attributeValue.EntityId    = entry.PersonId;
                            attributeValue.AttributeId = entry.AttributeId;
                            attributeValue.Value       = entry.File.Guid.ToString();
                            rockContext.AttributeValues.Add(attributeValue);
                        }
                        else if (attributeValue.CreatedDateTime < entry.File.CreatedDateTime)
                        {
                            attributeValue.Value = entry.File.Guid.ToString();
                            rockContext.Entry(attributeValue).State = EntityState.Modified;
                        }

                        attributeList.Add(entry.AttributeId);
                    }
                }

                rockContext.SaveChanges(DisableAuditing);
            });
        }
コード例 #2
0
        /// <summary>
        /// Saves the files.
        /// </summary>
        /// <param name="newFileList">The new file list.</param>
        private static void SaveFiles(Dictionary <int, Rock.Model.BinaryFile> newFileList, ProviderComponent storageProvider)
        {
            var rockContext = new RockContext();

            rockContext.WrapTransaction(() =>
            {
                rockContext.BinaryFiles.AddRange(newFileList.Values);
                rockContext.SaveChanges();

                foreach (var entry in newFileList)
                {
                    if (entry.Value != null)
                    {
                        if (storageProvider != null)
                        {
                            storageProvider.SaveContent(entry.Value);
                            entry.Value.Path = storageProvider.GetPath(entry.Value);
                        }
                        else
                        {
                            LogException("Binary File Import", string.Format("Could not load provider {0}.", storageProvider.ToString()));
                        }
                    }

                    // associate the image with the right transaction
                    var transactionImage           = new FinancialTransactionImage();
                    transactionImage.TransactionId = entry.Key;
                    transactionImage.BinaryFileId  = entry.Value.Id;
                    transactionImage.Order         = 0;
                    rockContext.FinancialTransactions.FirstOrDefault(t => t.Id == entry.Key)
                    .Images.Add(transactionImage);
                }

                rockContext.SaveChanges(DisableAuditing);
            });
        }
コード例 #3
0
        /// <summary>
        /// Saves the files.
        /// </summary>
        /// <param name="newFileList">The new file list.</param>
        private static void SaveFiles(List <DocumentKeys> newFileList, ProviderComponent storageProvider)
        {
            var rockContext = new RockContext();

            rockContext.WrapTransaction(() =>
            {
                rockContext.BinaryFiles.AddRange(newFileList.Select(f => f.File));
                rockContext.SaveChanges();

                foreach (var entry in newFileList)
                {
                    if (entry.File != null)
                    {
                        if (storageProvider != null)
                        {
                            storageProvider.SaveContent(entry.File);
                            entry.File.Path = storageProvider.GetPath(entry.File);
                        }
                        else
                        {
                            LogException("Binary File Import", string.Format("Could not load provider {0}.", storageProvider.ToString()));
                        }
                    }

                    // set person attribute value to this binary file guid
                    var attributeValue = rockContext.AttributeValues.FirstOrDefault(p => p.AttributeId == entry.AttributeId && p.EntityId == entry.PersonId);
                    if (attributeValue == null || attributeValue.CreatedDateTime < entry.File.CreatedDateTime)
                    {
                        bool addToContext          = attributeValue == null;
                        attributeValue             = new AttributeValue();
                        attributeValue.EntityId    = entry.PersonId;
                        attributeValue.AttributeId = entry.AttributeId;
                        attributeValue.Value       = entry.File.Guid.ToString();
                        attributeValue.IsSystem    = false;

                        if (addToContext)
                        {
                            rockContext.AttributeValues.Add(attributeValue);
                        }
                    }
                }

                rockContext.SaveChanges(DisableAuditing);
            });
        }
コード例 #4
0
        /// <summary>
        /// Saves the files.
        /// </summary>
        /// <param name="newFileList">The new file list.</param>
        /// <param name="storageProvider">The storage provider.</param>
        private static void SaveFiles(Dictionary <int, Rock.Model.BinaryFile> newFileList, ProviderComponent storageProvider)
        {
            var rockContext = new RockContext();

            rockContext.WrapTransaction(() =>
            {
                rockContext.BinaryFiles.AddRange(newFileList.Values);
                rockContext.SaveChanges();

                foreach (var file in newFileList)
                {
                    if (storageProvider != null)
                    {
                        storageProvider.SaveContent(file.Value);
                        file.Value.Path = storageProvider.GetPath(file.Value);
                    }
                    else
                    {
                        LogException("Binary File Import", string.Format("Could not load provider {0}.", storageProvider.ToString()));
                    }

                    // associate the person with this photo
                    rockContext.People.FirstOrDefault(p => p.Id == file.Key).PhotoId = file.Value.Id;
                }

                rockContext.SaveChanges(DisableAuditing);
            });
        }
コード例 #5
0
        /// <summary>
        /// Saves the files.
        /// </summary>
        /// <param name="newFileList">The new file list.</param>
        /// <param name="storageProvider">The storage provider.</param>
        private static void SaveFiles(Dictionary <KeyValuePair <int, int>, Rock.Model.BinaryFile> newFileList, ProviderComponent storageProvider)
        {
            var rockContext = new RockContext();

            rockContext.WrapTransaction(() =>
            {
                rockContext.BinaryFiles.AddRange(newFileList.Values);
                rockContext.SaveChanges(DisableAuditing);

                foreach (var entry in newFileList)
                {
                    if (entry.Value != null)
                    {
                        if (storageProvider != null)
                        {
                            storageProvider.SaveContent(entry.Value);
                            entry.Value.Path = storageProvider.GetPath(entry.Value);
                        }
                        else
                        {
                            LogException("Binary File Import", string.Format("Could not load provider {0}.", storageProvider.ToString()));
                        }
                    }

                    // associate the document with the correct BenevolenceRequest
                    var benevolenceDocument = new BenevolenceRequestDocument
                    {
                        BenevolenceRequestId = entry.Key.Key,
                        BinaryFileId         = entry.Value.Id,
                        Order = 0
                    };

                    if (entry.Key.Value > 0)
                    {
                        benevolenceDocument.ForeignKey = entry.Key.Value.ToString();
                        benevolenceDocument.ForeignId  = entry.Key.Value;
                    }

                    rockContext.BenevolenceRequests.FirstOrDefault(r => r.Id == entry.Key.Key)
                    .Documents.Add(benevolenceDocument);
                }

                rockContext.SaveChanges(DisableAuditing);
            });
        }