Esempio n. 1
0
        public static void DoWork(string host, int id)
        {
            var db = DbUtil.Create(host);

            db.RepairTransactions(id);
            // finished
            var lop = FetchLongRunningOp(db, id, Op);

            lop.Completed = DateTime.Now;
            db.SubmitChanges();
        }
Esempio n. 2
0
        public static void DoWork(RepairTransactions model)
        {
            var db = DbUtil.Create(model.Host);

            db.RepairTransactions(model.OrgId);
            // finished
            var lop = FetchLongRunningOperation(db, Op, model.QueryId);

            lop.Completed = DateTime.Now;
            db.SubmitChanges();
        }
Esempio n. 3
0
        public IdentityServiceDbContext <IdentityUser, IdentityServiceApplication> CreateContext(bool delete = false)
        {
            var db = DbUtil.Create <TestContext>(_fixture.ConnectionString);

            if (delete)
            {
                db.Database.EnsureDeleted();
            }
            db.Database.EnsureCreated();
            return(db);
        }
Esempio n. 4
0
        public ActionResult Find(string fromDate, string toDate)
        {
            var    fdt           = fromDate.ToDate();
            var    tdt           = toDate.ToDate();
            string host          = Util.Host;
            var    runningtotals = new DuplicatesRun
            {
                Started   = DateTime.Now,
                Count     = 0,
                Processed = 0,
                Found     = 0
            };

            CurrentDatabase.DuplicatesRuns.InsertOnSubmit(runningtotals);
            CurrentDatabase.SubmitChanges();

            HostingEnvironment.QueueBackgroundWorkItem(ct =>
            {
                var db = DbUtil.Create(host);
                var rt = db.DuplicatesRuns.OrderByDescending(mm => mm.Id).First();
                db.ExecuteCommand("delete duplicate");
                var q = from p in db.People
                        where p.CreatedDate > fdt
                        where p.CreatedDate < tdt.Value.AddDays(1)
                        select p.PeopleId;
                rt.Count = q.Count();
                db.SubmitChanges();
                foreach (var p in q)
                {
                    var pids = db.FindPerson4(p);
                    rt.Processed++;
                    db.SubmitChanges();
                    if (!pids.Any())
                    {
                        continue;
                    }

                    foreach (var pid in pids)
                    {
                        if (pid.PeopleId != null)
                        {
                            db.InsertDuplicate(p, pid.PeopleId.Value);
                        }
                    }

                    rt.Found++;
                }
                rt.Completed = DateTime.Now;
                db.SubmitChanges();
            });
            return(Redirect("/Duplicates/Progress"));
        }
Esempio n. 5
0
        public ActionResult Start(int tag, int orgid)
        {
            var runningtotals = new AddToOrgFromTagRun
            {
                Started   = DateTime.Now,
                Count     = 0,
                Processed = 0,
                Orgid     = orgid
            };

            DbUtil.Db.AddToOrgFromTagRuns.InsertOnSubmit(runningtotals);
            DbUtil.Db.SubmitChanges();
            var host = Util.Host;
            var qid  = DbUtil.Db.FetchLastQuery().Id;

            System.Threading.Tasks.Task.Factory.StartNew(() =>
            {
                Thread.CurrentThread.Priority = ThreadPriority.BelowNormal;
                var Db  = DbUtil.Create(host);
                var cul = Db.Setting("Culture", "en-US");
                Thread.CurrentThread.CurrentUICulture = new CultureInfo(cul);
                Thread.CurrentThread.CurrentCulture   = CultureInfo.CreateSpecificCulture(cul);
                IEnumerable <int> q = null;
                if (tag == -1)                 // (last query)
                {
                    q = Db.PeopleQuery(qid).Select(pp => pp.PeopleId);
                }
                else
                {
                    q = from t in Db.TagPeople
                        where t.Id == tag
                        select t.PeopleId;
                }
                var pids = q.ToList();
                foreach (var pid in pids)
                {
                    Db.Dispose();
                    Db = DbUtil.Create(host);
                    OrganizationMember.InsertOrgMembers(Db,
                                                        orgid, pid, MemberTypeCode.Member, DateTime.Now, null, false);
                    var r = Db.AddToOrgFromTagRuns.Where(mm => mm.Orgid == orgid).OrderByDescending(mm => mm.Id).First();
                    r.Processed++;
                    r.Count = pids.Count;
                    Db.SubmitChanges();
                }
                var rr       = Db.AddToOrgFromTagRuns.Where(mm => mm.Orgid == orgid).OrderByDescending(mm => mm.Id).First();
                rr.Completed = DateTime.Now;
                Db.SubmitChanges();
                Db.UpdateMainFellowship(orgid);
            });
            return(Redirect("/AddToOrgPrevFromTag/Progress/" + orgid));
        }
Esempio n. 6
0
        public ActionResult CreateMeetings(DateTime dt, bool noautoabsents, OrgSearchModel model)
        {
            var orgIds = model.FetchOrgs().Select(oo => oo.OrganizationId).ToList();

            foreach (var oid in orgIds)
            {
                var db = DbUtil.Create(Util.Host);
                Meeting.FetchOrCreateMeeting(db, oid, dt, noautoabsents);
                db.Dispose();
            }
            DbUtil.LogActivity("Creating new meetings from OrgSearch");
            return(Content("done"));
        }
Esempio n. 7
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"));
        }
Esempio n. 8
0
        public void Update()
        {
            var pids = (from p in People(DbUtil.Db.CurrentOrg) select p.PeopleId).ToList();

            foreach (var pid in pids)
            {
                DbUtil.DbDispose();
                DbUtil.Db = DbUtil.Create(Util.Host);
                var om = DbUtil.Db.OrganizationMembers.Single(mm => mm.PeopleId == pid && mm.OrganizationId == Id);

                var changes = new List <ChangeDetail>();
                if (InactiveDate.HasValue)
                {
                    om.UpdateValue(changes, "InactiveDate", InactiveDate);
                }
                if (RemoveInactiveDate)
                {
                    om.UpdateValue(changes, "InactiveDate", null);
                }

                if (EnrollmentDate.HasValue)
                {
                    om.UpdateValue(changes, "EnrollmentDate", EnrollmentDate);
                }

                om.Pending = Pending;

                if (MemberType.Value != "0")
                {
                    om.UpdateValue(changes, "MemberTypeId", MemberType.Value.ToInt());
                }

                if (MakeMemberTypeOriginal)
                {
                    var et = (from e in DbUtil.Db.EnrollmentTransactions
                              where e.PeopleId == om.PeopleId
                              where e.OrganizationId == Id
                              orderby e.TransactionDate
                              select e).First();
                    et.MemberTypeId = om.MemberTypeId;
                }

                DbUtil.Db.SubmitChanges();
                foreach (var g in changes)
                {
                    DbUtil.LogActivity("OrgMem change " + g.Field, om.OrganizationId, om.PeopleId);
                }
            }
        }
Esempio n. 9
0
 internal void PostTransactions()
 {
     foreach (var pid in Pids)
     {
         var db = DbUtil.Create(Util.Host);
         var om = DbUtil.Db.OrganizationMembers.Single(mm => mm.PeopleId == pid && mm.OrganizationId == OrgId);
         var ts = DbUtil.Db.ViewTransactionSummaries.SingleOrDefault(
             tt => tt.RegId == om.TranId && tt.PeopleId == om.PeopleId);
         var reason = ts == null ? "Initial Tran" : "Adjustment";
         var descriptionForPayment = OnlineRegModel.GetDescriptionForPayment(OrgId);
         om.AddTransaction(DbUtil.Db, reason, Payment ?? 0, Description, Amount, AdjustFee, descriptionForPayment);
         DbUtil.Db.SubmitChanges();
         DbUtil.LogActivity("OrgMem " + reason, OrgId, pid);
     }
 }
Esempio n. 10
0
        private static void DoWork(AddToOrgFromTag model)
        {
            Thread.CurrentThread.Priority = ThreadPriority.BelowNormal;
            var db  = DbUtil.Create(model.host);
            var cul = db.Setting("Culture", "en-US");

            Thread.CurrentThread.CurrentUICulture = new CultureInfo(cul);
            Thread.CurrentThread.CurrentCulture   = CultureInfo.CreateSpecificCulture(cul);

            LongRunningOp lop = null;

            foreach (var pid in model.pids)
            {
                db.Dispose();
                db = DbUtil.Create(model.host);
                switch (model.Group)
                {
                case GroupSelectCode.Member:
                    OrganizationMember.InsertOrgMembers(db, model.Id, pid, MemberTypeCode.Member, DateTime.Now, null, pending: false);
                    break;

                case GroupSelectCode.Pending:
                    OrganizationMember.InsertOrgMembers(db, model.Id, pid, MemberTypeCode.Member, DateTime.Now, null, pending: true);
                    break;

                case GroupSelectCode.Prospect:
                    OrganizationMember.InsertOrgMembers(db, model.Id, pid, MemberTypeCode.Prospect, DateTime.Now, null, pending: false);
                    break;

                case GroupSelectCode.Inactive:
                    OrganizationMember.InsertOrgMembers(db, model.Id, pid, MemberTypeCode.InActive, DateTime.Now, DateTime.Now, pending: false);
                    break;

                case GroupSelectCode.Previous:
                    Organization.AddAsPreviousMember(db, model.Id, pid, model.OrgName, MemberTypeCode.InActive, DateTime.Now, DateTime.Now, model.UserId);
                    break;
                }
                lop = FetchLongRunningOp(db, model.Id, Op);
                Debug.Assert(lop != null, "r != null");
                lop.Processed++;
                db.SubmitChanges();
                db.LogActivity($"Org{model.GroupName} AddFromTag", model.Id, pid);
            }
            // finished
            lop           = FetchLongRunningOp(db, model.Id, Op);
            lop.Completed = DateTime.Now;
            db.SubmitChanges();
        }
Esempio n. 11
0
        public ActionResult Find(string FromDate, string ToDate)
        {
            var    fdt           = FromDate.ToDate();
            var    tdt           = ToDate.ToDate();
            string host          = Util.Host;
            var    runningtotals = new DuplicatesRun
            {
                Started   = DateTime.Now,
                Count     = 0,
                Processed = 0,
                Found     = 0
            };

            DbUtil.Db.DuplicatesRuns.InsertOnSubmit(runningtotals);
            DbUtil.Db.SubmitChanges();

            Alias.Task.Factory.StartNew(() =>
            {
                Thread.CurrentThread.Priority = ThreadPriority.Lowest;
                var Db = DbUtil.Create(host);
                var rt = Db.DuplicatesRuns.OrderByDescending(mm => mm.Id).First();
                Db.ExecuteCommand("delete duplicate");
                var q = from p in Db.People
                        where p.CreatedDate > fdt
                        where p.CreatedDate < tdt.Value.AddDays(1)
                        select p.PeopleId;
                rt.Count = q.Count();
                Db.SubmitChanges();
                foreach (var p in q)
                {
                    var pids = Db.FindPerson4(p);
                    rt.Processed++;
                    Db.SubmitChanges();
                    if (pids.Count() == 0)
                    {
                        continue;
                    }
                    foreach (var pid in pids)
                    {
                        Db.InsertDuplicate(p, pid.PeopleId.Value);
                    }
                    rt.Found++;
                }
                rt.Completed = DateTime.Now;
                Db.SubmitChanges();
            });
            return(Redirect("/Duplicates/Progress"));
        }
Esempio n. 12
0
        internal void PostTransactions()
        {
            var pids = (from p in People(DbUtil.Db.CurrentOrg) select p.PeopleId).ToList();

            foreach (var pid in pids)
            {
                var db = DbUtil.Create(Util.Host);
                var om = db.OrganizationMembers.Single(mm => mm.PeopleId == pid && mm.OrganizationId == Id);
                var ts = db.ViewTransactionSummaries.SingleOrDefault(
                    tt => tt.RegId == om.TranId && tt.PeopleId == om.PeopleId);
                var reason = ts == null ? "Initial Tran" : "Adjustment";
                om.AddTransaction(db, reason, Payment ?? 0, Description, Amount, AdjustFee);
                db.SubmitChanges();
                DbUtil.LogActivity("OrgMem " + reason, Id, pid);
            }
        }
Esempio n. 13
0
        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;

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

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

                    m = new UploadPeopleModel(Db, pid ?? 0, noupdate);
                    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("/UploadPeople/Progress"));
        }
Esempio n. 14
0
        private void DoWork(OrgSearchDrop model)
        {
            Thread.CurrentThread.Priority = ThreadPriority.BelowNormal;
            var db  = DbUtil.Create(model.host);
            var cul = db.Setting("Culture", "en-US");

            Thread.CurrentThread.CurrentUICulture = new CultureInfo(cul);
            Thread.CurrentThread.CurrentCulture   = CultureInfo.CreateSpecificCulture(cul);

            LongRunningOp lop = null;

            foreach (var orginfo in model.orginfos)
            {
                var pids = (from m in db.OrganizationMembers
                            where m.OrganizationId == orginfo.Id
                            select m.PeopleId
                            ).ToList();
                var n = 0;
                foreach (var pid in pids)
                {
                    n++;
                    db.Dispose();
                    db = DbUtil.Create(model.host);
                    var om = db.OrganizationMembers.Single(mm => mm.PeopleId == pid && mm.OrganizationId == orginfo.Id);
                    if (DropDate.HasValue)
                    {
                        om.Drop(db, DropDate.Value);
                    }
                    else
                    {
                        om.Drop(db);
                    }
                    lop = FetchLongRunningOp(db, model.Id, Op);
                    Debug.Assert(lop != null, "r != null");
                    lop.Processed++;
                    lop.CustomMessage = $"Working on {orginfo.Name}, {n}/{pids.Count}";
                    db.SubmitChanges();
                }
                var o = db.LoadOrganizationById(orginfo.Id);
                o.OrganizationStatusId = CmsData.Codes.OrgStatusCode.Inactive;
                db.SubmitChanges();
            }
            // finished
            lop           = FetchLongRunningOp(db, model.Id, Op);
            lop.Completed = DateTime.Now;
            db.SubmitChanges();
        }
Esempio n. 15
0
        public string AddSmallGroup(int sgtagid)
        {
            var name = DbUtil.Db.MemberTags.Single(mm => mm.Id == sgtagid && mm.OrgId == OrgId).Name;

            foreach (var pid in Pids)
            {
                DbUtil.DbDispose();
                DbUtil.Db = DbUtil.Create(Util.Host);
                var om = DbUtil.Db.OrganizationMembers.Single(mm => mm.PeopleId == pid && mm.OrganizationId == OrgId);
                var nn = om.AddToGroup(DbUtil.Db, sgtagid);
                if (nn == 1)
                {
                    DbUtil.LogActivity("OrgMem AddSubGroup " + name, om.OrganizationId, om.PeopleId);
                }
            }
            return($"{Pids.Count} added to sub-group {name}");
        }
Esempio n. 16
0
        public ActionResult Index(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;

            HostingEnvironment.QueueBackgroundWorkItem(ct =>
            {
                var Db = DbUtil.Create(host);
                try
                {
                    var m = new UploadPeopleModel(host, pid ?? 0, noupdate, testing: true);
                    m.DoUpload(text);
                    Db.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(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("/UploadPeople/Progress"));
        }
Esempio n. 17
0
        public static void DoWork(ValidateAddress model)
        {
            Thread.CurrentThread.Priority = ThreadPriority.BelowNormal;
            var db  = DbUtil.Create(model.host);
            var cul = db.Setting("Culture", "en-US");

            Thread.CurrentThread.CurrentUICulture = new CultureInfo(cul);
            Thread.CurrentThread.CurrentCulture   = CultureInfo.CreateSpecificCulture(cul);

            LongRunningOp lop = null;

            foreach (var pid in model.pids)
            {
                db.Dispose();
                var fsb = new List <ChangeDetail>();
                db = DbUtil.Create(model.host);
                var f   = db.LoadFamilyByPersonId(pid);
                var ret = AddressVerify.LookupAddress(f.AddressLineOne, f.AddressLineTwo, f.CityName, f.StateCode, f.ZipCode);
                if (ret.found != false && !ret.error.HasValue() && ret.Line1 != "error")
                {
                    f.UpdateValue(fsb, "AddressLineOne", ret.Line1);
                    f.UpdateValue(fsb, "AddressLineTwo", ret.Line2);
                    f.UpdateValue(fsb, "CityName", ret.City);
                    f.UpdateValue(fsb, "StateCode", ret.State);
                    f.UpdateValue(fsb, "ZipCode", ret.Zip.GetDigits());
                    var rc = db.FindResCode(ret.Zip, null);
                    f.UpdateValue(fsb, "ResCodeId", rc.ToString());
                }
                else
                {
                    f.UpdateValue(fsb, "ZipCode", f.ZipCode.Zip5());
                }

                lop = FetchLongRunningOp(db, model.Id, Op);
                Debug.Assert(lop != null, "r != null");
                lop.Processed++;
                f.LogChanges(db, fsb, pid, Util.UserPeopleId ?? 0);
                db.SubmitChanges();
                //Thread.Sleep(1000);
            }
            // finished
            lop           = FetchLongRunningOp(db, model.Id, Op);
            lop.Completed = DateTime.Now;
            db.SubmitChanges();
        }
Esempio n. 18
0
        public static void DoMoveWork(MoveOrgMembersModel model)
        {
            var jobStatusContext = DbUtil.Create(model.Host);
            var jobWorkerContext = DbUtil.Create(model.Host);

            jobWorkerContext.CommandTimeout = 2200;
            var cul = jobWorkerContext.Setting("Culture", "en-US");

            Thread.CurrentThread.CurrentUICulture = new CultureInfo(cul);
            Thread.CurrentThread.CurrentCulture   = CultureInfo.CreateSpecificCulture(cul);
            LongRunningOperation lop = null;

            foreach (var i in model.List) // {personId}.{organizationId}
            {
                var a = i.Split('.');
                if (a.Length != 2)
                {
                    continue;
                }

                var pid = a[0].ToInt();
                var oid = a[1].ToInt();

                if (oid == model.TargetId)
                {
                    continue;
                }

                OrganizationMember.MoveToOrg(jobWorkerContext, pid, oid, model.TargetId, model.MoveRegistrationData, model.ChangeMemberType == true ? model.MoveToMemberTypeId : -1);
                //Once member has been inserted into the new Organization then update member in Organizations as enrolled / not enrolled accordingly
                jobWorkerContext.RepairTransactions(oid);
                jobWorkerContext.RepairTransactions(model.TargetId);
                lop = FetchLongRunningOperation(jobStatusContext, Op, model.QueryId);
                Debug.Assert(lop != null, "r != null");
                lop.Processed++;
                lop.CustomMessage = $"Working from {pid},{oid} to {model.TargetId}";
                jobStatusContext.SubmitChanges();
            }
            // finished
            lop           = FetchLongRunningOperation(jobStatusContext, Op, model.QueryId);
            lop.Completed = DateTime.Now;
            jobStatusContext.SubmitChanges();
            jobWorkerContext.UpdateMainFellowship(model.TargetId);
        }
Esempio n. 19
0
        private string AddNewExtraValueToSelectionFromQuery()
        {
            var list = DbUtil.Db.PeopleQuery(QueryId).Select(pp => pp.PeopleId).ToList();

            if (ClearOldValuesFirst)
            {
                using (var db = DbUtil.Create(DbUtil.Db.Host))
                {
                    var q   = DbUtil.Db.PeopleQuery(QueryId).Select(pp => pp.PeopleId);
                    var tag = DbUtil.Db.PopulateTemporaryTag(q);
                    var cmd = AddToFamilyRecordInsteadOfPerson
                        ? "dbo.ClearFamilyExtraValuesForTag"
                        : "dbo.ClearExtraValuesForTag";
                    DbUtil.Db.ExecuteCommand(cmd + " {0}, {1}", ExtraValueName, tag.Id);
                }
            }

            if (AddToFamilyRecordInsteadOfPerson)
            {
                ExtraValueTable = "Family";
            }

            switch (AdhocExtraValueType.Value)
            {
            case "Code":
                return(AddNewExtraValueCodes(list));

            case "Text":
            case "Text2":
                return(AddNewExtraValueDatums(list));

            case "Date":
                return(AddNewExtraValueDates(list));

            case "Int":
                return(AddNewExtraValueInts(list));

            case "Bit":
                return(AddNewExtraValueBools(list));
            }
            DbUtil.LogActivity($"EV AddNewFromQuery {ExtraValueName} {AdhocExtraValueType.Value}");
            return(null);
        }
Esempio n. 20
0
        public string AddSmallGroup(int sgtagid)
        {
            var pids = (from p in People(DbUtil.Db.CurrentOrg) select p.PeopleId).ToList();
            var n    = 0;
            var name = DbUtil.Db.MemberTags.Single(mm => mm.Id == sgtagid && mm.OrgId == Id).Name;

            foreach (var pid in pids)
            {
                DbUtil.DbDispose();
                DbUtil.Db = DbUtil.Create(Util.Host);
                var om = DbUtil.Db.OrganizationMembers.Single(mm => mm.PeopleId == pid && mm.OrganizationId == Id);
                var nn = om.AddToGroup(DbUtil.Db, sgtagid);
                n += nn;
                if (nn == 1)
                {
                    DbUtil.LogActivity("OrgMem AddSubGroup " + name, om.OrganizationId, om.PeopleId);
                }
            }
            return($"{n} added to sub-group {name}");
        }
Esempio n. 21
0
        private void TryDeleteAllContributions()
        {
            if (Testing)
                return;
            var db = DbUtil.Create(Host);
            if (!db.Setting("UploadExcelIpsDeleteGifts"))
                return;

            var deletesql = @"
DELETE dbo.BundleDetail
FROM dbo.BundleDetail d
JOIN dbo.Contribution c ON d.ContributionId = c.ContributionId
DELETE dbo.Contribution
DELETE dbo.BundleHeader
DBCC CHECKIDENT ('[Contribution]', RESEED, 0)
DBCC CHECKIDENT ('[BundleHeader]', RESEED, 0)
DBCC CHECKIDENT ('[BundleDetail]', RESEED, 0)
";
            db.ExecuteCommand(deletesql);
        }
Esempio n. 22
0
        private static void DoWork(OrgDrop model)
        {
            var db  = DbUtil.Create(model.Host);
            var cul = db.Setting("Culture", "en-US");

            Thread.CurrentThread.CurrentUICulture = new CultureInfo(cul);
            Thread.CurrentThread.CurrentCulture   = CultureInfo.CreateSpecificCulture(cul);

            LongRunningOperation lop = null;

            foreach (var pid in model.Pids)
            {
                //DbUtil.Db.Dispose();
                //db = DbUtil.Create(model.Host);
                var om = db.OrganizationMembers.Single(mm => mm.PeopleId == pid && mm.OrganizationId == model.filter.Id);
                if (model.DropDate.HasValue)
                {
                    om.Drop(db, model.DropDate.Value);
                }
                else
                {
                    om.Drop(db);
                }

                db.SubmitChanges();
                if (model.RemoveFromEnrollmentHistory)
                {
                    db.ExecuteCommand("DELETE dbo.EnrollmentTransaction WHERE PeopleId = {0} AND OrganizationId = {1}", pid, model.filter.Id);
                }

                lop = FetchLongRunningOperation(db, Op, model.QueryId);
                Debug.Assert(lop != null, "r != null");
                lop.Processed++;
                db.SubmitChanges();
                db.LogActivity($"Org{model.DisplayGroup} Drop{(model.RemoveFromEnrollmentHistory ? " w/history" : "")}", model.filter.Id, pid, uid: model.UserId);
            }
            // finished
            lop           = FetchLongRunningOperation(db, Op, model.QueryId);
            lop.Completed = DateTime.Now;
            db.SubmitChanges();
        }
Esempio n. 23
0
        private void DoWork(OrgDrop model)
        {
            Thread.CurrentThread.Priority = ThreadPriority.BelowNormal;
            var db  = DbUtil.Create(model.host);
            var cul = db.Setting("Culture", "en-US");

            Thread.CurrentThread.CurrentUICulture = new CultureInfo(cul);
            Thread.CurrentThread.CurrentCulture   = CultureInfo.CreateSpecificCulture(cul);

            LongRunningOp lop = null;

            foreach (var pid in pids)
            {
                db.Dispose();
                db = DbUtil.Create(model.host);
                var om = db.OrganizationMembers.Single(mm => mm.PeopleId == pid && mm.OrganizationId == Id);
                if (DropDate.HasValue)
                {
                    om.Drop(db, DropDate.Value);
                }
                else
                {
                    om.Drop(db);
                }
                db.SubmitChanges();
                if (RemoveFromEnrollmentHistory)
                {
                    db.ExecuteCommand("DELETE dbo.EnrollmentTransaction WHERE PeopleId = {0} AND OrganizationId = {1}", pid, Id);
                }
                lop = FetchLongRunningOp(db, model.Id, Op);
                Debug.Assert(lop != null, "r != null");
                lop.Processed++;
                db.SubmitChanges();
                db.LogActivity($"Org{Group} Drop{(RemoveFromEnrollmentHistory ? " w/history" : "")}", Id, pid, UserId);
            }
            // finished
            lop           = FetchLongRunningOp(db, model.Id, Op);
            lop.Completed = DateTime.Now;
            db.SubmitChanges();
        }
Esempio n. 24
0
        public ActionResult Index(HttpPostedFileBase file, bool noupdate)
        {
            var host = Util.Host;
            var pid  = Util.UserPeopleId;

            var package = new ExcelPackage(file.InputStream);

            HostingEnvironment.QueueBackgroundWorkItem(ct =>
            {
                try
                {
                    using (var testdb = DbUtil.Create(host))
                    {
                        var testrun = ProcessImport(testdb, noupdate, host, pid, package, true);
                    }

                    using (var realdb = DbUtil.Create(host))
                    {
                        var realrun = ProcessImport(realdb, noupdate, host, pid, package, false);
                    }
                }
                catch (Exception ex)
                {
                    var db = DbUtil.Create(host);

                    var q = from r in db.UploadPeopleRuns
                            where r.Id == db.UploadPeopleRuns.Max(rr => rr.Id)
                            select r;

                    var rt   = q.Single();
                    rt.Error = ex.Message.Truncate(200);

                    db.SubmitChanges();

                    ErrorLog.GetDefault(null).Log(new Error(ex));
                }
            });

            return(Redirect("/UploadExcelIps/Progress"));
        }
Esempio n. 25
0
        private static void DoWork(DeleteMeeting model)
        {
            Thread.CurrentThread.Priority = ThreadPriority.BelowNormal;
            var db  = DbUtil.Create(model.host);
            var cul = db.Setting("Culture", "en-US");

            Thread.CurrentThread.CurrentUICulture = new CultureInfo(cul);
            Thread.CurrentThread.CurrentCulture   = CultureInfo.CreateSpecificCulture(cul);

            LongRunningOp lop = null;

            foreach (var pid in model.pids)
            {
                db.Dispose();
                db = DbUtil.Create(model.host);
                Attend.RecordAttendance(db, pid, model.Id, false);
                lop = FetchLongRunningOp(db, model.Id, Op);
                Debug.Assert(lop != null, "r != null");
                lop.Processed++;
                db.SubmitChanges();
            }
            db.ExecuteCommand(@"
DELETE dbo.SubRequest 
FROM dbo.SubRequest sr
JOIN dbo.Attend a ON a.AttendId = sr.AttendId
WHERE a.MeetingId = {0}
", model.Id);
            db.ExecuteCommand("DELETE dbo.VolRequest WHERE MeetingId = {0}", model.Id);
            db.ExecuteCommand("DELETE dbo.attend WHERE MeetingId = {0}", model.Id);
            db.ExecuteCommand("DELETE dbo.MeetingExtra WHERE MeetingId = {0}", model.Id);
            db.ExecuteCommand("DELETE dbo.meetings WHERE MeetingId = {0}", model.Id);

            db.SubmitChanges();

            // finished
            lop           = FetchLongRunningOp(db, model.Id, Op);
            lop.Completed = DateTime.Now;
            db.SubmitChanges();
        }
Esempio n. 26
0
        public static void DoMoveWork(MoveOrgMembersModel model)
        {
            var db = DbUtil.Create(model.Host);

            db.CommandTimeout = 2200;
            var cul = db.Setting("Culture", "en-US");

            Thread.CurrentThread.CurrentUICulture = new CultureInfo(cul);
            Thread.CurrentThread.CurrentCulture   = CultureInfo.CreateSpecificCulture(cul);
            LongRunningOperation lop = null;

            foreach (var i in model.List)
            {
                var a = i.Split('.');
                if (a.Length != 2)
                {
                    continue;
                }
                var pid = a[0].ToInt();
                var oid = a[1].ToInt();

                if (oid == model.TargetId)
                {
                    continue;
                }
                OrganizationMember.MoveToOrg(db, pid, oid, model.TargetId, model.MoveRegistrationData, model.ChangeMemberType == true ? model.MoveToMemberTypeId : -1);
                lop = FetchLongRunningOperation(db, Op, model.QueryId);
                Debug.Assert(lop != null, "r != null");
                lop.Processed++;
                lop.CustomMessage = $"Working from {pid},{oid} to {model.TargetId}";
                db.SubmitChanges();
            }
            // finished
            lop           = FetchLongRunningOperation(db, Op, model.QueryId);
            lop.Completed = DateTime.Now;
            db.SubmitChanges();
            db.UpdateMainFellowship(model.TargetId);
        }
Esempio n. 27
0
        public static void DoWork(RepairTransactionsOrgs model)
        {
            Thread.CurrentThread.Priority = ThreadPriority.BelowNormal;
            var db  = DbUtil.Create(model.host);
            var cul = db.Setting("Culture", "en-US");

            Thread.CurrentThread.CurrentUICulture = new CultureInfo(cul);
            Thread.CurrentThread.CurrentCulture   = CultureInfo.CreateSpecificCulture(cul);
            LongRunningOp lop = null;

            foreach (var oid in model.Orgs.Split(',').Select(mm => mm.ToInt()))
            {
                db.RepairTransactionsOrgs(oid);
                lop = FetchLongRunningOp(db, model.Id, Op);
                Debug.Assert(lop != null, "r != null");
                lop.Processed++;
                db.SubmitChanges();
            }
            // finished
            lop           = FetchLongRunningOp(db, model.Id, Op);
            lop.Completed = DateTime.Now;
            db.SubmitChanges();
        }
Esempio n. 28
0
        public static Person FindPerson(string first, string last, DateTime?DOB, string email, string phone, out int count)
        {
            count = 0;
            if (!first.HasValue() || !last.HasValue())
            {
                return(null);
            }
            first = first.Trim();
            last  = last.Trim();
            var fone = Util.GetDigits(phone);
            var ctx  = DbUtil.Create(Util.Host);

            ctx.SetNoLock();
            var q = from p in ctx.People
                    where (p.FirstName == first || p.NickName == first || p.MiddleName == first)
                    where (p.LastName == last || p.MaidenName == last)
                    select p;
            var list = q.ToList();

            count = list.Count;
            if (count == 0) // not going to find anything
            {
                ctx.Dispose();
                return(null);
            }

            if (DOB.HasValue && DOB > DateTime.MinValue)
            {
                var dt = DOB.Value;
                if (dt > Util.Now)
                {
                    dt = dt.AddYears(-100);
                }
                var q2 = from p in q
                         where p.BirthDay == dt.Day && p.BirthMonth == dt.Month && p.BirthYear == dt.Year
                         select p;
                count = q2.Count();
                if (count == 1) // use only birthday if there and unique
                {
                    return(PersonFound(ctx, q2));
                }
            }
            if (email.HasValue())
            {
                var q2 = from p in q
                         where p.EmailAddress == email
                         select p;
                count = q2.Count();
                if (count == 1)
                {
                    return(PersonFound(ctx, q2));
                }
            }
            if (phone.HasValue())
            {
                var q2 = from p in q
                         where p.CellPhone.Contains(fone) || p.Family.HomePhone.Contains(fone)
                         select p;
                count = q2.Count();
                if (count == 1)
                {
                    return(PersonFound(ctx, q2));
                }
            }
            return(null);
        }
Esempio n. 29
0
        public static void ProcessQueue(int iNewListID)
        {
            var sHost   = Util.Host;
            var sSID    = GetSid();
            var sToken  = GetToken();
            var iListID = iNewListID;

            if (sSID.Length == 0 || sToken.Length == 0)
            {
                return;
            }

            HostingEnvironment.QueueBackgroundWorkItem(ct =>
            {
                var stSID    = sSID;
                var stToken  = sToken;
                var itListID = iListID;

                try
                {
                    var db = DbUtil.Create(sHost);

                    var smsList = (from e in db.SMSLists
                                   where e.Id == itListID
                                   select e).Single();

                    var smsItems = from e in db.SMSItems
                                   where e.ListID == itListID
                                   select e;

                    var smsGroup = (from e in db.SMSNumbers
                                    where e.GroupID == smsList.SendGroupID
                                    select e).ToList();

                    var iCount = 0;

                    foreach (var item in smsItems)
                    {
                        if (item.NoNumber || item.NoOptIn)
                        {
                            continue;
                        }

                        var btSent = SendSms(stSID, stToken, smsGroup[iCount].Number, item.Number, smsList.Message);

                        if (btSent)
                        {
                            item.Sent = true;
                            db.SubmitChanges();
                        }

                        iCount++;
                        if (iCount >= smsGroup.Count())
                        {
                            iCount = 0;
                        }
                    }
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex);
                }
            });
        }
Esempio n. 30
0
        public bool DoUpload(string text)
        {
            var rt  = Db2.UploadPeopleRuns.OrderByDescending(mm => mm.Id).First();
            var sep = text.First(vv => new char[] { '\t', ',' }.Contains(vv));
            var csv = new CsvReader(new StringReader(text), false, sep);

            csv.SupportsMultiline = true;
            var list = csv.ToList();

            var list0 = list.First().Select(kk => kk).ToList();

            names = list0.ToDictionary(i => i.TrimEnd(),
                                       i => list0.FindIndex(s => s == i), StringComparer.OrdinalIgnoreCase);

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

            var db = DbUtil.Create(host);

            if (names.ContainsKey("campus"))
            {
                var campuslist = (from li in list.Skip(1)
                                  where li.Length == names.Count
                                  group li by li[names["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);
                            }
                        }
                    }
                }
            }
            var now = DateTime.Now;

            if (!testing)
            {
                db.SubmitChanges();
            }
            Campuses = db.Campus.ToDictionary(cp => cp.Description, cp => cp.Id);

            var q = (from li in list.Skip(1)
                     where li.Length == names.Count
                     group li by li[names["familyid"]]
                     into fam
                     select fam).ToList();

            rt.Count = q.Sum(ff => ff.Count());
            Db2.SubmitChanges();

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

                FindPerson3 pid;
                Person      p = null;
                foreach (var a in fam)
                {
                    if (!testing)
                    {
                        db.SubmitChanges();
                        db.Dispose();
                        db = DbUtil.Create(host);
                    }

                    var      potentialdup = false;
                    var      first        = a[names["first"]];
                    var      last         = a[names["last"]];
                    DateTime dt;
                    DateTime?dob = null;
                    if (names.ContainsKey("birthday"))
                    {
                        if (DateTime.TryParse(a[names["birthday"]], out dt))
                        {
                            dob = dt;
                            if (dob.Value < SqlDateTime.MinValue)
                            {
                                dob = null;
                            }
                        }
                    }
                    string email     = null;
                    string cell      = null;
                    string homephone = null;
                    if (names.ContainsKey("email"))
                    {
                        email = a[names["email"]].Trim();
                    }
                    if (names.ContainsKey("cellphone"))
                    {
                        cell = a[names["cellphone"]].GetDigits();
                    }
                    if (names.ContainsKey("homephone"))
                    {
                        homephone = a[names["homephone"]].GetDigits();
                    }
                    pid = db.FindPerson3(first, last, dob, email, cell, homephone, null).FirstOrDefault();

                    if (noupdate && pid != null)
                    {
                        if (!testing)
                        {
                            var pd = db.LoadPersonById(pid.PeopleId.Value);
                            pd.AddEditExtraBool("FoundDup", true);
                        }
                        potentialdup = true;
                        pid          = null;
                    }
                    if (pid != null) // found
                    {
                        p       = db.LoadPersonById(pid.PeopleId.Value);
                        prevpid = p.PeopleId;
                        psb     = new List <ChangeDetail>();
                        fsb     = new List <ChangeDetail>();

                        UpdateField(p, a, "TitleCode", "title");
                        UpdateField(p, a, "FirstName", "first");
                        UpdateField(p, a, "NickName", "goesby");
                        UpdateField(p, a, "LastName", "last");
                        UpdateField(p, a, "EmailAddress", "email");
                        UpdateField(p, a, "EmailAddress2", "email2");
                        UpdateField(p, a, "DOB", "birthday");
                        UpdateField(p, a, "AltName", "altname");
                        UpdateField(p, a, "SuffixCode", "suffix");
                        UpdateField(p, a, "MiddleName", "middle");

                        UpdateField(p, a, "CellPhone", "cellphone", GetDigits(a, "cellphone"));
                        UpdateField(p, a, "WorkPhone", "workphone", GetDigits(a, "workphone"));
                        UpdateField(p, a, "GenderId", "gender", Gender(a));
                        UpdateField(p, a, "MaritalStatusId", "marital", Marital(a));
                        UpdateField(p, a, "PositionInFamilyId", "position", Position(a));
                        if (!testing)
                        {
                            UpdateField(p, a, "CampusId", "campus", Campus(a));
                        }

                        UpdateField(p.Family, a, "AddressLineOne", "address");
                        UpdateField(p.Family, a, "AddressLineTwo", "address2");
                        UpdateField(p.Family, a, "CityName", "city");
                        UpdateField(p.Family, a, "StateCode", "state");
                        UpdateField(p.Family, a, "ZipCode", "zip");

                        if (names.ContainsKey("memberstatus"))
                        {
                            UpdateMemberStatus(db, p, a);
                        }

                        if (!testing)
                        {
                            p.LogChanges(db, psb, PeopleId);
                            p.Family.LogChanges(db, fsb, p.PeopleId, PeopleId);
                            db.SubmitChanges();
                            p.AddEditExtraBool("InsertPeopleUpdated", true);
                        }
                    }
                    else // new person
                    {
                        if (!testing)
                        {
                            if (prevpid > 0)
                            {
                                f = db.LoadFamilyByPersonId(prevpid);
                            }
                        }

                        if (f == null || !a[names["familyid"]].HasValue())
                        {
                            f = new Family();
                            SetField(f, a, "AddressLineOne", "address");
                            SetField(f, a, "AddressLineTwo", "address2");
                            SetField(f, a, "CityName", "city");
                            SetField(f, a, "StateCode", "state");
                            SetField(f, a, "ZipCode", "zip");
                            SetField(f, a, "HomePhone", "homephone", GetDigits(a, "homephone"));
                            db.Families.InsertOnSubmit(f);
                            if (!testing)
                            {
                                db.SubmitChanges();
                            }
                        }

                        string goesby = null;
                        if (names.ContainsKey("goesby"))
                        {
                            goesby = a[names["goesby"]];
                        }
                        p = Person.Add(db, false, f, 10, null,
                                       a[names["first"]],
                                       goesby,
                                       a[names["last"]],
                                       dob.FormatDate(),
                                       0, 0, 0, null, testing);
                        prevpid = p.PeopleId;
                        p.FixTitle();

                        SetField(p, a, "AltName", "altname");
                        SetField(p, a, "SuffixCode", "suffix");
                        SetField(p, a, "MiddleName", "middle");
                        SetField(p, a, "MaidenName", "maidenname");
                        SetField(p, a, "EmployerOther", "employer");
                        SetField(p, a, "OccupationOther", "occupation");
                        SetField(p, a, "CellPhone", "cellphone", GetDigits(a, "cellphone"));
                        SetField(p, a, "WorkPhone", "workphone", GetDigits(a, "workphone"));
                        SetField(p, a, "EmailAddress", "email");
                        SetField(p, a, "EmailAddress2", "email2");
                        SetField(p, a, "GenderId", "gender", Gender(a));
                        SetField(p, a, "MaritalStatusId", "marital", Marital(a));
                        SetField(p, a, "WeddingDate", "weddingdate", GetDate(p, a, "weddingdate"));
                        SetField(p, a, "JoinDate", "joindate", GetDate(p, a, "joindate"));
                        SetField(p, a, "DropDate", "dropdate", GetDate(p, a, "dropdate"));
                        SetField(p, a, "BaptismDate", "baptismdate", GetDate(p, a, "baptismdate"));
                        SetField(p, a, "PositionInFamilyId", "position", Position(a));
                        SetField(p, a, "TitleCode", "title", Title(a));
                        SetField(p, a, "DeceasedDate", "deceased", GetDate(p, a, "deceased"));
                        if (names.ContainsKey("memberstatus"))
                        {
                            SetMemberStatus(db, p, a);
                        }
                        if (!testing)
                        {
                            SetField(p, a, "CampusId", "campus", Campus(a));
                            p.AddEditExtraBool("InsertPeopleAdded", true);
                            if (potentialdup)
                            {
                                p.AddEditExtraBool("FoundDup", true);
                            }
                            db.SubmitChanges();
                        }
                    }
                    if (names.ContainsKey("createddate"))
                    {
                        SetCreatedDate(p, a);
                    }
                    if (names.ContainsKey("backgroundcheck"))
                    {
                        SetBackgroundCheckDate(db, p, a);
                    }

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

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

                    rt.Processed++;
                    Db2.SubmitChanges();
                }
                if (!testing)
                {
                    db.SubmitChanges();
                }
            }
            rt.Completed = DateTime.Now;
            Db2.SubmitChanges();
            return(true);
        }