public ActionResult Search(bool? admin, string username,
     bool? date, DateTime? from, DateTime? to,
     bool? description, string contains)
 {
     SearchOperationLogOption solo = new SearchOperationLogOption();
     if (admin != null)
     {
         solo.Admin = admin.Value;
         solo.UserName = username;
     }
     if (date != null)
     {
         solo.Date = date.Value;
         solo.From = from ?? DateTime.MinValue;
         solo.To = to ?? DateTime.MinValue;
     }
     if (description != null)
     {
         solo.Description = description.Value;
         solo.Contains = contains;
     }
     List<object> logs = _bll.Search(solo);
     if (logs.Count <= 0)
     {
         return JsonHelper.GetJsonResult(_ERROR, "没有记录");
     }
     return JsonHelper.GetJsonResult(_OK, "查询成功", null, logs);
 }
 public List<object> Search(SearchOperationLogOption solo)
 {
     if (solo == null)
     {
         throw new ArgumentNullException("solo不能为null");
     }
     return dal.Search(solo);
 }
        public List<object> Search(SearchOperationLogOption solo)
        {
            var joinsql = from log in dbContext.AdminOperationLogs
                          join admin in dbContext.AdminUsers on log.AdminUserId equals admin.Id into temp
                          from tt in temp.DefaultIfEmpty()
                          select new
                          {
                              AdminUserId = tt.Id,
                              UserName = tt.UserName,
                              CreateDateTime = log.CreateDateTime,
                              Description = log.Description,
                          };
            bool ok = false;    // 是否有查询条件
            if (solo.Admin)
            {
                AdminUser au = dbContext.AdminUsers.Where(a => a.UserName == solo.UserName).FirstOrDefault();
                if (au != null)
                {
                    joinsql = joinsql.Where(log => log.AdminUserId == au.Id);
                    ok = true;
                }
            }
            if (solo.Date)
            {
                DateTime start = solo.From;
                DateTime end = solo.To;
                if (start != DateTime.MinValue || end != DateTime.MinValue)
                {
                    if (start != DateTime.MinValue && end != DateTime.MinValue && start > end)
                    {
                        CommonHelper.Swap<DateTime>(ref start, ref end);
                    }
                    end = (end == DateTime.MinValue) ? DateTime.MaxValue : end.AddDays(1).AddMilliseconds(-1.0);  // {23:59:59.9990000}
                    joinsql = joinsql.Where(log => log.CreateDateTime >= start).Where(log => log.CreateDateTime <= end);
                    ok = true;
                }
            }
            if (solo.Description)
            {
                if (!CommonHelper.IsNullOrEmptyOrWhiteSpace(solo.Contains))
                {
                    joinsql = joinsql.Where(log => log.Description.Contains(solo.Contains));
                    ok = true;
                }
            }

            List<object> logs = new List<object>();
            if (ok)
            {
                joinsql = joinsql.OrderByDescending(log => log.CreateDateTime);
                foreach (var log in joinsql)
                {
                    logs.Add(new
                    {
                        UserName = log.UserName,
                        CreateDateTime = log.CreateDateTime,
                        Description = log.Description,
                    });
                }
            }
            return logs;
        }