public int GetCountFilteredLoginsForUser(string userId, int?count, TimeSpanGranularity granularity = 0) { if (count.HasValue && granularity > 0) { var beginDate = DefineBeginDate(count.Value, granularity); return(_context.UserLoginMonitors.Where(x => x.UserId == userId && x.TimeStamp >= beginDate).Count()); } else { return(GetLoginsForUser(userId).Count()); } }
public static DateTime DefineBeginDate(int count, TimeSpanGranularity granularity) { var beginDate = DateTime.MinValue; switch (granularity) { case DataHelper.TimeSpanGranularity.Days: beginDate = DateTime.Now.AddDays(-count); break; case DataHelper.TimeSpanGranularity.Months: beginDate = DateTime.Now.AddMonths(-count); break; case DataHelper.TimeSpanGranularity.Years: beginDate = DateTime.Now.AddYears(-count); break; default: break; } return(beginDate); }