public void DoWork()
        {
            Db = DbUtil.Create(Host);
            Db.CommandTimeout = 1200;

            var noaddressok = Db.Setting("RequireAddressOnStatement", "true") == "false";
            showCheckNo = Db.Setting("RequireCheckNoOnStatement", "false").ToLower() == "true";
            showNotes = Db.Setting("RequireNotesOnStatement", "false").ToLower() == "true";
            const bool UseMinAmt = true;

            var qc = APIContribution.contributors(Db, fd, td, 0, 0, 0, noaddressok, UseMinAmt, StartsWith, Sort, tagid: TagId, excludeelectronic: ExcludeElectronic);
            var runningtotals = Db.ContributionsRuns.OrderByDescending(mm => mm.Id).First();
            runningtotals.Count = qc.Count();
            Db.SubmitChanges();
            if (showCheckNo || showNotes)
            {
                var c = new ContributionStatementsExtra
                {
                    FromDate = fd,
                    ToDate = td,
                    typ = 3,
                    ShowCheckNo = showCheckNo,
                    ShowNotes = showNotes
                };
                using (var stream = new FileStream(OutputFile, FileMode.Create))
                    c.Run(stream, Db, qc);
                LastSet = c.LastSet();
                var sets = c.Sets();
                foreach (var set in sets)
                    using (var stream = new FileStream(Output(OutputFile, set), FileMode.Create))
                        c.Run(stream, Db, qc, set);
                runningtotals = Db.ContributionsRuns.OrderByDescending(mm => mm.Id).First();
                runningtotals.LastSet = LastSet;
                runningtotals.Sets = string.Join(",", sets);
                runningtotals.Completed = DateTime.Now;
                Db.SubmitChanges();
            }
            else
            {
                var c = new ContributionStatements
                {
                    FromDate = fd,
                    ToDate = td,
                    typ = 3
                };
                using (var stream = new FileStream(OutputFile, FileMode.Create))
                    c.Run(stream, Db, qc);
                LastSet = c.LastSet();
                var sets = c.Sets();
                foreach (var set in sets)
                    using (var stream = new FileStream(Output(OutputFile, set), FileMode.Create))
                        c.Run(stream, Db, qc, set);
                runningtotals = Db.ContributionsRuns.OrderByDescending(mm => mm.Id).First();
                runningtotals.LastSet = LastSet;
                runningtotals.Sets = string.Join(",", sets);
                runningtotals.Completed = DateTime.Now;
                Db.SubmitChanges();
            }
        }
        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);
        }
 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);
 }
Example #4
0
 public static void AddAsPreviousMember(CMSDataContext db, int oid, int pid, string orgname, int mbrid, DateTime joindt, DateTime dropdt, int userid)
 {
     db.EnrollmentTransactions.InsertOnSubmit(
         new EnrollmentTransaction
         {
             OrganizationId = oid,
             PeopleId = pid,
             OrganizationName = orgname,
             MemberTypeId = mbrid,
             TransactionDate = joindt,
             TransactionTypeId = 1,
             CreatedBy = userid,
             CreatedDate = Util.Now,
         });
     db.EnrollmentTransactions.InsertOnSubmit(
         new EnrollmentTransaction
         {
             OrganizationId = oid,
             PeopleId = pid,
             OrganizationName = orgname,
             MemberTypeId = mbrid,
             TransactionDate = dropdt,
             TransactionTypeId = 5,
             CreatedBy = userid,
             CreatedDate = Util.Now,
         });
     db.SubmitChanges();
 }
        public static OrganizationMember AddOrgMember(CMSDataContext db, int organizationId, int peopleId, int memberTypeId, DateTime enrollmentDate, string name)
        {
            var om = new OrganizationMember
            {
                OrganizationId = organizationId,
                PeopleId = peopleId,
                MemberTypeId = memberTypeId,
                EnrollmentDate = enrollmentDate,
                CreatedDate = Util.Now,
                SkipInsertTriggerProcessing = true
            };

            var et = new EnrollmentTransaction
            {
                OrganizationId = om.OrganizationId,
                PeopleId = om.PeopleId,
                MemberTypeId = om.MemberTypeId,
                OrganizationName = name,
                TransactionDate = enrollmentDate,
                EnrollmentDate = enrollmentDate,
                TransactionTypeId = 1,
                // join
                CreatedBy = Util.UserId1,
                CreatedDate = Util.Now,
                AttendancePercentage = om.AttendPct,
                SkipInsertTriggerProcessing = true
            };

            db.OrganizationMembers.InsertOnSubmit(om);
            db.EnrollmentTransactions.InsertOnSubmit(et);

            db.SubmitChanges();
            return om;
        }
Example #6
0
 public void RemoveExistingLop(CMSDataContext db, int id, string op)
 {
     var exlop = FetchLongRunningOp(db, id, op);
     if (exlop != null)
         db.LongRunningOps.DeleteOnSubmit(exlop);
     db.SubmitChanges();
 }
Example #7
0
 public static Meeting FetchOrCreateMeeting(CMSDataContext Db, int OrgId, DateTime dt, bool? noautoabsents = null)
 {
     var meeting = (from m in Db.Meetings
                    where m.OrganizationId == OrgId && m.MeetingDate == dt
                    select m).FirstOrDefault();
     if (meeting == null)
     {
         var acr = (from s in Db.OrgSchedules
                    where s.OrganizationId == OrgId
                    where s.SchedTime.Value.TimeOfDay == dt.TimeOfDay
                    where s.SchedDay == (int)dt.DayOfWeek
                    select s.AttendCreditId).SingleOrDefault();
         meeting = new Meeting
         {
             OrganizationId = OrgId,
             MeetingDate = dt,
             CreatedDate = Util.Now,
             CreatedBy = Util.UserId1,
             GroupMeetingFlag = false,
             AttendCreditId = acr ?? 1,
             NoAutoAbsents = noautoabsents
         };
         Db.Meetings.InsertOnSubmit(meeting);
         Db.SubmitChanges();
     }
     return meeting;
 }
Example #8
0
        public void Save(CMSDataContext Db, bool increment = false, string owner = null)
        {
            var q = (from e in Db.Queries
                     where e.QueryId == Id
                     select e).FirstOrDefault();

            if (q == null)
            {
                q = new Query
                {
                    QueryId = Id,
                    Owner = Util.UserName,
                    Created = DateTime.Now,
                    Ispublic = IsPublic,
                    Name = Description
                };
                Db.Queries.InsertOnSubmit(q);
            }
            if(increment)
                q.LastRun = DateTime.Now;

            if (Description != q.Name)
            {
                var same = (from v in Db.Queries
                            where !v.Ispublic
                            where v.Owner == Util.UserName
                            where v.Name == Description
                            orderby v.LastRun descending
                            select v).FirstOrDefault();
                if (same != null)
                    same.Text = ToXml();
                else
                {
                    var c = Clone();
                    var cq = new Query
                    {
                        QueryId = c.Id,
                        Owner = Util.UserName,
                        Created = q.Created,
                        Ispublic = q.Ispublic,
                        Name = q.Name,
                        Text = c.ToXml(),
                        RunCount = q.RunCount,
                        CopiedFrom = q.CopiedFrom,
                        LastRun = q.LastRun
                    };
                    Db.Queries.InsertOnSubmit(cq);
                }
            }
            q.Name = Description;
            q.LastRun = DateTime.Now;
            if(owner.HasValue())
                q.Owner = owner;
            q.Ispublic = IsPublic;
            if (increment)
                q.RunCount = q.RunCount + 1;
            q.Text = ToXml();
            Db.SubmitChanges();
        }
Example #9
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");
        }
        private void DeleteDocuments(CMSDataContext db, CMSImageDataContext idb)
        {
            var docs = db.OrgMemberDocuments.Where(p => p.PeopleId == this.PeopleId & p.OrganizationId == this.OrganizationId);

            foreach (var item in docs)
            {
                ImageData.Image.Delete(idb, item.ImageId);
            }
            db.OrgMemberDocuments.DeleteAllOnSubmit(docs);
            db.SubmitChanges();
        }
Example #11
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 #12
0
 public static TaskList GetRequiredTaskList(CMSDataContext Db, string name, int pid)
 {
     var list = Db.TaskLists.SingleOrDefault(tl => tl.CreatedBy == pid && tl.Name == name);
     if (list == null)
     {
         list = new TaskList { CreatedBy = pid, Name = name };
         Db.TaskLists.InsertOnSubmit(list);
         Db.SubmitChanges();
     }
     return list;
 }
Example #13
0
		public static Ministry FetchOrCreateMinistry(CMSDataContext Db, string name)
		{
			var m = Db.Ministries.SingleOrDefault(pp => pp.MinistryName == name);
			if (m == null)
			{
				m = new Ministry { MinistryName = name };
				Db.Ministries.InsertOnSubmit(m);
				Db.SubmitChanges();
			}
			return m;
		}
Example #14
0
 public static int FetchOrCreateBundleType(CMSDataContext Db, string type)
 {
     var bt = Db.BundleHeaderTypes.SingleOrDefault(m => m.Description == type);
     if (bt == null)
     {
         var max = Db.BundleHeaderTypes.Max(mm => mm.Id) + 1;
         bt = new BundleHeaderType { Id = max, Code = "M" + max, Description = type };
         Db.BundleHeaderTypes.InsertOnSubmit(bt);
         Db.SubmitChanges();
     }
     return bt.Id;
 }
Example #15
0
        public QueryBuilderClause SaveTo(CMSDataContext db, string name, string user, bool ispublic)
        {
            var saveto = new QueryBuilderClause();

            db.QueryBuilderClauses.InsertOnSubmit(saveto);
            saveto.CopyFromAll(this, db);
            saveto.SavedBy     = user;
            saveto.Description = name;
            saveto.IsPublic    = ispublic;
            db.SubmitChanges();
            return(saveto);
        }
Example #16
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 #17
0
        public int CleanSlate2(CMSDataContext Db)
        {
            foreach (var c in Clauses)
            {
                DeleteClause(c, Db);
            }
            SetQueryType(QueryType.Group);
            SetComparisonType(CompareType.AllTrue);
            var nc = AddNewClause(QueryType.MatchAnything, CompareType.Equal, null);

            Db.SubmitChanges();
            return(nc.QueryId);
        }
Example #18
0
 public void RemoveRoles(CMSDataContext Db, params string[] values)
 {
     foreach (var s in values)
     {
         var role = Db.Roles.SingleOrDefault(r => r.RoleName == s);
         if (role == null)
         {
             continue;
         }
         Db.UserRoles.DeleteOnSubmit(UserRoles.Single(x => x.Role.RoleName == role.RoleName));
     }
     Db.SubmitChanges();
 }
Example #19
0
 public static Contact AddContact(CMSDataContext Db, int pid, DateTime? date, string comments)
 {
     var c = new Contact
     {
         ContactDate = date ?? DateTime.Parse("1/1/1900"),
         CreatedBy = Util.UserPeopleId ?? Util.UserId1,
         CreatedDate = DateTime.Now,
         Comments = comments
     };
     c.contactees.Add(new Contactee { PeopleId = pid });
     Db.Contacts.InsertOnSubmit(c);
     Db.SubmitChanges();
     return c;
 }
Example #20
0
        public static Ministry FetchOrCreateMinistry(CMSDataContext Db, string name)
        {
            var m = Db.Ministries.SingleOrDefault(pp => pp.MinistryName == name);

            if (m == null)
            {
                m = new Ministry {
                    MinistryName = name
                };
                Db.Ministries.InsertOnSubmit(m);
                Db.SubmitChanges();
            }
            return(m);
        }
Example #21
0
        public static TaskList GetRequiredTaskList(CMSDataContext Db, string name, int pid)
        {
            var list = Db.TaskLists.SingleOrDefault(tl => tl.CreatedBy == pid && tl.Name == name);

            if (list == null)
            {
                list = new TaskList {
                    CreatedBy = pid, Name = name
                };
                Db.TaskLists.InsertOnSubmit(list);
                Db.SubmitChanges();
            }
            return(list);
        }
        public void Process(CMSDataContext db)
        {
            var lop = new LongRunningOp
            {
                Started = DateTime.Now,
                Count = Orgs.Split(',').Length,
                Processed = 0,
                Id = Id,
                Operation = Op
            };
            db.LongRunningOps.InsertOnSubmit(lop);
            db.SubmitChanges();
            Tasks.Task.Run(() => DoWork(this));
		}
Example #23
0
 public static Contact AddOrgContact(CMSDataContext db, int orgId, DateTime? date, string comments, int contactmakerid)
 {
     var c = new Contact
     {
         OrganizationId = orgId,
         ContactDate = date ?? DateTime.Parse("1/1/1900"),
         CreatedDate = DateTime.Now,
         Comments = comments
     };
     c.contactsMakers.Add(new Contactor { PeopleId = contactmakerid });
     db.Contacts.InsertOnSubmit(c);
     db.SubmitChanges();
     return c;
 }
Example #24
0
		public static ContactType FetchOrCreateContactType(CMSDataContext Db, string type)
		{
			var ct = Db.ContactTypes.SingleOrDefault(pp => pp.Description == type);
			if (ct == null)
			{
				var max = Db.ContactTypes.Max(mm => mm.Id) + 10;
				if (max < 1000)
					max = 1010;
				ct = new ContactType { Id = max, Description = type, Code = type.Truncate(20) };
				Db.ContactTypes.InsertOnSubmit(ct);
				Db.SubmitChanges();
			}
			return ct;
		}
Example #25
0
 public static ContactReason FetchOrCreateContactReason(CMSDataContext db, string reason)
 {
     var r = db.ContactReasons.SingleOrDefault(pp => pp.Description == reason);
     if (r == null)
     {
         var max = db.ContactReasons.Max(mm => mm.Id) + 10;
         if (max < 1000)
             max = 1010;
         r = new ContactReason { Id = max, Description = reason, Code = reason.Truncate(20) };
         db.ContactReasons.InsertOnSubmit(r);
         db.SubmitChanges();
     }
     return r;
 }
Example #26
0
        public static Program FetchOrCreateProgram(CMSDataContext Db, string program)
        {
            var p = Db.Programs.SingleOrDefault(pp => pp.Name == program);

            if (p == null)
            {
                p = new Program {
                    Name = program
                };
                Db.Programs.InsertOnSubmit(p);
                Db.SubmitChanges();
            }
            return(p);
        }
Example #27
0
        public void Process(CMSDataContext db)
        {
            var lop = new LongRunningOp
            {
                Started = DateTime.Now,
                Count = db.OrganizationMembers.Count(m => m.OrganizationId == Id),
                Processed = 0,
                Id = Id,
                Operation = Op
            };
            db.LongRunningOps.InsertOnSubmit(lop);
            db.SubmitChanges();

            Tasks.Task.Run(() => DoWork(host, Id));
        }
Example #28
0
        public static void ContentDeleteFromID(CMSDataContext context, int id)
        {
            if (id == 0)
            {
                return;
            }

            var cDelete = ContentFromID(context, id);

            if (cDelete != null)
            {
                context.Contents.DeleteOnSubmit(cDelete);
                context.SubmitChanges();
            }
        }
Example #29
0
        public static int FetchOrCreateBundleType(CMSDataContext Db, string type)
        {
            var bt = Db.BundleHeaderTypes.SingleOrDefault(m => m.Description == type);

            if (bt == null)
            {
                var max = Db.BundleHeaderTypes.Max(mm => mm.Id) + 1;
                bt = new BundleHeaderType {
                    Id = max, Code = "M" + max, Description = type
                };
                Db.BundleHeaderTypes.InsertOnSubmit(bt);
                Db.SubmitChanges();
            }
            return(bt.Id);
        }
Example #30
0
 public static Organization CreateOrganization(CMSDataContext Db, Division division, string organization)
 {
     var o = new Organization
     {
         OrganizationName = organization,
         SecurityTypeId = 0,
         CreatedDate = Util.Now,
         CreatedBy = Util.UserId1,
         OrganizationStatusId = 30,
     };
     division.Organizations.Add(o);
     Db.DivOrgs.InsertOnSubmit(new DivOrg { Division = division, Organization = o });
     Db.SubmitChanges();
     return o;
 }
Example #31
0
        public void Process(CMSDataContext db)
        {
            var lop = new LongRunningOp
            {
                Started = DateTime.Now,
                Count = db.OrganizationMembers.Count(m => m.OrganizationId == Id),
                Processed = 0,
                Id = Id,
                Operation = Op
            };
            db.LongRunningOps.InsertOnSubmit(lop);
            db.SubmitChanges();

            HostingEnvironment.QueueBackgroundWorkItem(ct => DoWork(host, Id));
        }
Example #32
0
        public static string DropFromOrgLinkUrl(CMSDataContext db, int orgid, int pid, int queueid)
        {
            var qs = $"{orgid},{pid},{queueid}";
            var ot = new OneTimeLink
            {
                Id          = Guid.NewGuid(),
                Querystring = qs,
            };

            db.OneTimeLinks.InsertOnSubmit(ot);
            db.SubmitChanges();
            var url = db.ServerLink($"/OnlineReg/DropFromOrgLink/{ot.Id.ToCode()}");

            return(url);
        }
Example #33
0
        public static int CreateRole(CMSDataContext db, string name)
        {
            bool?hardwired = null;

            if (Hardwired().Contains(name))
            {
                hardwired = true;
            }
            var role = new Role {
                Hardwired = hardwired, RoleName = name
            };

            db.Roles.InsertOnSubmit(role);
            db.SubmitChanges();
            return(role.RoleId);
        }
Example #34
0
 public void Process(CMSDataContext db)
 {
     // running has not started yet, start it on a separate thread
     pids = FetchPeopleIds(db, Tag.Value.ToInt()).ToList();
     var lop = new LongRunningOp()
     {
         Started = DateTime.Now,
         Count = pids.Count,
         Processed = 0,
         Id = Id,
         Operation = Op,
     };
     db.LongRunningOps.InsertOnSubmit(lop);
     db.SubmitChanges();
     Tasks.Task.Run(() => DoWork(this));
 }
Example #35
0
 public void Process(CMSDataContext db)
 {
     // running has not started yet, start it on a separate thread
     orginfos = JsonConvert.DeserializeObject<List<OrgInfo>>(Orgs);
     var lop = new LongRunningOp()
     {
         Started = DateTime.Now,
         Count = orginfos.Count,
         Processed = 0,
         Id = Id,
         Operation = Op,
     };
     db.LongRunningOps.InsertOnSubmit(lop);
     db.SubmitChanges();
     Task.Run(() => DoWork(this));
 }
Example #36
0
        public static int AddTask(CMSDataContext Db, int pid)
        {
            var p = Db.LoadPersonById(pid);
            var t = new Task
            {
                ListId                = GetRequiredTaskList(Db, "InBox", Db.UserPeopleId.Value).Id,
                OwnerId               = Db.UserPeopleId.Value,
                Description           = "Please Contact",
                ForceCompleteWContact = true,
                StatusId              = TaskStatusCode.Active,
            };

            p.TasksAboutPerson.Add(t);
            Db.SubmitChanges();
            return(t.Id);
        }
Example #37
0
 public static Contact AddContact(CMSDataContext Db, int contacteeid, DateTime? date, string comments, int? contactmakerid = null)
 {
     var c = new Contact
     {
         ContactDate = date ?? DateTime.Parse("1/1/1900"),
         CreatedBy = Util.UserPeopleId ?? Util.UserId1,
         CreatedDate = DateTime.Now,
         Comments = comments
     };
     c.contactees.Add(new Contactee { PeopleId = contacteeid });
     if(contactmakerid.HasValue)
         c.contactsMakers.Add(new Contactor { PeopleId = contactmakerid.Value });
     Db.Contacts.InsertOnSubmit(c);
     Db.SubmitChanges();
     return c;
 }
Example #38
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 #39
0
 public void Process(CMSDataContext db)
 {
     // running has not started yet, start it on a separate thread
     pids = (from p in People(db.CurrentOrg) select p.PeopleId.Value).ToList();
     Started = DateTime.Now;
     var lop = new LongRunningOp()
     {
         Started = Started,
         Count = pids.Count,
         Processed = 0,
         Id = Id,
         Operation = Op,
     };
     db.LongRunningOps.InsertOnSubmit(lop);
     db.SubmitChanges();
     Task.Run(() => DoWork(this));
 }
Example #40
0
        public void CopySettings(CMSDataContext Db, int fromid)
        {
            var frorg = Db.LoadOrganizationById(fromid);

            //only Copy settings
            NotifyIds          = frorg.NotifyIds;
            FirstMeetingDate   = frorg.FirstMeetingDate;
            LastDayBeforeExtra = frorg.LastDayBeforeExtra;
            LastMeetingDate    = frorg.LastMeetingDate;
            Limit = frorg.Limit;
            RegistrationTypeId = frorg.RegistrationTypeId;

            RegSetting = frorg.RegSetting;

            CopySettings2(frorg, this);
            Db.SubmitChanges();
        }
Example #41
0
        public static Contact AddOrgContact(CMSDataContext db, int orgId, DateTime?date, string comments, int contactmakerid)
        {
            var c = new Contact
            {
                OrganizationId = orgId,
                ContactDate    = date ?? DateTime.Parse("1/1/1900"),
                CreatedDate    = DateTime.Now,
                Comments       = comments
            };

            c.contactsMakers.Add(new Contactor {
                PeopleId = contactmakerid
            });
            db.Contacts.InsertOnSubmit(c);
            db.SubmitChanges();
            return(c);
        }
Example #42
0
 public static string ExternalLink(CMSDataContext db, int?peopleId, string url)
 {
     if (url.Contains("{token}"))
     {
         var expirationWindow = db.Setting("OTLTokenExpirationMinutes", "5").ToInt();
         var otl = new OneTimeLink
         {
             Id          = Guid.NewGuid(),
             Querystring = peopleId.ToString(),
             Expires     = DateTime.Now.AddMinutes(expirationWindow)
         };
         db.OneTimeLinks.InsertOnSubmit(otl);
         db.SubmitChanges();
         url = url.Replace("{token}", otl.Id.ToCode());
     }
     return(url);
 }
Example #43
0
        public static Division FetchOrCreateDivision(CMSDataContext Db, Program program, string division)
        {
            var d = Db.Divisions.SingleOrDefault(pp => pp.Name == division);

            if (d == null)
            {
                d = new Division {
                    Name = division, Program = program
                };
                var progdiv = new ProgDiv {
                    Division = d, Program = program
                };
                Db.ProgDivs.InsertOnSubmit(progdiv);
                Db.SubmitChanges();
            }
            return(d);
        }
 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);
 }
        private void UpdateFailureCount(CMSDataContext Db, User user, string failureType)
        {
            var windowStart  = new DateTime();
            int failureCount = 0;

            if (failureType == "password")
            {
                failureCount = user.FailedPasswordAttemptCount;
                windowStart  = user.FailedPasswordAttemptWindowStart ?? Util.Now;
            }
            else if (failureType == "passwordAnswer")
            {
                failureCount = user.FailedPasswordAnswerAttemptCount;
                windowStart  = user.FailedPasswordAnswerAttemptWindowStart ?? Util.Now;
            }
            var windowEnd = windowStart.AddMinutes(PasswordAttemptWindow);

            if (failureCount == 0 || Util.Now > windowEnd)
            {
                if (failureType == "password")
                {
                    user.FailedPasswordAttemptCount       = 1;
                    user.FailedPasswordAttemptWindowStart = Util.Now;
                }
                else if (failureType == "passwordAnswer")
                {
                    user.FailedPasswordAnswerAttemptCount       = 1;
                    user.FailedPasswordAnswerAttemptWindowStart = Util.Now;
                }
            }
            else if (failureCount++ >= MaxInvalidPasswordAttempts)
            {
                user.IsLockedOut       = true;
                user.LastLockedOutDate = DateTime.Now;
            }
            else if (failureType == "password")
            {
                user.FailedPasswordAttemptCount = failureCount;
            }
            else if (failureType == "passwordAnswer")
            {
                user.FailedPasswordAnswerAttemptCount = failureCount;
            }
            Db.SubmitChanges();
        }
Example #46
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;
            var cs = Util.GetConnectionString(host);

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

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

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

                    var q = from r in Db.UploadPeopleRuns
                            where r.Id == Db.UploadPeopleRuns.Max(rr => rr.Id)
                            select r;
                    var rt = q.Single();
                    rt.Error = ex.Message.Truncate(200);
                    Db.SubmitChanges();
                }
            });
            return Redirect("/UploadPeople/Progress");
        }
Example #47
0
        public static void RecordAttend(CMSDataContext Db, int PeopleId, int OrgId, bool Present, DateTime dt)
        {
            var q = from o in Db.Organizations
                    where o.OrganizationId == OrgId
                    let p = Db.People.Single(pp => pp.PeopleId == PeopleId)
                            select new
            {
                o.Location,
                OrgEntryPoint = o.EntryPointId,
                p.EntryPointId,
            };
            var info = q.Single();

            if (info.EntryPointId == null)
            {
                var p = Db.LoadPersonById(PeopleId);
                if (info.OrgEntryPoint > 0)
                {
                    p.EntryPointId = info.OrgEntryPoint;
                    Db.SubmitChanges();
                }
            }
            int ntries = 6;

            while (true)
            {
                try
                {
                    Db.RecordAttendance(OrgId, PeopleId, dt, Present, info.Location);
                    return;
                }
                catch (SqlException ex)
                {
                    if (ex.Number == 1205)
                    {
                        if (--ntries > 0)
                        {
                            System.Threading.Thread.Sleep(500);
                            continue;
                        }
                    }
                    throw;
                }
            }
        }
Example #48
0
        public static Organization CreateOrganization(CMSDataContext db, Division division, string organization)
        {
            var o = new Organization
            {
                OrganizationName     = organization,
                SecurityTypeId       = 0,
                CreatedDate          = Util.Now,
                CreatedBy            = db.UserId1,
                OrganizationStatusId = 30,
            };

            division.Organizations.Add(o);
            db.DivOrgs.InsertOnSubmit(new DivOrg {
                Division = division, Organization = o
            });
            db.SubmitChanges();
            return(o);
        }
Example #49
0
        public static Organization CreateOrganization(CMSDataContext Db, int divid, string organization)
        {
            var o = new Organization
            {
                OrganizationName     = organization,
                SecurityTypeId       = 0,
                CreatedDate          = Util.Now,
                CreatedBy            = Util.UserId1,
                OrganizationStatusId = 30,
                DivisionId           = divid,
            };

            Db.DivOrgs.InsertOnSubmit(new DivOrg {
                DivId = divid, Organization = o
            });
            Db.SubmitChanges();
            return(o);
        }
Example #50
0
        public void RemoveFromGroup(CMSDataContext Db, string name)
        {
            var mt = Db.MemberTags.SingleOrDefault(t => t.Name == name && t.OrgId == OrganizationId);

            if (mt == null)
            {
                return;
            }
            var omt =
                Db.OrgMemMemTags.SingleOrDefault(t => t.PeopleId == PeopleId && t.MemberTagId == mt.Id && t.OrgId == OrganizationId);

            if (omt != null)
            {
                OrgMemMemTags.Remove(omt);
                Db.OrgMemMemTags.DeleteOnSubmit(omt);
                Db.SubmitChanges();
            }
        }
Example #51
0
        public static ContactReason FetchOrCreateContactReason(CMSDataContext db, string reason)
        {
            var r = db.ContactReasons.SingleOrDefault(pp => pp.Description == reason);

            if (r == null)
            {
                var max = db.ContactReasons.Max(mm => mm.Id) + 10;
                if (max < 1000)
                {
                    max = 1010;
                }
                r = new ContactReason {
                    Id = max, Description = reason, Code = reason.Truncate(20)
                };
                db.ContactReasons.InsertOnSubmit(r);
                db.SubmitChanges();
            }
            return(r);
        }
Example #52
0
        public static ContactType FetchOrCreateContactType(CMSDataContext Db, string type)
        {
            var ct = Db.ContactTypes.SingleOrDefault(pp => pp.Description == type);

            if (ct == null)
            {
                var max = Db.ContactTypes.Max(mm => mm.Id) + 10;
                if (max < 1000)
                {
                    max = 1010;
                }
                ct = new ContactType {
                    Id = max, Description = type, Code = type.Truncate(20)
                };
                Db.ContactTypes.InsertOnSubmit(ct);
                Db.SubmitChanges();
            }
            return(ct);
        }
Example #53
0
        public static Contact AddContact(CMSDataContext Db, int pid, DateTime?date, string comments)
        {
            var c = new Contact
            {
                ContactDate     = date ?? DateTime.Parse("1/1/1900"),
                CreatedBy       = Util.UserPeopleId ?? Util.UserId1,
                CreatedDate     = DateTime.Now,
                ContactTypeId   = ContactTypeCode.Other,
                ContactReasonId = ContactReasonCode.Other,
                Comments        = comments
            };

            c.contactees.Add(new Contactee {
                PeopleId = pid
            });
            Db.Contacts.InsertOnSubmit(c);
            Db.SubmitChanges();
            return(c);
        }
Example #54
0
        public static OrganizationType FetchOrCreateType(CMSDataContext Db, string type)
        {
            var t = Db.OrganizationTypes.SingleOrDefault(pp => pp.Description == type);

            if (t == null)
            {
                var max = 10;
                if (Db.OrganizationTypes.Any())
                {
                    max = Db.OrganizationTypes.Max(mm => mm.Id) + 10;
                }
                t = new OrganizationType {
                    Description = type, Code = type.Substring(0, 3), Id = max
                };
                Db.OrganizationTypes.InsertOnSubmit(t);
                Db.SubmitChanges();
            }
            return(t);
        }
Example #55
0
 public void Process(CMSDataContext db)
 {
     var q = from a in db.Attends
             where a.MeetingId == Id
             where a.AttendanceFlag || a.EffAttendFlag == true
             select a.PeopleId;
     pids = q.ToList();
     var lop = new LongRunningOp()
     {
         Started = DateTime.Now,
         Count = pids.Count,
         Processed = 0,
         Id = Id,
         Operation = Op,
     };
     db.LongRunningOps.InsertOnSubmit(lop);
     db.SubmitChanges();
     HostingEnvironment.QueueBackgroundWorkItem(ct => DoWork(this));
 }
Example #56
0
 public static void AddNewPerson(CMSDataContext Db, int newpersonid)
 {
     var NewPeopleManagerId = Db.NewPeopleManagerId;
     var task = new Task
     {
         ListId = GetRequiredTaskList(Db, "InBox", NewPeopleManagerId).Id,
         OwnerId = NewPeopleManagerId,
         Description = "New Person Data Entry",
         WhoId = newpersonid,
         StatusId = TaskStatusCode.Active,
     };
     if (Util.UserPeopleId.HasValue && Util.UserPeopleId.Value != NewPeopleManagerId)
     {
         task.CoOwnerId = Util.UserPeopleId.Value;
         task.CoListId = GetRequiredTaskList(Db, "InBox", Util.UserPeopleId.Value).Id;
     }
     Db.Tasks.InsertOnSubmit(task);
     Db.SubmitChanges();
 }
Example #57
0
        public static MemberType FetchOrCreateMemberType(CMSDataContext Db, string type)
        {
            var mt = Db.MemberTypes.SingleOrDefault(pp => pp.Description == type);

            if (mt == null)
            {
                var max = Db.MemberTypes.Max(mm => mm.Id) + 10;
                if (max < 1000)
                {
                    max = 1010;
                }
                mt = new MemberType {
                    Id = max, Description = type, Code = type.Truncate(20), AttendanceTypeId = AttendTypeCode.Member
                };
                Db.MemberTypes.InsertOnSubmit(mt);
                Db.SubmitChanges();
            }
            return(mt);
        }
Example #58
0
        public void UploadPicture(CMSDataContext db, System.IO.Stream stream, int PeopleId)
        {
            if (Picture == null)
            {
                Picture = new Picture();
            }
            var bits = new byte[stream.Length];

            stream.Read(bits, 0, bits.Length);
            var p = Picture;

            p.CreatedDate = Util.Now;
            p.CreatedBy   = Util.UserName;
            p.ThumbId     = Image.NewImageFromBits(bits, 50, 50).Id;
            p.SmallId     = Image.NewImageFromBits(bits, 120, 120).Id;
            p.MediumId    = Image.NewImageFromBits(bits, 320, 400).Id;
            p.LargeId     = Image.NewImageFromBits(bits).Id;
            LogPictureUpload(db, PeopleId, Util.UserPeopleId ?? 1);
            db.SubmitChanges();
        }
Example #59
0
        public int AddToGroup(CMSDataContext Db, int n)
        {
            var omt = Db.OrgMemMemTags.SingleOrDefault(t =>
                                                       t.PeopleId == PeopleId &&
                                                       t.MemberTagId == n &&
                                                       t.OrgId == OrganizationId);

            if (omt == null)
            {
                Db.OrgMemMemTags.InsertOnSubmit(new OrgMemMemTag
                {
                    PeopleId    = PeopleId,
                    OrgId       = OrganizationId,
                    MemberTagId = n
                });
                Db.SubmitChanges();
                return(1);
            }
            return(0);
        }
Example #60
0
 public FamilyResult(int fid, int campus, int thisday, int page, bool waslocked)
 {
     this.fid = fid;
     this.campus = campus;
     this.thisday = thisday;
     this.page = page;
     this.waslocked = waslocked;
     if (fid > 0)
     {
         var db = new CMSDataContext(Util.ConnectionString);
         var lockf = db.FamilyCheckinLocks.SingleOrDefault(f => f.FamilyId == fid);
         if (lockf == null)
         {
             lockf = new FamilyCheckinLock { FamilyId = fid, Created = DateTime.Now };
             db.FamilyCheckinLocks.InsertOnSubmit(lockf);
         }
         lockf.Locked = true;
         if (!waslocked)
             lockf.Created = DateTime.Now;
         db.SubmitChanges();
     }
 }