Ejemplo n.º 1
0
        public ContentResult TagAll(string tagname, bool?cleartagfirst, QueryModel m)
        {
            // take a query, add all people from the result of that query to the tag specified
            // empty the tag first if requested
            string resultMessage  = string.Empty;
            bool   shouldContinue = true;

            if (shouldContinue)
            {
                var workingTag     = CurrentDatabase.FetchOrCreateTag(Util2.GetValidTagName(tagname), Util.UserPeopleId, DbUtil.TagTypeId_Personal);
                var shouldEmptyTag = cleartagfirst ?? false;

                if (shouldEmptyTag)
                {
                    CurrentDatabase.ClearTag(workingTag);
                }

                m.TagAll(workingTag);

                Util2.CurrentTag = workingTag.Name;

                resultMessage  = "Manage";
                shouldContinue = false;
            }

            return(Content(resultMessage));
        }
Ejemplo n.º 2
0
        public ContentResult TagAll(Guid id, string tagname, bool?cleartagfirst)
        {
            if (!tagname.HasValue())
            {
                return(Content("no tag name"));
            }

            CurrentDatabase.SetNoLock();
            var q = CurrentDatabase.PeopleQuery(id);

            if (Util2.CurrentTagName == tagname && !(cleartagfirst ?? false))
            {
                CurrentDatabase.TagAll(q);
                return(Content("Remove"));
            }
            var tag = CurrentDatabase.FetchOrCreateTag(tagname, Util.UserPeopleId, DbUtil.TagTypeId_Personal);

            if (cleartagfirst ?? false)
            {
                CurrentDatabase.ClearTag(tag);
            }

            CurrentDatabase.TagAll(q, tag);
            Util2.CurrentTag = tagname;
            CurrentDatabase.TagCurrent();
            return(Content("Manage"));
        }
Ejemplo n.º 3
0
        public ActionResult UpdateNotifyIds(int id, int topid, string field)
        {
            var t             = CurrentDatabase.FetchOrCreateTag(CurrentDatabase.CurrentSessionId, CurrentDatabase.UserPeopleId, DbUtil.TagTypeId_AddSelected);
            var selected_pids = (from p in t.People(CurrentDatabase)
                                 orderby p.PeopleId == topid ? "0" : "1"
                                 select p.PeopleId).ToArray();
            var o         = CurrentDatabase.LoadOrganizationById(id);
            var notifyids = string.Join(",", selected_pids);

            switch (field.ToLower())
            {
            case "notifyids":
                o.NotifyIds = notifyids;
                break;

            case "giftnotifyids":
                o.GiftNotifyIds = notifyids;
                break;
            }
            CurrentDatabase.TagPeople.DeleteAllOnSubmit(t.PersonTags);
            CurrentDatabase.Tags.DeleteOnSubmit(t);
            CurrentDatabase.SubmitChanges();
            ViewBag.OrgId = id;
            ViewBag.field = field;
            var view = ViewExtensions2.RenderPartialViewToString(this, "Registration/NotifyList", notifyids);

            return(Content(view));
            //return View("NotifyList2", notifyids);
        }
Ejemplo n.º 4
0
        public ActionResult NotifyIds(int id, string field)
        {
            Response.NoCache();
            var t = CurrentDatabase.FetchOrCreateTag(CurrentDatabase.CurrentSessionId, CurrentDatabase.UserPeopleId, DbUtil.TagTypeId_AddSelected);

            CurrentDatabase.TagPeople.DeleteAllOnSubmit(t.PersonTags);
            CurrentDatabase.SetCurrentOrgId(id);
            CurrentDatabase.SubmitChanges();
            var    o         = CurrentDatabase.LoadOrganizationById(id);
            string notifyids = null;

            switch (field.ToLower())
            {
            case "notifyids":
                notifyids = o.NotifyIds;
                break;

            case "giftnotifyids":
                notifyids = o.GiftNotifyIds;
                break;
            }
            var q = CurrentDatabase.PeopleFromPidString(notifyids).Select(p => p.PeopleId);

            foreach (var pid in q)
            {
                t.PersonTags.Add(new TagPerson {
                    PeopleId = pid
                });
            }
            CurrentDatabase.SubmitChanges();
            return(Redirect("/SearchUsers?ordered=true&topid=" + q.FirstOrDefault()));
        }
Ejemplo n.º 5
0
        public ActionResult UpdatePersonCanEmailForList(int id, int?topid0)
        {
            var t             = CurrentDatabase.FetchOrCreateTag(CurrentDatabase.CurrentSessionId, CurrentDatabase.UserPeopleId, DbUtil.TagTypeId_AddSelected);
            var selected_pids = (from p in t.People(CurrentDatabase)
                                 where p.PeopleId != id
                                 select p.PeopleId).ToArray();

            CurrentDatabase.TagPeople.DeleteAllOnSubmit(t.PersonTags);
            CurrentDatabase.Tags.DeleteOnSubmit(t);
            CurrentDatabase.SubmitChanges();
            if (topid0 == id)
            {
                var cn = new SqlConnection(Util.ConnectionString);
                cn.Open();
                cn.Execute("delete PeopleCanEmailFor where CanEmail = @id", new { id });
            }
            foreach (var pid in selected_pids)
            {
                CurrentDatabase.PeopleCanEmailFors.InsertOnSubmit(new PeopleCanEmailFor {
                    CanEmail = id, OnBehalfOf = pid
                });
            }

            CurrentDatabase.SubmitChanges();
            return(Content("ok"));
        }
Ejemplo n.º 6
0
        public ActionResult UpdateShared()
        {
            var t             = CurrentDatabase.FetchOrCreateTag(Util.SessionId, Util.UserPeopleId, DbUtil.TagTypeId_AddSelected);
            var tag           = CurrentDatabase.TagCurrent();
            var selected_pids = (from p in t.People(CurrentDatabase)
                                 where p.PeopleId != Util.UserPeopleId
                                 select p.PeopleId).ToArray();
            var userDeletes = tag.TagShares.Where(ts => !selected_pids.Contains(ts.PeopleId));

            CurrentDatabase.TagShares.DeleteAllOnSubmit(userDeletes);
            var tag_pids = tag.TagShares.Select(ts => ts.PeopleId).ToArray();
            var userAdds = from pid in selected_pids
                           join tpid in tag_pids on pid equals tpid into j
                           from p in j.DefaultIfEmpty(-1)
                           where p == -1
                           select pid;

            foreach (var pid in userAdds)
            {
                tag.TagShares.Add(new TagShare {
                    PeopleId = pid
                });
            }

            CurrentDatabase.TagPeople.DeleteAllOnSubmit(t.PersonTags);
            CurrentDatabase.Tags.DeleteOnSubmit(t);
            CurrentDatabase.SubmitChanges();
            return(Content(CurrentDatabase.TagShares.Count(tt => tt.TagId == tag.Id).ToString()));
        }
Ejemplo n.º 7
0
        public ActionResult TagUntag(int id, bool ischecked, bool isordered)
        {
            var t     = CurrentDatabase.FetchOrCreateTag(Util.SessionId, Util.UserPeopleId, DbUtil.TagTypeId_AddSelected);
            var count = t.PersonTags.Count();
            var topid = "";
            var tp    = CurrentDatabase.TagPeople.SingleOrDefault(tt => tt.PeopleId == id && tt.Id == t.Id);

            if (ischecked)
            {
                if (tp != null)
                {
                    CurrentDatabase.TagPeople.DeleteOnSubmit(tp);
                }
            }
            else if (tp == null)
            {
                if (count == 0 && isordered)
                {
                    topid = id.ToString();
                }

                tp = new TagPerson()
                {
                    Id = t.Id, PeopleId = id
                };
                CurrentDatabase.TagPeople.InsertOnSubmit(tp);
            }
            CurrentDatabase.SubmitChanges();
            return(Content(topid));
        }
Ejemplo n.º 8
0
        public ActionResult PersonCanEmailForList(int id)
        {
            Response.NoCache();
            var t = CurrentDatabase.FetchOrCreateTag(CurrentDatabase.CurrentSessionId, CurrentDatabase.UserPeopleId, DbUtil.TagTypeId_AddSelected);

            CurrentDatabase.TagPeople.DeleteAllOnSubmit(t.PersonTags);
            CurrentDatabase.SubmitChanges();
            if (id > 0)
            {
                var q = (from cf in CurrentDatabase.PeopleCanEmailFors
                         where cf.CanEmail == id
                         select cf.OnBehalfOf).ToList();
                if (!q.Contains(id))
                {
                    t.PersonTags.Add(new TagPerson {
                        PeopleId = id
                    });
                }

                foreach (var pid in q)
                {
                    t.PersonTags.Add(new TagPerson {
                        PeopleId = pid
                    });
                }

                CurrentDatabase.SubmitChanges();
                return(Redirect("/SearchUsers?ordered=true&topid=" + id));
            }
            return(Redirect("/SearchUsers?singlemode=true"));
        }
Ejemplo n.º 9
0
        public ActionResult SharedTags()
        {
            var t = CurrentDatabase.FetchOrCreateTag(Util.SessionId, Util.UserPeopleId, DbUtil.TagTypeId_AddSelected);

            CurrentDatabase.TagPeople.DeleteAllOnSubmit(t.PersonTags);
            CurrentDatabase.SubmitChanges();
            var tag = CurrentDatabase.TagCurrent();

            foreach (var ts in tag.TagShares)
            {
                t.PersonTags.Add(new TagPerson {
                    PeopleId = ts.PeopleId
                });
            }

            CurrentDatabase.SubmitChanges();
            return(Redirect("/SearchUsers"));
        }
Ejemplo n.º 10
0
        public ActionResult Tag(int id, string tagname, bool?cleartagfirst)
        {
            if (Util2.CurrentTagName == tagname && !(cleartagfirst ?? false))
            {
                Person.Tag(CurrentDatabase, id, Util2.CurrentTagName, Util2.CurrentTagOwnerId, DbUtil.TagTypeId_Personal);
                CurrentDatabase.SubmitChanges();
                return(Content("OK"));
            }
            var tag = CurrentDatabase.FetchOrCreateTag(tagname, Util.UserPeopleId, DbUtil.TagTypeId_Personal);

            if (cleartagfirst ?? false)
            {
                CurrentDatabase.ClearTag(tag);
            }

            Person.Tag(CurrentDatabase, id, Util2.CurrentTagName, Util2.CurrentTagOwnerId, DbUtil.TagTypeId_Personal);
            CurrentDatabase.SubmitChanges();
            Util2.CurrentTag = tagname;
            CurrentDatabase.TagCurrent();
            return(Content("OK"));
        }
Ejemplo n.º 11
0
        public void TagAll(string tagname, bool?cleartagfirst)
        {
            var workingTag     = CurrentDatabase.FetchOrCreateTag(Util2.GetValidTagName(tagname), CurrentDatabase.UserPeopleId, DbUtil.TagTypeId_Personal);
            var shouldEmptyTag = cleartagfirst ?? false;

            if (shouldEmptyTag)
            {
                CurrentDatabase.ClearTag(workingTag);
            }
            if (workingTag == null)
            {
                throw new ArgumentNullException(nameof(workingTag));
            }

            CurrentDatabase.CurrentTagName    = workingTag.Name;
            CurrentDatabase.CurrentTagOwnerId = workingTag.PersonOwner.PeopleId;

            var q = Senders();

            CurrentDatabase.TagAll(q, workingTag);
        }
Ejemplo n.º 12
0
        public ActionResult NotifyIds(int id, string field)
        {
            if (Util.SessionTimedOut())
            {
                return(Content("<script type='text/javascript'>window.onload = function() { parent.location = '/'; }</script>"));
            }
            Response.NoCache();
            var t = CurrentDatabase.FetchOrCreateTag(Util.SessionId, Util.UserPeopleId, DbUtil.TagTypeId_AddSelected);

            CurrentDatabase.TagPeople.DeleteAllOnSubmit(t.PersonTags);
            CurrentDatabase.SetCurrentOrgId(id);
            CurrentDatabase.SubmitChanges();
            var    o         = CurrentDatabase.LoadOrganizationById(id);
            string notifyids = null;

            switch (field.ToLower())
            {
            case "notifyids":
                notifyids = o.NotifyIds;
                break;

            case "giftnotifyids":
                notifyids = o.GiftNotifyIds;
                break;
            }
            var q = CurrentDatabase.PeopleFromPidString(notifyids).Select(p => p.PeopleId);

            foreach (var pid in q)
            {
                t.PersonTags.Add(new TagPerson {
                    PeopleId = pid
                });
            }
            CurrentDatabase.SubmitChanges();
            return(Redirect("/SearchUsers?ordered=true&topid=" + q.FirstOrDefault()));
        }
Ejemplo n.º 13
0
        public ContentResult TagAll(string tagname, bool?cleartagfirst, QueryModel m)
        {
            if (!tagname.HasValue())
            {
                return(Content("error: no tag name"));
            }

            if (Util2.CurrentTagName == tagname && !(cleartagfirst ?? false))
            {
                m.TagAll();
                return(Content("Remove"));
            }
            var tag = CurrentDatabase.FetchOrCreateTag(tagname, Util.UserPeopleId, DbUtil.TagTypeId_Personal);

            if (cleartagfirst ?? false)
            {
                CurrentDatabase.ClearTag(tag);
            }

            m.TagAll(tag);
            Util2.CurrentTag = tagname;
            CurrentDatabase.TagCurrent();
            return(Content("Manage"));
        }
Ejemplo n.º 14
0
        public void SendEmails()
        {
            var tag = CurrentDatabase.FetchOrCreateTag(Util.SessionId, Util.UserPeopleId, CurrentDatabase.NextTagId);

            CurrentDatabase.ExecuteCommand("delete TagPerson where Id = {0}", tag.Id);
            CurrentDatabase.TagAll(pids, tag);
            var dt = new DateTime(ticks);

            foreach (var id in pids)
            {
                var vr = new SubRequest
                {
                    AttendId     = attend.AttendId,
                    RequestorId  = person.PeopleId,
                    Requested    = dt,
                    SubstituteId = id,
                };
                attend.SubRequests.Add(vr);
            }
            CurrentDatabase.SubmitChanges();

            var qb = CurrentDatabase.ScratchPadCondition();

            qb.Reset();
            qb.AddNewClause(QueryType.HasMyTag, CompareType.Equal, $"{tag.Id},temp");
            attend.Commitment = CmsData.Codes.AttendCommitmentCode.FindSub;
            qb.Save(CurrentDatabase);

            var rurl       = CurrentDatabase.ServerLink($"/OnlineReg/VolSubReport/{attend.AttendId}/{person.PeopleId}/{dt.Ticks}");
            var reportlink = $@"<a href=""{rurl}"">Substitute Status Report</a>";
            var list       = CurrentDatabase.PeopleFromPidString(org.NotifyIds).ToList();

            //list.Insert(0, person);
            CurrentDatabase.Email(person.FromEmail, list,
                                  "Volunteer Substitute Commitment for " + org.OrganizationName,
                                  $@"
<p>{person.Name} has requested a substitute on {attend.MeetingDate:MMM d} at {attend.MeetingDate:h:mm tt}.</p>
<blockquote>
{reportlink}
</blockquote>");

            // Email subs
            var m = new MassEmailer(qb.Id);

            m.Subject = subject;
            m.Body    = message;

            m.FromName    = person.Name;
            m.FromAddress = person.FromEmail;

            var    eqid = m.CreateQueue(transactional: true).Id;
            string host = CurrentDatabase.Host;
            // save these from HttpContext to set again inside thread local storage
            var useremail         = Util.UserEmail;
            var isinroleemailtest = HttpContextFactory.Current.User.IsInRole("EmailTest");

            Log("Send Emails");

            HostingEnvironment.QueueBackgroundWorkItem(ct =>
            {
                try
                {
                    var db = CMSDataContext.Create(host);
                    // set these again inside thread local storage
                    Util.UserEmail         = useremail;
                    Util.IsInRoleEmailTest = isinroleemailtest;
                    db.SendPeopleEmail(eqid);
                }
                catch (Exception ex)
                {
                    Log("Email Error");
                    var ex2           = new Exception("Emailing error for queueid " + eqid, ex);
                    ErrorLog errorLog = ErrorLog.GetDefault(null);
                    errorLog.Log(new Error(ex2));

                    var db = CMSDataContext.Create(host);
                    // set these again inside thread local storage
                    Util.UserEmail         = useremail;
                    Util.IsInRoleEmailTest = isinroleemailtest;
                    var equeue             = db.EmailQueues.Single(ee => ee.Id == eqid);
                    equeue.Error           = ex.Message.Truncate(200);
                    db.SubmitChanges();
                }
            });
        }