Beispiel #1
0
        public FindResponse FindDataLogs(FindRequest request)
        {
            var response = new FindResponse();

            using (var db = DbContext)
            {
                var query = db.DataLogs.AsQueryable();

                if (request.Table.HasValue)
                {
                    query = query.Where(q => q.Table == request.Table);
                }

                if (request.ItemId.HasValue)
                {
                    query = query.Where(q => q.ItemId == request.ItemId);
                }

                if (!String.IsNullOrEmpty(request.TextSearch))
                {
                    request.TextSearch = request.TextSearch.ToStr().Trim().ToLower();
                    query = query.Where(q =>
                        q.BeUser.FullName.ToLower().Contains(request.TextSearch)
                        || q.OldData.ToLower().Contains(request.TextSearch)
                        || q.NewData.ToLower().Contains(request.TextSearch)
                        || q.Action.ToString().ToLower().Contains(request.TextSearch)
                        );
                }

                if (request.FromDate.HasValue)
                {
                    query = query.Where(q => q.LogDate >= request.FromDate);
                }

                if (request.ToDate.HasValue)
                {
                    query = query.Where(q => q.LogDate <= request.ToDate);
                }

                query = request.IsSortingValid ? request.ApplySortOption(query) : request.ApplyPageOption(query.OrderByDescending(q => q.LogDate));

                var pagingResult = request.ApplyPageOption(query).ToList();

                response.TotalRecords = query.Count();
                response.Results = pagingResult.MapList<DataLog>();
            }

            return response;
        }
        public ActionResult Index(DataLogIndexModel model)
        {
            if (!model.SortDirection.HasValue)
            {
                model.SortDirection = SortDirection.Desc;
            }

            model.InitSortInfo();

            if (string.IsNullOrWhiteSpace(model.SortBy))
            {
                model.SortBy = "LogDate";
            }
            if (model.TextSearch!=null||model.FromDate!=null||model.ToDate!=null)
            {
                var filter = new FindRequest
                {
                    Table = TableLog.Customer,
                    TextSearch = model.TextSearch,
                    FromDate = DateTimeHelper.ConvertToUtcNull(model.FromDate, CurrentUserTimeZoneId).ToStartDateTimeNull(),
                    ToDate = DateTimeHelper.ConvertToUtcNull(model.ToDate, CurrentUserTimeZoneId).ToEndDateTimeNull(),
                    SortOption = new SortOption(new[] { new SortItem(model.SortBy, model.SortDirection.Value) }),
                    PageOption = new PageOption { PageSize = model.Pagination.PageSize, PageNumber = model.Pagination.CurrentPageIndex }
                };

                var response = ServiceHelper.DataLog.ExecuteDispose(s => s.FindDataLogs(filter));
                model.Results = response.Results.MapList<DataLogModel>();
                model.Pagination.TotalRecords = response.TotalRecords;
                model.Pagination.ShowPaging = false;
                model.FilterVisible = true;
            }
            else
            {
                model.Results = new List<DataLogModel>();
                model.Pagination.TotalRecords = 0;
                model.Pagination.ShowPaging = false;
                model.FilterVisible = true;
            }

            return View(model);
        }
Beispiel #3
0
 public FindResponse FindDataLogs(FindRequest request)
 {
     return Execute(_repository, r => r.FindDataLogs(request));
 }