public ActionResult Start(int tag, int meetingid, bool addasmembers)
 {
     var runningtotals = new AddToOrgFromTagRun
     {
         Started = DateTime.Now,
         Count = 0,
         Processed = 0,
         Orgid = meetingid
     };
     DbUtil.Db.AddToOrgFromTagRuns.InsertOnSubmit(runningtotals);
     DbUtil.Db.SubmitChanges();
     var host = Util.Host;
     var qid = DbUtil.Db.FetchLastQuery().Id;
     System.Threading.Tasks.Task.Factory.StartNew(() =>
     {
         System.Threading.Thread.CurrentThread.Priority = System.Threading.ThreadPriority.BelowNormal;
         var Db = new CMSDataContext(Util.GetConnectionString(host));
         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();
         var meeting = Db.Meetings.SingleOrDefault(mm => mm.MeetingId == meetingid);
         var joindate = meeting.MeetingDate.Value.AddMinutes(-1);
         var orgid = meeting.OrganizationId;
         foreach (var pid in pids)
         {
             Db.Dispose();
             Db = new CMSDataContext(Util.GetConnectionString(host));
             if (addasmembers)
                 OrganizationMember.InsertOrgMembers(Db,
                     orgid, pid, MemberTypeCode.Member, joindate, null, false);
             Db.RecordAttendance(meetingid, pid, true);
             var r = Db.AddToOrgFromTagRuns.Where(mm => mm.Orgid == meetingid).OrderByDescending(mm => mm.Id).First();
             r.Processed++;
             r.Count = pids.Count;
             Db.SubmitChanges();
         }
         var rr = Db.AddToOrgFromTagRuns.Where(mm => mm.Orgid == meetingid).OrderByDescending(mm => mm.Id).First();
         rr.Completed = DateTime.Now;
         Db.SubmitChanges();
         Db.UpdateMainFellowship(orgid);
     });
     return Redirect("/AddAttendeesFromTag/Progress/" + meetingid);
 }
示例#2
0
        public void MovePersonStuff(CMSDataContext db, int targetid)
        {
            var toperson = db.People.Single(p => p.PeopleId == targetid);
            foreach (var om in this.OrganizationMembers)
            {
                var om2 = OrganizationMember.InsertOrgMembers(db, om.OrganizationId, targetid, om.MemberTypeId, om.EnrollmentDate.Value, om.InactiveDate, om.Pending ?? false);
                db.UpdateMainFellowship(om.OrganizationId);
                om2.CreatedBy = om.CreatedBy;
                om2.CreatedDate = om.CreatedDate;
                om2.AttendPct = om.AttendPct;
                om2.AttendStr = om.AttendStr;
                om2.LastAttended = om.LastAttended;
                om2.Request = om.Request;
                om2.Grade = om.Grade;
                om2.Amount = om.Amount;
                om2.TranId = om.TranId;
                om2.AmountPaid = om.AmountPaid;
                om2.PayLink = om.PayLink;
                om2.Moved = om.Moved;
                om2.InactiveDate = om.InactiveDate;
                om.Pending = om.Pending;
                om.Request = om.Request;
                om2.RegisterEmail = om.RegisterEmail;
                om2.ShirtSize = om.ShirtSize;
                om2.Tickets = om.Tickets;
                om2.UserData = om.UserData;
                om2.OnlineRegData = om.OnlineRegData;
                db.SubmitChanges();
                foreach (var m in om.OrgMemMemTags)
                    if (!om2.OrgMemMemTags.Any(mm => mm.MemberTagId == m.MemberTagId))
                        om2.OrgMemMemTags.Add(new OrgMemMemTag { MemberTagId = m.MemberTagId });
                db.SubmitChanges();
                db.OrgMemMemTags.DeleteAllOnSubmit(om.OrgMemMemTags);
                db.SubmitChanges();
                TrySubmit(db, $"Organizations (orgid:{om.OrganizationId})");
            }
            db.OrganizationMembers.DeleteAllOnSubmit(this.OrganizationMembers);
            TrySubmit(db, "DeletingMemberships");

            foreach (var et in this.EnrollmentTransactions)
                et.PeopleId = targetid;
            TrySubmit(db, "EnrollmentTransactions");

            var tplist = TransactionPeople.ToList();
            if (tplist.Any())
            {
                db.TransactionPeople.DeleteAllOnSubmit(TransactionPeople);
                TrySubmit(db, "Delete TransactionPeople");

                foreach (var tp in tplist)
                    db.TransactionPeople.InsertOnSubmit(new TransactionPerson
                    {
                        OrgId = tp.OrgId,
                        Amt = tp.Amt,
                        Id = tp.Id,
                        PeopleId = targetid
                    });
                TrySubmit(db, "Add TransactionPeople");
            }

            var q = from a in db.Attends
                    where a.AttendanceFlag == true
                    where a.PeopleId == this.PeopleId
                    select a;
            foreach (var a in q)
                Attend.RecordAttendance(db, targetid, a.MeetingId, true);
            db.AttendUpdateN(targetid, 10);

            foreach (var c in this.Contributions)
                c.PeopleId = targetid;
            TrySubmit(db, "Contributions");

            foreach (var u in this.Users)
                u.PeopleId = targetid;
            TrySubmit(db, "Users");

            if (this.Volunteers.Any() && !toperson.Volunteers.Any())
                foreach (var v in this.Volunteers)
                {
                    var vv = new Volunteer
                    {
                        PeopleId = targetid,
                        Children = v.Children,
                        Comments = v.Comments,
                        Leader = v.Leader,
                        ProcessedDate = v.ProcessedDate,
                        Standard = v.Standard,
                        StatusId = v.StatusId,
                    };
                    db.Volunteers.InsertOnSubmit(vv);
                }
            TrySubmit(db, "Volunteers");

            foreach (var v in this.VolunteerForms)
                v.PeopleId = targetid;
            TrySubmit(db, "VolunteerForms");

            foreach (var c in this.contactsMade)
            {
                var cp = db.Contactors.SingleOrDefault(c2 => c2.PeopleId == targetid && c.ContactId == c2.ContactId);
                if (cp == null)
                    c.contact.contactsMakers.Add(new Contactor { PeopleId = targetid });
                db.Contactors.DeleteOnSubmit(c);
            }
            TrySubmit(db, "ContactsMade");

            foreach (var c in this.contactsHad)
            {
                var cp = db.Contactees.SingleOrDefault(c2 => c2.PeopleId == targetid && c.ContactId == c2.ContactId);
                if (cp == null)
                    c.contact.contactees.Add(new Contactee { PeopleId = targetid });
                db.Contactees.DeleteOnSubmit(c);
            }
            TrySubmit(db, "ContactsHad");

            foreach (var e in this.PeopleExtras)
            {
                var field = e.Field;
            FindExisting:
                var cp = db.PeopleExtras.FirstOrDefault(c2 => c2.PeopleId == targetid && c2.Field == field);
                if (cp != null)
                {
                    field = field + "_mv";
                    goto FindExisting;
                }
                var e2 = new PeopleExtra
                             {
                                 PeopleId = targetid,
                                 Field = field,
                                 Data = e.Data,
                                 StrValue = e.StrValue,
                                 DateValue = e.DateValue,
                                 IntValue = e.IntValue,
                                 IntValue2 = e.IntValue2,
                                 TransactionTime = e.TransactionTime
                             };
                db.PeopleExtras.InsertOnSubmit(e2);
                TrySubmit(db, $"ExtraValues (pid={e2.PeopleId},field={e2.Field})");
            }
            db.PeopleExtras.DeleteAllOnSubmit(PeopleExtras);
            TrySubmit(db, "Delete ExtraValues");

            var torecreg = toperson.RecRegs.SingleOrDefault();
            var frrecreg = RecRegs.SingleOrDefault();
            if (torecreg == null && frrecreg != null)
                frrecreg.PeopleId = targetid;
            if (torecreg != null && frrecreg != null)
            {
                torecreg.Comments = frrecreg.Comments + "\n" + torecreg.Comments;
                if (Util.HasValue(frrecreg.ShirtSize))
                    torecreg.ShirtSize = frrecreg.ShirtSize;
                if (Util.HasValue(frrecreg.MedicalDescription))
                    torecreg.MedicalDescription = frrecreg.MedicalDescription;
                if (Util.HasValue(frrecreg.Doctor))
                    torecreg.Doctor = frrecreg.Doctor;
                if (Util.HasValue(frrecreg.Docphone))
                    torecreg.Docphone = frrecreg.Docphone;
                if (frrecreg.MedAllergy.HasValue)
                    torecreg.MedAllergy = frrecreg.MedAllergy;
                if (frrecreg.Tylenol.HasValue)
                    torecreg.Tylenol = frrecreg.Tylenol;
                if (frrecreg.Robitussin.HasValue)
                    torecreg.Robitussin = frrecreg.Robitussin;
                if (frrecreg.Advil.HasValue)
                    torecreg.Advil = frrecreg.Advil;
                if (frrecreg.Maalox.HasValue)
                    torecreg.Maalox = frrecreg.Maalox;
                if (Util.HasValue(frrecreg.Insurance))
                    torecreg.Insurance = frrecreg.Insurance;
                if (Util.HasValue(frrecreg.Policy))
                    torecreg.Policy = frrecreg.Policy;
                if (Util.HasValue(frrecreg.Mname))
                    torecreg.Mname = frrecreg.Mname;
                if (Util.HasValue(frrecreg.Fname))
                    torecreg.Fname = frrecreg.Fname;
                if (Util.HasValue(frrecreg.Emcontact))
                    torecreg.Emcontact = frrecreg.Emcontact;
                if (Util.HasValue(frrecreg.Emphone))
                    torecreg.Emphone = frrecreg.Emphone;
                if (frrecreg.ActiveInAnotherChurch.HasValue)
                    torecreg.ActiveInAnotherChurch = frrecreg.ActiveInAnotherChurch;
            }
            TrySubmit(db, "RegReg");

            var mg = db.ManagedGivings.FirstOrDefault(mm => mm.PeopleId == targetid);
            if (mg == null)
            {
                var v = this.ManagedGivings.FirstOrDefault();
                if (v != null)
                {
                    db.ManagedGivings.InsertOnSubmit(new ManagedGiving()
                                {
                                    Day1 = v.Day1,
                                    Day2 = v.Day2,
                                    EveryN = v.EveryN,
                                    NextDate = v.NextDate,
                                    PeopleId = targetid,
                                    Period = v.Period,
                                    SemiEvery = v.SemiEvery,
                                    StartWhen = v.StartWhen,
                                    StopAfter = v.StopAfter,
                                    StopWhen = v.StopWhen,
                                    Type = v.Type,
                                });
                    var qq = from ra in db.RecurringAmounts
                             where ra.PeopleId == PeopleId
                             select ra;
                    foreach (var ra in qq)
                        db.RecurringAmounts.InsertOnSubmit(
                            new RecurringAmount()
                                {
                                    PeopleId = targetid,
                                    Amt = ra.Amt,
                                    FundId = ra.FundId,
                                });
                }
                TrySubmit(db, "ManagedGivings");
            }

            var pi = db.PaymentInfos.FirstOrDefault(mm => mm.PeopleId == targetid);
            if (pi == null) // the target has none
                foreach (var i in PaymentInfos)
                    DbUtil.Db.PaymentInfos.InsertOnSubmit(
                        new PaymentInfo
                            {
                                Address = i.Address,
                                Address2 = i.Address2,
                                AuNetCustId = i.AuNetCustId,
                                AuNetCustPayId = i.AuNetCustPayId,
                                AuNetCustPayBankId = i.AuNetCustPayBankId,
                                BluePayCardVaultId = i.BluePayCardVaultId,
                                City = i.City,
                                Country = i.Country,
                                Expires = i.Expires,
                                FirstName = i.FirstName,
                                LastName = i.LastName,
                                MaskedAccount = i.MaskedAccount,
                                MaskedCard = i.MaskedCard,
                                MiddleInitial = i.MiddleInitial,
                                PeopleId = targetid,
                                Phone = i.Phone,
                                PreferredGivingType = i.PreferredGivingType,
                                PreferredPaymentType = i.PreferredPaymentType,
                                Routing = i.Routing,
                                SageBankGuid = i.SageBankGuid,
                                SageCardGuid = i.SageCardGuid,
                                State = i.State,
                                Suffix = i.Suffix,
                                Testing = i.Testing,
                                Zip = i.Zip,
                                TbnBankVaultId = i.TbnBankVaultId,
                                TbnCardVaultId = i.TbnCardVaultId
                            });
            TrySubmit(db, "PaymentInfos");

            foreach (var bc in this.BackgroundChecks)
                bc.PeopleID = targetid;
            TrySubmit(db, "BackgroundChecks");

            foreach (var c in this.CheckInTimes)
                c.PeopleId = targetid;
            TrySubmit(db, "CheckinTimes");

            db.ExecuteCommand(@"
            UPDATE dbo.GoerSupporter SET GoerId = {1} WHERE GoerId = {0};
            UPDATE dbo.GoerSupporter SET SupporterId = {1} WHERE SupporterId = {0};
            UPDATE dbo.GoerSenderAmounts SET GoerId = {1} WHERE GoerId = {0};
            UPDATE dbo.GoerSenderAmounts SET SupporterId = {1} WHERE SupporterId = {0}", PeopleId, targetid);
        }
 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 = new CMSDataContext(Util.GetConnectionString(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 = new CMSDataContext(Util.GetConnectionString(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);
 }