public ActionResult Index(int id)
        {
            var mm = DbUtil.Db.Meetings.SingleOrDefault(m => m.MeetingId == id);
            if (mm == null)
                return Content("error: no meeting");
            DbUtil.LogActivity("Delete meeting for {0}".Fmt(Session["ActiveOrganization"]));

            var runningtotals = new DeleteMeetingRun
            {
                Started = DateTime.Now,
                Count = mm.Attends.Count(a => a.EffAttendFlag == true || a.AttendanceFlag == true),
                Processed = 0,
                Meetingid = id
            };
            DbUtil.Db.DeleteMeetingRuns.InsertOnSubmit(runningtotals);
            DbUtil.Db.SubmitChanges();
            var host = Util.Host;
            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);

                var meeting = Db.Meetings.SingleOrDefault(m => m.MeetingId == id);
                var q = from a in Db.Attends
                        where a.MeetingId == id
                        where a.AttendanceFlag == true || a.EffAttendFlag == true
                        select a.PeopleId;
                var list = q.ToList();
                foreach (var pid in list)
                {
                    Db.Dispose();
                    Db = new CMSDataContext(Util.GetConnectionString(host));
                    Attend.RecordAttendance(Db, pid, id, false);
                    var r = Db.DeleteMeetingRuns.Where(m => m.Meetingid == id).OrderByDescending(m => m.Id).First();
                    r.Processed++;
                    Db.SubmitChanges();
                }
                var rr = Db.DeleteMeetingRuns.Where(m => m.Meetingid == id).OrderByDescending(m => m.Id).First();
                rr.Processed--;
                Db.SubmitChanges();
                Db.ExecuteCommand(
                    "delete dbo.SubRequest WHERE EXISTS(SELECT NULL FROM Attend a WHERE a.AttendId = AttendId AND a.MeetingId = {0})",
                    id);
                Db.ExecuteCommand("DELETE dbo.VolRequest where MeetingId = {0}", id);
                Db.ExecuteCommand("delete attend where MeetingId = {0}", id);
                Db.ExecuteCommand("delete MeetingExtra where MeetingId = {0}", id);
                Db.ExecuteCommand("delete meetings where MeetingId = {0}", id);
                rr.Processed++;
                rr.Completed = DateTime.Now;
                Db.SubmitChanges();
            });
            return Redirect("/DeleteMeeting/Progress/" + id);
        }
Example #2
0
        public EnrollmentTransaction Drop(CMSDataContext Db, bool addToHistory)
        {
            Db.SubmitChanges();
            int ntries = 2;

            while (true)
            {
                try
                {
                    var q = from o in Db.Organizations
                            where o.OrganizationId == OrganizationId
                            let count = Db.Attends.Count(a => a.PeopleId == PeopleId &&
                                                         a.OrganizationId == OrganizationId &&
                                                         (a.MeetingDate < DateTime.Today || a.AttendanceFlag == true))
                                        select new { count, Organization.DaysToIgnoreHistory };
                    var i = q.Single();
                    if (!EnrollmentDate.HasValue)
                    {
                        EnrollmentDate = CreatedDate;
                    }
                    var droptrans = new EnrollmentTransaction
                    {
                        OrganizationId    = OrganizationId,
                        PeopleId          = PeopleId,
                        MemberTypeId      = MemberTypeId,
                        OrganizationName  = Organization.OrganizationName,
                        TransactionDate   = Util.Now,
                        TransactionTypeId = 5,
                        // drop
                        CreatedBy            = Util.UserId1,
                        CreatedDate          = Util.Now,
                        Pending              = Pending,
                        AttendancePercentage = AttendPct,
                    };
                    Db.EnrollmentTransactions.InsertOnSubmit(droptrans);
                    Db.OrgMemMemTags.DeleteAllOnSubmit(this.OrgMemMemTags);
                    Db.OrganizationMembers.DeleteOnSubmit(this);
                    Db.ExecuteCommand("DELETE FROM dbo.SubRequest WHERE EXISTS(SELECT NULL FROM Attend a WHERE a.AttendId = AttendId AND a.OrganizationId = {0} AND a.MeetingDate > {1} AND a.PeopleId = {2})", OrganizationId, Util.Now, PeopleId);
                    Db.ExecuteCommand("DELETE dbo.Attend WHERE OrganizationId = {0} AND MeetingDate > {1} AND PeopleId = {2} AND ISNULL(Commitment, 1) = 1", OrganizationId, Util.Now, PeopleId);
                    return(droptrans);
                }
                catch (SqlException ex)
                {
                    if (ex.Number == 1205)
                    {
                        if (--ntries > 0)
                        {
                            Db.Dispose();
                            System.Threading.Thread.Sleep(500);
                            continue;
                        }
                    }
                    throw;
                }
            }
        }
        public EnrollmentTransaction Drop(CMSDataContext db, DateTime dropdate, string orgname)
        {
            db.SubmitChanges();
            while (true)
            {
                if (!EnrollmentDate.HasValue)
                {
                    EnrollmentDate = CreatedDate;
                }
                var sglist = (from mt in db.OrgMemMemTags
                              where mt.PeopleId == PeopleId
                              where mt.OrgId == OrganizationId
                              select mt.MemberTag.Name
                              ).ToList();
                var droptrans = new EnrollmentTransaction
                {
                    OrganizationId       = OrganizationId,
                    PeopleId             = PeopleId,
                    MemberTypeId         = MemberTypeId,
                    OrganizationName     = orgname,
                    TransactionDate      = dropdate,
                    TransactionTypeId    = 5, // drop
                    CreatedBy            = Util.UserId1,
                    CreatedDate          = Util.Now,
                    Pending              = Pending,
                    AttendancePercentage = AttendPct,
                    InactiveDate         = InactiveDate,
                    UserData             = UserData,
                    Request              = Request,
                    ShirtSize            = ShirtSize,
                    Grade         = Grade,
                    Tickets       = Tickets,
                    RegisterEmail = RegisterEmail,
                    Score         = Score,
                    SmallGroups   = string.Join("\n", sglist)
                };

                db.EnrollmentTransactions.InsertOnSubmit(droptrans);
                db.OrgMemMemTags.DeleteAllOnSubmit(this.OrgMemMemTags);
                db.OrganizationMembers.DeleteOnSubmit(this);
                db.ExecuteCommand(@"
DELETE dbo.SubRequest
FROM dbo.SubRequest sr
JOIN dbo.Attend a ON a.AttendId = sr.AttendId
WHERE a.OrganizationId = {0}
AND a.MeetingDate > {1}
AND a.PeopleId = {2}
", OrganizationId, Util.Now, PeopleId);
                db.ExecuteCommand("DELETE dbo.Attend WHERE OrganizationId = {0} AND MeetingDate > {1} AND PeopleId = {2} AND ISNULL(Commitment, 1) = 1", OrganizationId, Util.Now, PeopleId);
                db.ExecuteCommand("DELETE dbo.Attend WHERE OrganizationId = {0} AND DATEADD(DAY, DATEDIFF(DAY, 0, MeetingDate), 0) = DATEADD(DAY, DATEDIFF(DAY, 0, GETDATE()), 0) AND PeopleId = {1} AND AttendanceFlag = 0", OrganizationId, PeopleId);
                db.ExecuteCommand("UPDATE dbo.GoerSenderAmounts SET InActive = 1 WHERE OrgId = {0} AND (GoerId = {1} OR SupporterId = {1})", OrganizationId, PeopleId);
                return(droptrans);
            }
        }
Example #4
0
        public EnrollmentTransaction Drop(CMSDataContext db, DateTime dropdate, string orgname)
        {
            db.SubmitChanges();
            while (true)
            {
                if (!EnrollmentDate.HasValue)
                    EnrollmentDate = CreatedDate;
                var sglist = (from mt in db.OrgMemMemTags
                              where mt.PeopleId == PeopleId
                              where mt.OrgId == OrganizationId
                              select mt.MemberTag.Name
                    ).ToList();
                var droptrans = new EnrollmentTransaction
                {
                    OrganizationId = OrganizationId,
                    PeopleId = PeopleId,
                    MemberTypeId = MemberTypeId,
                    OrganizationName = orgname,
                    TransactionDate = dropdate,
                    TransactionTypeId = 5, // drop
                    CreatedBy = Util.UserId1,
                    CreatedDate = Util.Now,
                    Pending = Pending,
                    AttendancePercentage = AttendPct,
                    InactiveDate = InactiveDate,
                    UserData = UserData,
                    Request = Request,
                    ShirtSize = ShirtSize,
                    Grade = Grade,
                    Tickets = Tickets,
                    RegisterEmail = RegisterEmail,
                    Score = Score,
                    SmallGroups = string.Join("\n", sglist)
                };

                db.EnrollmentTransactions.InsertOnSubmit(droptrans);
                db.OrgMemMemTags.DeleteAllOnSubmit(this.OrgMemMemTags);
                db.OrganizationMembers.DeleteOnSubmit(this);
                db.ExecuteCommand(@"
DELETE dbo.SubRequest
FROM dbo.SubRequest sr
JOIN dbo.Attend a ON a.AttendId = sr.AttendId
WHERE a.OrganizationId = {0}
AND a.MeetingDate > {1}
AND a.PeopleId = {2}
", OrganizationId, Util.Now, PeopleId);
                db.ExecuteCommand("DELETE dbo.Attend WHERE OrganizationId = {0} AND MeetingDate > {1} AND PeopleId = {2} AND ISNULL(Commitment, 1) = 1", OrganizationId, Util.Now, PeopleId);
                db.ExecuteCommand("DELETE dbo.Attend WHERE OrganizationId = {0} AND DATEADD(DAY, DATEDIFF(DAY, 0, MeetingDate), 0) = DATEADD(DAY, DATEDIFF(DAY, 0, GETDATE()), 0) AND PeopleId = {1} AND AttendanceFlag = 0", OrganizationId, PeopleId);
                db.ExecuteCommand("UPDATE dbo.GoerSenderAmounts SET InActive = 1 WHERE OrgId = {0} AND (GoerId = {1} OR SupporterId = {1})", OrganizationId, PeopleId);
                return droptrans;
            }
        }
Example #5
0
        public void DeletePicture(CMSDataContext db)
        {
            if (Picture == null)
            {
                return;
            }
            Image.Delete(Picture.ThumbId);
            Image.Delete(Picture.SmallId);
            Image.Delete(Picture.MediumId);
            Image.Delete(Picture.LargeId);
            var pid = PictureId;

            Picture = null;
            db.SubmitChanges();
            db.ExecuteCommand("DELETE dbo.Picture WHERE PictureId = {0}", pid);
        }
Example #6
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 = new CMSDataContext(Util.GetConnectionString(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("/Manage/Duplicates/Progress");
        }
Example #7
0
File: Family.cs Project: vs06/bvcms
 public void DeletePicture(CMSDataContext db)
 {
     if (Picture == null)
         return;
     Image.Delete(Picture.ThumbId);
     Image.Delete(Picture.SmallId);
     Image.Delete(Picture.MediumId);
     Image.Delete(Picture.LargeId);
     var pid = PictureId;
     Picture = null;
     db.SubmitChanges();
     db.ExecuteCommand("DELETE dbo.Picture WHERE PictureId = {0}", pid);
 }
Example #8
0
        public EnrollmentTransaction Drop(CMSDataContext db, DateTime dropdate, bool addToHistory)
        {
            db.SubmitChanges();
            //            int ntries = 2;
            while (true)
            {
                //                try
                //                {
                var q = from o in db.Organizations
                        where o.OrganizationId == OrganizationId
                        let count = db.Attends.Count(a => a.PeopleId == PeopleId &&
                                                     a.OrganizationId == OrganizationId &&
                                                     (a.MeetingDate < DateTime.Today || a.AttendanceFlag == true))
                                    select new { count, Organization.DaysToIgnoreHistory };
                var i = q.Single();
                if (!EnrollmentDate.HasValue)
                {
                    EnrollmentDate = CreatedDate;
                }
                var sglist = (from mt in db.OrgMemMemTags
                              where mt.PeopleId == PeopleId
                              where mt.OrgId == OrganizationId
                              select mt.MemberTag.Name
                              ).ToList();
                var droptrans = new EnrollmentTransaction
                {
                    OrganizationId    = OrganizationId,
                    PeopleId          = PeopleId,
                    MemberTypeId      = MemberTypeId,
                    OrganizationName  = Organization.OrganizationName,
                    TransactionDate   = dropdate,
                    TransactionTypeId = 5,
                    // drop
                    CreatedBy            = Util.UserId1,
                    CreatedDate          = Util.Now,
                    Pending              = Pending,
                    AttendancePercentage = AttendPct,
                    InactiveDate         = InactiveDate,
                    UserData             = UserData,
                    Request              = Request,
                    ShirtSize            = ShirtSize,
                    Grade         = Grade,
                    Tickets       = Tickets,
                    RegisterEmail = RegisterEmail,
                    Score         = Score,
                    SmallGroups   = string.Join("\n", sglist)
                };

                db.EnrollmentTransactions.InsertOnSubmit(droptrans);
                db.OrgMemMemTags.DeleteAllOnSubmit(this.OrgMemMemTags);
                db.OrganizationMembers.DeleteOnSubmit(this);
                db.ExecuteCommand("DELETE FROM dbo.SubRequest WHERE EXISTS(SELECT NULL FROM Attend a WHERE a.AttendId = AttendId AND a.OrganizationId = {0} AND a.MeetingDate > {1} AND a.PeopleId = {2})", OrganizationId, Util.Now, PeopleId);
                db.ExecuteCommand("DELETE dbo.Attend WHERE OrganizationId = {0} AND MeetingDate > {1} AND PeopleId = {2} AND ISNULL(Commitment, 1) = 1", OrganizationId, Util.Now, PeopleId);
                db.ExecuteCommand("UPDATE dbo.GoerSenderAmounts SET InActive = 1 WHERE OrgId = {0} AND (GoerId = {1} OR SupporterId = {1})", OrganizationId, PeopleId);
                return(droptrans);
                //                }
                //                catch (SqlException ex)
                //                {
                //                    if (ex.Number == 1205)
                //                        if (--ntries > 0)
                //                        {
                //                            Db.Dispose();
                //                            System.Threading.Thread.Sleep(500);
                //                            continue;
                //                        }
                //                    throw;
                //                }
            }
        }
        public EnrollmentTransaction Drop(CMSDataContext db, CMSImageDataContext idb, DateTime dropdate, string orgname, bool skipTriggerProcessing = false)
        {
            db.SubmitChanges();
            while (true)
            {
                if (!EnrollmentDate.HasValue)
                {
                    EnrollmentDate = CreatedDate;
                }

                var sglist = (from mt in db.OrgMemMemTags
                              where mt.PeopleId == PeopleId
                              where mt.OrgId == OrganizationId
                              select mt.MemberTag.Name
                              ).ToList();
                var droptrans = new EnrollmentTransaction
                {
                    OrganizationId       = OrganizationId,
                    PeopleId             = PeopleId,
                    MemberTypeId         = MemberTypeId,
                    OrganizationName     = orgname,
                    EnrollmentDate       = EnrollmentDate, //Adding Enrollment Date to show on the system after droppĂ­ng member.
                    TransactionDate      = dropdate,
                    TransactionTypeId    = 5,              // drop
                    CreatedBy            = db.UserId1,
                    CreatedDate          = Util.Now,
                    Pending              = Pending,
                    AttendancePercentage = AttendPct,
                    InactiveDate         = InactiveDate,
                    UserData             = UserData,
                    Request              = Request,
                    ShirtSize            = ShirtSize,
                    Grade         = Grade,
                    Tickets       = Tickets,
                    RegisterEmail = RegisterEmail,
                    Score         = Score,
                    SmallGroups   = string.Join("\n", sglist),
                    SkipInsertTriggerProcessing = skipTriggerProcessing
                };

                db.EnrollmentTransactions.InsertOnSubmit(droptrans);
                db.OrgMemberExtras.DeleteAllOnSubmit(this.OrgMemberExtras);
                db.OrgMemMemTags.DeleteAllOnSubmit(this.OrgMemMemTags);
                db.SubmitChanges();
                foreach (var ev in this.OrgMemberExtras)
                {
                    var ev2 = new PrevOrgMemberExtra()
                    {
                        EnrollmentTranId = droptrans.TransactionId,
                        OrganizationId   = ev.OrganizationId,
                        PeopleId         = ev.PeopleId,
                        Field            = ev.Field,
                        StrValue         = ev.StrValue,
                        Data             = ev.Data,
                        BitValue         = ev.BitValue,
                        IntValue         = ev.IntValue,
                        DateValue        = ev.DateValue,
                    };
                    db.PrevOrgMemberExtras.InsertOnSubmit(ev2);
                    db.SubmitChanges();
                }
                DeleteDocuments(db, idb);
                db.OrgMemberExtras.DeleteAllOnSubmit(this.OrgMemberExtras);
                db.OrganizationMembers.DeleteOnSubmit(this);
                db.ExecuteCommand(@"
DELETE dbo.SubRequest
FROM dbo.SubRequest sr
JOIN dbo.Attend a ON a.AttendId = sr.AttendId
WHERE a.OrganizationId = {0}
AND a.MeetingDate > {1}
AND a.PeopleId = {2}
", OrganizationId, Util.Now, PeopleId);
                db.ExecuteCommand("DELETE dbo.Attend WHERE OrganizationId = {0} AND MeetingDate > {1} AND PeopleId = {2} AND ISNULL(Commitment, 1) = 1", OrganizationId, Util.Now, PeopleId);
                db.ExecuteCommand("DELETE dbo.Attend WHERE OrganizationId = {0} AND DATEADD(DAY, DATEDIFF(DAY, 0, MeetingDate), 0) = DATEADD(DAY, DATEDIFF(DAY, 0, GETDATE()), 0) AND PeopleId = {1} AND AttendanceFlag = 0", OrganizationId, PeopleId);
                db.ExecuteCommand("UPDATE dbo.GoerSenderAmounts SET InActive = 1 WHERE OrgId = {0} AND (GoerId = {1} OR SupporterId = {1})", OrganizationId, PeopleId);
                return(droptrans);
            }
        }
Example #10
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);
        }
Example #11
0
 public EnrollmentTransaction Drop(CMSDataContext Db, DateTime dropdate, bool addToHistory)
 {
     Db.SubmitChanges();
     int ntries = 2;
     while (true)
     {
         try
         {
             var q = from o in Db.Organizations
                     where o.OrganizationId == OrganizationId
                     let count = Db.Attends.Count(a => a.PeopleId == PeopleId
                                                       && a.OrganizationId == OrganizationId
                                                       && (a.MeetingDate < DateTime.Today || a.AttendanceFlag == true))
                     select new { count, Organization.DaysToIgnoreHistory };
             var i = q.Single();
             if (!EnrollmentDate.HasValue)
                 EnrollmentDate = CreatedDate;
             var droptrans = new EnrollmentTransaction
                             {
                                 OrganizationId = OrganizationId,
                                 PeopleId = PeopleId,
                                 MemberTypeId = MemberTypeId,
                                 OrganizationName = Organization.OrganizationName,
                                 TransactionDate = dropdate,
                                 TransactionTypeId = 5,
                                 // drop
                                 CreatedBy = Util.UserId1,
                                 CreatedDate = Util.Now,
                                 Pending = Pending,
                                 AttendancePercentage = AttendPct,
                             };
             Db.EnrollmentTransactions.InsertOnSubmit(droptrans);
             Db.OrgMemMemTags.DeleteAllOnSubmit(this.OrgMemMemTags);
             Db.OrganizationMembers.DeleteOnSubmit(this);
             Db.ExecuteCommand("DELETE FROM dbo.SubRequest WHERE EXISTS(SELECT NULL FROM Attend a WHERE a.AttendId = AttendId AND a.OrganizationId = {0} AND a.MeetingDate > {1} AND a.PeopleId = {2})", OrganizationId, Util.Now, PeopleId);
             Db.ExecuteCommand("DELETE dbo.Attend WHERE OrganizationId = {0} AND MeetingDate > {1} AND PeopleId = {2} AND ISNULL(Commitment, 1) = 1", OrganizationId, Util.Now, PeopleId);
             return droptrans;
         }
         catch (SqlException ex)
         {
             if (ex.Number == 1205)
                 if (--ntries > 0)
                 {
                     Db.Dispose();
                     System.Threading.Thread.Sleep(500);
                     continue;
                 }
             throw;
         }
     }
 }