Пример #1
0
        public ActionResult Index(HttpPostedFileBase file, bool noupdate, bool ignoremissinggifts)
        {
            string host = Util.Host;
            var    pid  = Util.UserPeopleId;

            var package = new ExcelPackage(file.InputStream);

            HostingEnvironment.QueueBackgroundWorkItem(ct =>
            {
                try
                {
                    var localDbInstance = DbUtil.Create(host);

                    UploadPeopleRun testrun = ProcessImport(localDbInstance, noupdate, ignoremissinggifts, host, pid, package, true);
                    UploadPeopleRun realrun = ProcessImport(localDbInstance, noupdate, ignoremissinggifts, host, pid, package, false);
                }
                catch (Exception ex)
                {
                    //CurrentDatabase.Dispose();
                    //db = DbUtil.Create(host);

                    //var q = from r in CurrentDatabase.UploadPeopleRuns
                    //        where r.Id == CurrentDatabase.UploadPeopleRuns.Max(rr => rr.Id)
                    //        select r;
                    Elmah.ErrorLog.GetDefault(null).Log(new Elmah.Error(ex));
                    //var rt = q.Single();
                    //rt.Error = ex.Message.Truncate(200);
                    //CurrentDatabase.SubmitChanges();
                }
            });
            return(Redirect("/UploadExcelIps/Progress"));
        }
Пример #2
0
        public ActionResult UploadAddresses(string text)
        {
            string host = Util.Host;
            var    pid  = Util.UserPeopleId;

            HostingEnvironment.QueueBackgroundWorkItem(ct =>
            {
                var db = DbUtil.Create(host);
                try
                {
                    var runningtotals = new UploadPeopleRun {
                        Started = DateTime.Now, Count = 0, Processed = 0
                    };
                    db.UploadPeopleRuns.InsertOnSubmit(runningtotals);
                    db.SubmitChanges();

                    var m = new UploadAddressesModel(db, pid ?? 0);
                    m.DoUpload(text);
                }
                catch (Exception ex)
                {
                    db.Dispose();
                    db = DbUtil.Create(host);

                    var q = from r in db.UploadPeopleRuns
                            where r.Id == db.UploadPeopleRuns.Max(rr => rr.Id)
                            select r;
                    Elmah.ErrorLog.GetDefault(null).Log(new Elmah.Error(ex));
                    var rt   = q.Single();
                    rt.Error = ex.Message.Truncate(200);
                    db.SubmitChanges();
                }
            });
            return(Redirect("/Batch/UploadAddressesProgress"));
        }
        public ActionResult Upload(string text, bool noupdate)
        {
            string host          = Util.Host;
            var    runningtotals = new UploadPeopleRun {
                Started = DateTime.Now, Count = 0, Processed = 0
            };

            DbUtil.Db.UploadPeopleRuns.InsertOnSubmit(runningtotals);
            DbUtil.Db.SubmitChanges();
            var pid = Util.UserPeopleId;
            var cs  = Util.GetConnectionString(host);

            Alias.Task.Factory.StartNew(() =>
            {
                Thread.CurrentThread.Priority = ThreadPriority.Lowest;
                var Db  = new CMSDataContext(cs);
                Db.Host = host;
                try
                {
                    var m = new UploadPeopleModel(Db, pid ?? 0, noupdate, cs);
                    m.DoUpload(text, testing: true);
                    Db.Dispose();
                    Db      = new CMSDataContext(cs);
                    Db.Host = host;

                    runningtotals = new UploadPeopleRun {
                        Started = DateTime.Now, Count = 0, Processed = 0
                    };
                    Db.UploadPeopleRuns.InsertOnSubmit(runningtotals);
                    Db.SubmitChanges();

                    m = new UploadPeopleModel(Db, pid ?? 0, noupdate, cs);
                    m.DoUpload(text);
                }
                catch (Exception ex)
                {
                    Db.Dispose();
                    Db      = new CMSDataContext(cs);
                    Db.Host = host;

                    var q = from r in Db.UploadPeopleRuns
                            where r.Id == Db.UploadPeopleRuns.Max(rr => rr.Id)
                            select r;
                    Elmah.ErrorLog.GetDefault(null).Log(new Elmah.Error(ex));
                    var rt   = q.Single();
                    rt.Error = ex.Message.Truncate(200);
                    Db.SubmitChanges();
                }
            });
            return(Redirect("/UploadPeople/Progress"));
        }
Пример #4
0
        private UploadPeopleRun ProcessImport(CMSDataContext db, bool noupdate, bool ignoremissinggifts, string host, int?pid, ExcelPackage package, bool testing)
        {
            var rt = new UploadPeopleRun {
                Started = DateTime.Now, Count = 0, Processed = 0
            };

            db.UploadPeopleRuns.InsertOnSubmit(rt);
            db.SubmitChanges();

            var upload = new UploadExcelIpsModel(db, host, pid ?? 0, noupdate, ignoremissinggifts, testing);

            upload.DoUpload(package);
            return(rt);
        }
Пример #5
0
        public ActionResult Index(HttpPostedFileBase file, bool noupdate)
        {
            string host          = Util.Host;
            var    runningtotals = new UploadPeopleRun {
                Started = DateTime.Now, Count = 0, Processed = 0
            };

            CurrentDatabase.UploadPeopleRuns.InsertOnSubmit(runningtotals);
            CurrentDatabase.SubmitChanges();
            var pid = Util.UserPeopleId;

            var package = new ExcelPackage(file.InputStream);

            HostingEnvironment.QueueBackgroundWorkItem(ct =>
            {
                try
                {
                    var db = DbUtil.Create(host);

                    var m = new UploadPeopleModel(host, pid ?? 0, noupdate, testing: true);
                    m.DoUpload(package);
                    CurrentDatabase.Dispose();
                    db = DbUtil.Create(host);

                    runningtotals = new UploadPeopleRun {
                        Started = DateTime.Now, Count = 0, Processed = 0
                    };
                    db.UploadPeopleRuns.InsertOnSubmit(runningtotals);
                    db.SubmitChanges();

                    m = new UploadPeopleModel(host, pid ?? 0, noupdate);
                    m.DoUpload(package);
                }
                catch (Exception ex)
                {
                    //CurrentDatabase.Dispose();
                    var db = DbUtil.Create(host);

                    var q = from r in db.UploadPeopleRuns
                            where r.Id == db.UploadPeopleRuns.Max(rr => rr.Id)
                            select r;
                    Elmah.ErrorLog.GetDefault(null).Log(new Elmah.Error(ex));
                    var rt   = q.Single();
                    rt.Error = ex.Message.Truncate(200);
                    db.SubmitChanges();
                }
            });
            return(Redirect("/UploadPeople/Progress"));
        }
Пример #6
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);
        }
Пример #7
0
        internal void UploadPeople(UploadPeopleRun rt, ExcelWorksheet ws)
        {
            Extravaluenames = (from name in Names
                               where !Standardnames.Contains(name.Key, StringComparer.OrdinalIgnoreCase)
                               where !Standardrecregnames.Contains(name.Key)
                               select name.Key).ToList();

            Recregnames = (from name in Names
                           where Standardrecregnames.Contains(name.Key)
                           select name.Key).ToList();

            if (Names.ContainsKey("Campus"))
            {
                var campuslist = (from li in Datalist
                                  group li by(string) li.Campus
                                  into campus
                                  where campus.Key.HasValue()
                                  select campus.Key).ToList();
                var dbc = from c in campuslist
                          join cp in JobDbContext.Campus on c equals cp.Description into j
                          from cp in j.DefaultIfEmpty()
                          select new { cp, c };
                var clist = dbc.ToList();
                if (clist.Count > 0)
                {
                    var maxcampusid = 0;
                    if (JobDbContext.Campus.Any())
                    {
                        maxcampusid = JobDbContext.Campus.Max(c => c.Id);
                    }

                    foreach (var i in clist)
                    {
                        if (i.cp != null)
                        {
                            continue;
                        }

                        var cp = new Campu {
                            Description = i.c, Id = ++maxcampusid
                        };
                        if (!Testing)
                        {
                            JobDbContext.Campus.InsertOnSubmit(cp);
                        }
                    }
                }
            }

            if (!Testing)
            {
                JobDbContext.SubmitChanges();
            }

            Campuses = JobDbContext.Campus.ToDictionary(cp => cp.Description, cp => cp.Id);

            var q = (from li in Datalist
                     group li by li.FamilyId
                     into fam
                     select fam).ToList();

            rt.Count       = q.Sum(ff => ff.Count());
            rt.Description = $"Uploading People {(Testing ? "in testing mode" : "for real")}";
            ProgressDbContext.SubmitChanges();

            foreach (var fam in q)
            {
                var prevpid = 0;

                foreach (var a in fam)
                {
                    if (!Testing)
                    {
                        JobDbContext.SubmitChanges();
                    }

                    Family f            = null;
                    var    potentialdup = false;
                    int?   pid          = FindRecord(JobDbContext, a, ref potentialdup);
                    if (pid == -1) // no data: no first or last name
                    {
                        continue;
                    }

                    var p = pid.HasValue
                        ? UpdateRecord(JobDbContext, pid.Value, a)
                        : NewRecord(JobDbContext, ref f, a, prevpid, potentialdup);
                    prevpid = p.PeopleId;

                    if (Recregnames.Any())
                    {
                        SetRecRegs(p, a);
                    }

                    if (Extravaluenames.Any())
                    {
                        ProcessExtraValues(JobDbContext, p, a);
                    }

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

                if (!Testing)
                {
                    JobDbContext.SubmitChanges();
                }
            }
        }
Пример #8
0
        private void UploadPledges(UploadPeopleRun rt, ExcelPackage pkg)
        {
            //var db = DbUtil.Create(Host);
            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;
            Db2.SubmitChanges();

            var weeks = (from g in data
                         group g by g.Date.Sunday() into weeklypledges
                         select weeklypledges).ToList();
            BundleHeader bh = null;
            var          c  = Db2.Content("OrphanedPledges", "---", ContentTypeCode.TypeText);

            c.Body = "";
            Db2.SubmitChanges();
            foreach (var week in weeks)
            {
                FinishBundle(Db2, bh);
                //if (!Testing)
                //{
                //    Db2.Dispose();
                //    db = DbUtil.Create(Host);
                //}
                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)
                            {
                                c       = Db2.Content("OrphanedPledges");
                                c.Body += $"{pledge.IndividualId} {pledge.Date:d} {pledge.Amount:C}\n";
                                Db2.SubmitChanges();
                                continue;
                            }
                            else
                            {
                                throw new Exception($"peopleid not found from individualid {pledge.IndividualId}");
                            }
                        }

                        f = Db2.FetchOrCreateFund(pledge.FundId, pledge.FundName ?? pledge.FundDescription);
                        f.FundPledgeFlag = true;
                    }
                    var bd = new BundleDetail();
                    bd.CreatedBy    = Util.UserId;
                    bd.CreatedDate  = DateTime.Now;
                    bd.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
                    };
                    bh.BundleDetails.Add(bd);
                    rt.Processed++;
                    Db2.SubmitChanges();
                }
            }
            FinishBundle(Db2, bh);
            //if (!Testing)
            //{
            //    DbUtil.Db.Dispose();
            //}
        }
Пример #9
0
        private void UploadGifts(UploadPeopleRun rt, ExcelPackage pkg)
        {
            var db   = DbUtil.Create(Host);
            var data = FetchContributionData(pkg.Workbook.Worksheets["Gift Data"]).ToList();

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

            var weeks = (from g in data
                         group g by g.Date.Sunday() into weeklygifts
                         select weeklygifts).ToList();
            BundleHeader bh = null;
            var          c  = db.Content("OrphanedGifts", "---", ContentTypeCode.TypeText);

            c.Body = "";
            db.SubmitChanges();
            foreach (var week in weeks)
            {
                FinishBundle(db, bh);
                if (!Testing)
                {
                    db.Dispose();
                    db = DbUtil.Create(Host);
                }
                bh = new BundleHeader
                {
                    BundleHeaderTypeId = BundleTypeCode.ChecksAndCash,
                    BundleStatusId     = BundleStatusCode.Closed,
                    CreatedBy          = Util.UserId,
                    CreatedDate        = DateTime.Today,
                    ContributionDate   = week.Key,
                };
                foreach (var gift in week)
                {
                    var pid = GetPeopleId(gift);
                    if (!Testing)
                    {
                        if (!pid.HasValue)
                        {
                            if (IgnoreMissingGifts)
                            {
                                c       = db.Content("OrphanedGifts");
                                c.Body += $"{gift.IndividualId} {gift.Date:d} {gift.Amount:C}\n";
                                db.SubmitChanges();
                                continue;
                            }
                            else
                            {
                                throw new Exception($"peopleid not found from individualid {gift.IndividualId}");
                            }
                        }
                    }
                    if (!Testing)
                    {
                        db.FetchOrCreateFund(gift.FundId, gift.FundName ?? gift.FundDescription);
                    }
                    var bd = new BundleDetail();
                    bd.CreatedBy    = Util.UserId;
                    bd.CreatedDate  = DateTime.Now;
                    bd.Contribution = new Contribution
                    {
                        CreatedBy            = Util.UserId,
                        CreatedDate          = DateTime.Now,
                        ContributionDate     = gift.Date,
                        FundId               = gift.FundId,
                        ContributionStatusId = 0,
                        ContributionTypeId   = ContributionTypeCode.CheckCash,
                        ContributionAmount   = gift.Amount,
                        CheckNo              = gift.CheckNo,
                        PeopleId             = pid
                    };
                    bh.BundleDetails.Add(bd);
                    rt.Processed++;
                    Db2.SubmitChanges();
                }
            }
            FinishBundle(db, bh);
            if (!Testing)
            {
                db.Dispose();
            }
        }
Пример #10
0
        private void UploadPeople(UploadPeopleRun rt, ExcelPackage pkg)
        {
            var db = DbUtil.Create(host);

            peopleids = db.PeopleExtras.Where(vv => vv.Field == "IndividualId" && vv.IntValue != null)
                        .ToDictionary(vv => vv.IntValue ?? 0, vv => vv.PeopleId);
            FetchData(pkg.Workbook.Worksheets["Personal Data"]);

            extravaluenames = (from name in names
                               where !standardnames.Contains(name.Key, StringComparer.OrdinalIgnoreCase)
                               where !standardrecregnames.Contains(name.Key)
                               select name.Key).ToList();
            recregnames = (from name in names
                           where standardrecregnames.Contains(name.Key)
                           select name.Key).ToList();

            if (names.ContainsKey("Campus"))
            {
                var campuslist = (from li in datalist
                                  group li by((string)li.Campus)
                                  into campus
                                  where campus.Key.HasValue()
                                  select campus.Key).ToList();
                var dbc = from c in campuslist
                          join cp in db.Campus on c equals cp.Description into j
                          from cp in j.DefaultIfEmpty()
                          select new { cp, c };
                var clist = dbc.ToList();
                if (clist.Count > 0)
                {
                    var maxcampusid = 0;
                    if (db.Campus.Any())
                    {
                        maxcampusid = db.Campus.Max(c => c.Id);
                    }
                    foreach (var i in clist)
                    {
                        if (i.cp == null)
                        {
                            var cp = new Campu {
                                Description = i.c, Id = ++maxcampusid
                            };
                            if (!Testing)
                            {
                                db.Campus.InsertOnSubmit(cp);
                            }
                        }
                    }
                }
            }
            if (!Testing)
            {
                db.SubmitChanges();
            }
            campuses = db.Campus.ToDictionary(cp => cp.Description, cp => cp.Id);

            var q = (from li in datalist
                     group li by li.FamilyId
                     into fam
                     select fam).ToList();

            rt.Count       = q.Sum(ff => ff.Count());
            rt.Description = $"Uploading People {(Testing ? "in testing mode" : "for real")}";
            db2.SubmitChanges();

            foreach (var fam in q)
            {
                var prevpid = 0;

                foreach (var a in fam)
                {
                    if (!Testing)
                    {
                        db.SubmitChanges();
                        db.Dispose();
                        db = DbUtil.Create(host);
                    }

                    Family f            = null;
                    var    potentialdup = false;
                    int?   pid          = FindRecord(db, a, ref potentialdup);
                    var    p            = pid.HasValue
                        ? UpdateRecord(db, pid.Value, a)
                        : NewRecord(db, ref f, a, prevpid, potentialdup);
                    prevpid = p.PeopleId;

                    if (recregnames.Any())
                    {
                        SetRecRegs(p, a);
                    }

                    if (extravaluenames.Any())
                    {
                        ProcessExtraValues(db, p, a);
                    }

                    rt.Processed++;
                    db2.SubmitChanges();
                }
                if (!Testing)
                {
                    db.SubmitChanges();
                }
            }
        }
Пример #11
0
        private void UploadPledges(UploadPeopleRun rt, ExcelPackage pkg)
        {
            var db   = DbUtil.Create(host);
            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;
            db2.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(db, bh);
                if (!Testing)
                {
                    db.Dispose();
                    db = DbUtil.Create(host);
                }
                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.IndividualId);
                    if (!pid.HasValue)
                    {
                        throw new Exception($"peopleid not found from individualid {pledge.IndividualId}");
                    }
                    if (!Testing)
                    {
                        var f = db.FetchOrCreateFund(pledge.FundId, pledge.FundName ?? pledge.FundDescription);
                        f.FundPledgeFlag = true;
                    }
                    var bd = new BundleDetail();
                    bd.CreatedBy    = Util.UserId;
                    bd.CreatedDate  = DateTime.Now;
                    bd.Contribution = new Contribution
                    {
                        CreatedBy            = Util.UserId,
                        CreatedDate          = DateTime.Now,
                        ContributionDate     = pledge.Date,
                        FundId               = pledge.FundId,
                        ContributionStatusId = 0,
                        ContributionTypeId   = ContributionTypeCode.Pledge,
                        ContributionAmount   = pledge.Amount,
                        PeopleId             = pid
                    };
                    bh.BundleDetails.Add(bd);
                    rt.Processed++;
                    db2.SubmitChanges();
                }
            }
            FinishBundle(db, bh);
            if (!Testing)
            {
                db.Dispose();
            }
        }