public IActionResult AuditLogTablePartialView(string name             = "", string type = "", string message = "",
                                                      int page                = 1,
                                                      int pageSize            = 20, FilterByDate filterOption = FilterByDate.All, string from = null, string to = null,
                                                      SortByColumn sortOption = SortByColumn.CreationDate, bool descending = true)
        {
            ViewBag.FilterOption = filterOption;
            ViewBag.FromDate     = from;
            ViewBag.ToDate       = to;
            ViewBag.SortOption   = sortOption;
            ViewBag.IdDescending = descending;
            ViewBag.Name         = name;
            ViewBag.Type         = type;
            ViewBag.Message      = message;

            var auditLogs = getAllAuditLogFactory.Create().Invoke();

            auditLogs = FilterLogs(name, type, message, auditLogs);
            if (filterOption != FilterByDate.All)
            {
                auditLogs = FilterByDateAuditLogs(auditLogs, filterOption, from, to);
            }

            ViewBag.TotalRows   = auditLogs.Count();
            ViewBag.UsersCount  = auditLogs.Count() / pageSize;
            ViewBag.Page        = page;
            ViewBag.RowsPerPage = pageSize;

            auditLogs = SortAuditLogs(auditLogs, sortOption, descending).Skip(pageSize * (page - 1)).Take(pageSize);

            return(PartialView("Partials/AuditLogTable", auditLogs));
        }
        private IEnumerable <AuditLogModel> FilterByDateAuditLogs(IEnumerable <AuditLogModel> auditLogs,
                                                                  FilterByDate filterOption, string from, string to)
        {
            switch (filterOption)
            {
            case FilterByDate.LastWeek:
                return(auditLogs.Where(m => m.CreationDate >= DateTime.Now.AddDays(-7)));

            case FilterByDate.LastMonth:
                return(auditLogs.Where(m => m.CreationDate >= DateTime.Now.AddMonths(-1)));

            case FilterByDate.Custom:
            {
                var fromTime = DateTime.ParseExact(from, "dd-MM-yyyy", CultureInfo.InvariantCulture);
                var toTime   = DateTime.ParseExact(to, "dd-MM-yyyy", CultureInfo.InvariantCulture);

                return(auditLogs.Where(m => (m.CreationDate.Date >= fromTime) && (m.CreationDate.Date <= toTime)));
            }

            default:
                return(null);
            }
        }