예제 #1
0
        public ActionResult LogReportFilter(string logType = null, string fromDate = null, string toDate = null)
        {
            var      allLogs   = _logService.GetAll();
            decimal  logTypeId = 0;
            DateTime fDate     = !string.IsNullOrEmpty(fromDate) ? GeneralMethods.ConvertToGregorian(fromDate) : DateTime.MinValue;
            DateTime tDate     = !string.IsNullOrEmpty(toDate) ? GeneralMethods.ConvertToGregorian(toDate) : DateTime.MinValue;

            if (decimal.TryParse(logType, out logTypeId) && logTypeId > 0)
            {
                allLogs = allLogs.Where(w => w.LogType.Id == logTypeId).ToList();
            }
            if (fDate != DateTime.MinValue)
            {
                allLogs = allLogs.Where(w => w.Date >= fDate).ToList();
            }
            if (tDate != DateTime.MinValue)
            {
                allLogs = allLogs.Where(w => w.Date <= tDate).ToList();
            }
            var model = allLogs.Select(s => new Models.Log
            {
                Date         = s.Date,
                Desacription = s.Desacription,
                Id           = s.Id,
                LogType      = new Models.LogType
                {
                    CreationDate     = s.LogType.CreationDate,
                    Id               = s.LogType.Id,
                    IsActive         = s.LogType.IsActive,
                    LastModifiedDate = s.LogType.LastModifiedDate,
                    LogTypeID        = s.LogType.LogTypeID,
                    Name             = s.LogType.Name
                },
                User = Mapper.Map <Models.User>(s.User)
            }).OrderByDescending(o => o.Date).ToList();

            TempData["FilteredModel"]  = model;
            TempData["FilterLogType"]  = logType;
            TempData["FilterFromDate"] = fromDate;
            TempData["FilterToDate"]   = toDate;
            return(Json(Url.Action("LogsReport", "Pages")));
        }