Пример #1
0
        public override bool DoUpload(ExcelPackage pkg)
        {
            var rt = ProgressDbContext.UploadPeopleRuns.OrderByDescending(mm => mm.Id).First();

            var ws = pkg.Workbook.Worksheets[PeopleSheetName];

            FetchData(pkg.Workbook.Worksheets[PeopleSheetName]);
            const string sheet = "Personal Data";

            CheckColumn("IndividualId", sheet);
            CheckColumn("FamilyId", sheet);
            CheckColumn("First", sheet);
            CheckColumn("Last", sheet);

            var sid = ((object)Datalist[0].IndividualId).ToString();

            if (sid.ToCharArray().Any(char.IsLetter))
            {
                AlphaNumericIds = true;
            }

            if (AlphaNumericIds)
            {
                _alphanumericPeopleIds = JobDbContext.PeopleExtras
                                         .Where(vv => vv.Field == "IndividualId" && vv.Data.Length > 0)
                                         .ToDictionary(vv => vv.Data, vv => vv.PeopleId);
            }
            else
            {
                _numericPeopleIds = JobDbContext.PeopleExtras
                                    .Where(vv => vv.Field == "IndividualId" && vv.IntValue != null)
                                    .ToDictionary(vv => vv.IntValue ?? 0, vv => vv.PeopleId);
            }

            UploadPeople(rt, ws);
            TryDeleteAllContributions();
            UploadPledges(rt, pkg);
            UploadGifts(rt, pkg);

            rt.Completed = DateTime.Now;
            ProgressDbContext.SubmitChanges();

            return(true);
        }
Пример #2
0
        private void UploadPledges(UploadPeopleRun rt, ExcelPackage pkg)
        {
            var data = FetchPledgeData(pkg.Workbook.Worksheets["Pledges"]).ToList();

            rt.Count       = data.Count;
            rt.Description = $"Uploading Pledges {(Testing ? "in testing mode" : "for real")}";
            rt.Processed   = 0;
            ProgressDbContext.SubmitChanges();

            var weeks = (from g in data
                         group g by g.Date.Sunday()
                         into weeklypledges
                         select weeklypledges).ToList();
            BundleHeader bh = null;

            foreach (var week in weeks)
            {
                FinishBundle(JobDbContext, bh);

                bh = new BundleHeader
                {
                    BundleHeaderTypeId = BundleTypeCode.Pledge,
                    BundleStatusId     = BundleStatusCode.Closed,
                    CreatedBy          = Util.UserId,
                    CreatedDate        = DateTime.Today,
                    ContributionDate   = week.Key
                };
                foreach (var pledge in week)
                {
                    var pid = GetPeopleId(pledge);
                    var f   = new ContributionFund {
                        FundId = 0
                    };
                    if (!Testing)
                    {
                        if (!pid.HasValue)
                        {
                            if (IgnoreMissingGifts)
                            {
                                _orphanedPledges.Append($"{pledge.IndividualId} {pledge.Date:d} {pledge.Amount:C}\n");
                                continue;
                            }

                            throw new Exception($"peopleid not found from individualid {pledge.IndividualId}");
                        }

                        f = ProgressDbContext.FetchOrCreateFund(pledge.FundId,
                                                                pledge.FundName ?? pledge.FundDescription);
                        f.FundPledgeFlag = true;
                    }

                    var bd = new BundleDetail
                    {
                        CreatedBy    = Util.UserId,
                        CreatedDate  = DateTime.Now,
                        Contribution = new Contribution
                        {
                            CreatedBy            = Util.UserId,
                            CreatedDate          = DateTime.Now,
                            ContributionDate     = pledge.Date,
                            FundId               = f.FundId,
                            ContributionStatusId = 0,
                            ContributionTypeId   = ContributionTypeCode.Pledge,
                            ContributionAmount   = pledge.Amount,
                            PeopleId             = pid,
                            CheckNo              = pledge.CheckNo,
                            ContributionDesc     = pledge.GiftDescription
                        }
                    };
                    bh.BundleDetails.Add(bd);

                    // save orphaned pledges
                    if (!Testing)
                    {
                        var currentOrphans = JobDbContext.Content("OrphanedPledges", "---", ContentTypeCode.TypeText);
                        currentOrphans.Body = _orphanedPledges.ToString();
                        JobDbContext.SubmitChanges();
                    }

                    rt.Processed++;
                    ProgressDbContext.SubmitChanges();
                }
            }

            FinishBundle(JobDbContext, bh);
        }