public SearchOutput Search(SearchFromTo <TypeLogEnum> requestDto, string username) { SystemConfiguration config = _configService.GetSystemConfig(SystemConfigEnum.ArchiveLogData.ToString()); var day = CaculateDayOfConfig(config); var begin = Clock.Now.Date.AddDays(-day); if (requestDto.From != null && requestDto.From.Value > begin) { begin = requestDto.From.Value; } requestDto.From = new DateTime(begin.Year, begin.Month, begin.Day, 0, 0, 0); if (requestDto.To != null) { var to = requestDto.To.Value.AddDays(1); requestDto.To = new DateTime(to.Year, to.Month, to.Day, 0, 0, 0); } User user = _userRepository.GetAll().FirstOrDefault(x => x.Username.Equals(username)); switch (requestDto.Property) { case TypeLogEnum.SystemLog: return(GetAllSystemLog(requestDto, user)); case TypeLogEnum.SynchronizationLog: return(GetAllSynchronizationLog(requestDto, user)); case TypeLogEnum.TransactionLog: return(GetAllTransactionLog(requestDto, user)); default: return(null); } }
private SearchOutput GetAllSynchronizationLog(SearchFromTo <TypeLogEnum> requestDto, User user) { List <Expression <Func <SynchronizationLog, bool> > > listExpresion = GetExpressions <SynchronizationLog>(requestDto.DataSearch, 5); var logQuery = _logRepository.GetAll().Where(a => TypeLogEnum.SynchronizationLog.ToString().Equals(a.Message) && (!requestDto.From.HasValue || a.TimeStamp >= requestDto.From.Value) && (!requestDto.To.HasValue || (a.TimeStamp < requestDto.To.Value))) .Select(row => new SynchronizationLog(row.LogEvent)); if (listExpresion != null) { foreach (Expression <Func <SynchronizationLog, bool> > expression in listExpresion) { logQuery = logQuery.Where(expression); } } ApplyOrderBy(requestDto.DataSearch, logQuery); return(ApplyPaging(requestDto.DataSearch, logQuery)); }
private SearchOutput GetAllSystemLog(SearchFromTo <TypeLogEnum> requestDto, User user) { if (!UserTypeEnum.SuperAdmin.Equals(user.UserType)) { return(null); } List <Expression <Func <SystemLog, bool> > > listExpresion = GetExpressions <SystemLog>(requestDto.DataSearch, 2); var logQuery = _logRepository.GetAll().Where(a => !TypeLogEnum.TransactionLog.ToString().Equals(a.Message) && !TypeLogEnum.SynchronizationLog.ToString().Equals(a.Message) && (!requestDto.From.HasValue || a.TimeStamp >= requestDto.From.Value) && (!requestDto.To.HasValue || (a.TimeStamp < requestDto.To.Value))) .Select(row => new SystemLog { Description = row.Level, Message = row.Message, Time = row.TimeStamp }); if (listExpresion != null) { foreach (Expression <Func <SystemLog, bool> > expression in listExpresion) { logQuery = logQuery.Where(expression); } } ApplyOrderBy(requestDto.DataSearch, logQuery); return(ApplyPaging(requestDto.DataSearch, logQuery)); }
public IActionResult Report([FromBody] SearchFromTo <TypeLogEnum> requestDto) { SearchOutput data = _logService.Search(requestDto, GetCurrentUser()); return(Json(data)); }