Beispiel #1
0
 internal static Expression ContributionAmount2(
     ParameterExpression parm, CMSDataContext Db,
     DateTime? start,
     DateTime? end,
     int fund,
     CompareType op,
     decimal amt)
 {
     if (Db.CurrentUser == null || Db.CurrentUser.Roles.All(rr => rr != "Finance"))
         return AlwaysFalse(parm);
     IQueryable<int> q = null;
     switch (op)
     {
         case CompareType.GreaterEqual:
             q = from c in Db.Contributions2(start, end, 0, false, false, true)
                 where fund == 0 || c.FundId == fund
                 group c by c.CreditGiverId into g
                 where g.Sum(cc => cc.Amount) >= amt
                 select g.Key ?? 0;
             break;
         case CompareType.Greater:
             q = from c in Db.Contributions2(start, end, 0, false, false, true)
                 where fund == 0 || c.FundId == fund
                 group c by c.CreditGiverId into g
                 where g.Sum(cc => cc.Amount) > amt
                 select g.Key ?? 0;
             break;
         case CompareType.LessEqual:
             q = from c in Db.Contributions2(start, end, 0, false, false, true)
                 where fund == 0 || c.FundId == fund
                 where c.Amount > 0
                 group c by c.CreditGiverId into g
                 where g.Sum(cc => cc.Amount) <= amt
                 select g.Key ?? 0;
             break;
         case CompareType.Less:
             q = from c in Db.Contributions2(start, end, 0, false, false, true)
                 where fund == 0 || c.FundId == fund
                 where c.Amount > 0
                 group c by c.CreditGiverId into g
                 where g.Sum(cc => cc.Amount) < amt
                 select g.Key ?? 0;
             break;
         case CompareType.Equal:
             q = from c in Db.Contributions2(start, end, 0, false, false, true)
                 where fund == 0 || c.FundId == fund
                 where c.Amount > 0
                 group c by c.CreditGiverId into g
                 where g.Sum(cc => cc.Amount) == amt
                 select g.Key ?? 0;
             break;
         case CompareType.NotEqual:
             q = from c in Db.Contributions2(start, end, 0, false, false, true)
                 where fund == 0 || c.FundId == fund
                 where c.Amount > 0
                 group c by c.CreditGiverId into g
                 where g.Sum(cc => cc.Amount) != amt
                 select g.Key ?? 0;
             break;
     }
     var tag = Db.PopulateTemporaryTag(q);
     Expression<Func<Person, bool>> pred = p => p.Tags.Any(t => t.Id == tag.Id);
     Expression expr = Expression.Invoke(pred, parm);
     return expr;
 }
Beispiel #2
0
        internal static Expression RecentPledgeCount(
            ParameterExpression parm, CMSDataContext Db,
            int days,
            int fund,
            CompareType op,
            int cnt)
        {
            if (Db.CurrentUser == null || Db.CurrentUser.Roles.All(rr => rr != "Finance"))
                return AlwaysFalse(parm);

            var now = DateTime.Now;
            var dt = now.AddDays(-days);
            IQueryable<int> q = null;
            switch (op)
            {
                case CompareType.Greater:
                    q = from c in Db.Contributions2(dt, now, 0, true, false, true)
                        where fund == 0 || c.FundId == fund
                        where c.PledgeAmount > 0
                        group c by c.CreditGiverId into g
                        where g.Count() > cnt
                        select g.Key ?? 0;
                    break;
                case CompareType.GreaterEqual:
                    q = from c in Db.Contributions2(dt, now, 0, true, false, true)
                        where fund == 0 || c.FundId == fund
                        where c.PledgeAmount > 0
                        group c by c.CreditGiverId into g
                        where g.Count() >= cnt
                        select g.Key ?? 0;
                    break;
                case CompareType.Less:
                    q = from c in Db.Contributions2(dt, now, 0, true, false, true)
                        where fund == 0 || c.FundId == fund
                        where c.PledgeAmount > 0
                        group c by c.CreditGiverId into g
                        where g.Count() < cnt
                        select g.Key ?? 0;
                    break;
                case CompareType.LessEqual:
                    q = from c in Db.Contributions2(dt, now, 0, true, false, true)
                        where fund == 0 || c.FundId == fund
                        where c.PledgeAmount > 0
                        group c by c.CreditGiverId into g
                        where g.Count() <= cnt
                        select g.Key ?? 0;
                    break;
                case CompareType.Equal:
                    if (cnt == 0) // special case, use different approach
                    {
                        q = from pid in Db.Pledges0(dt, now, fund, 0)
                            select pid.PeopleId;
                        Expression<Func<Person, bool>> pred0 = p => q.Contains(p.PeopleId);
                        Expression expr0 = Expression.Invoke(pred0, parm);
                        return expr0;
                    }
                    q = from c in Db.Contributions2(dt, now, 0, true, false, true)
                        where fund == 0 || c.FundId == fund
                        where c.PledgeAmount > 0
                        group c by c.CreditGiverId into g
                        where g.Count() == cnt
                        select g.Key ?? 0;
                    break;
                case CompareType.NotEqual:
                    q = from c in Db.Contributions2(dt, now, 0, true, false, true)
                        where fund == 0 || c.FundId == fund
                        where c.PledgeAmount > 0
                        group c by c.CreditGiverId into g
                        where g.Count() != cnt
                        select g.Key ?? 0;
                    break;
            }
            var tag = Db.PopulateTemporaryTag(q);
            Expression<Func<Person, bool>> pred = p => p.Tags.Any(t => t.Id == tag.Id);
            Expression expr = Expression.Invoke(pred, parm);
            return expr;
        }