8,497
社区成员
发帖
与我相关
我的任务
分享
public ViewSearch SearchByTopic(string key)
{
ViewSearch vs = new ViewSearch();
vs.Topic = TopicRepository.Where(t => SplitTopic(t.content, key));
return vs;
}
private bool SplitTopic(string Content, string key)
{
MatchCollection matchs = SplitTopic(Content);
foreach (var mc in matchs)
{
if (mc.ToString().ToLower().IndexOf(key) >= 0)
{
return true;
}
continue;
}
return false;
}
public static MatchCollection SplitTopic(string Content)
{
return Regex.Matches(Content, "<T>(.*?)</T>");
}
Expression<Func<SysLogEntity, bool>> expr = n => GetLogCondition(n, dateBegin, dateEnd);
Expression<Func<SysUsersEntity, bool>> expUser = user => GetUserCondition(user, strUser);
SysLogService ss = new SysLogService();
UserService us = new UserService();
IEnumerable<object> result = from log in ss.Table as IEnumerable<SysLogEntity>
join user in us.Table as IEnumerable<SysUsersEntity>
on log.UserId equals user.ID
where GetLogCondition(log, dateBegin, dateEnd) && GetUserCondition(user, strUser)
select new
{
Name = user.UserName,
Date = log.CreationDate,
Actions = log.Action,
What = log.EntityType,
ID = log.EntityId
} as object;
private bool GetLogCondition(SysLogEntity log,DateTime? dateBegin,DateTime? dateEnd)
{
bool result = true;
if (dateBegin >DateTime.Now.AddYears(-50))
result &= log.CreationDate >= dateBegin;
if (dateEnd > DateTime.Now.AddYears(-50))
result &= log.CreationDate <= dateEnd;
return result;
}
private bool GetUserCondition(SysUsersEntity user, string name)
{
bool result = true;
if (!string.IsNullOrEmpty(name))
result &= user.UserName.Contains(name);
return result;
}