public ListModel <CategoryModel> List(FilterModel filterModel) { var model = filterModel.CreateMapped <FilterModel, ListModel <CategoryModel> >(); return(List(filterModel.StartDate, filterModel.EndDate, filterModel.PageNumber, filterModel.PageSize, filterModel.Status, filterModel.Searched, Guid.Empty, model)); }
public ListModel <ParameterGroupModel> List(FilterModel filterModel) { var startDate = filterModel.StartDate.ResetTimeToStartOfDay(); var endDate = filterModel.EndDate.ResetTimeToEndOfDay(); Expression <Func <ParameterGroup, bool> > expression; if (filterModel.Status != -1) { var status = filterModel.Status.ToString().ToBoolean(); if (filterModel.Searched != null) { if (status) { expression = c => c.IsApproved && c.Name.Contains(filterModel.Searched); } else { expression = c => c.IsApproved == false && c.Name.Contains(filterModel.Searched); } } else { if (status) { expression = c => c.IsApproved; } else { expression = c => c.IsApproved == false; } } } else { if (filterModel.Searched != null) { expression = c => c.Name.Contains(filterModel.Searched); } else { expression = c => c.Id != Guid.Empty; } } expression = expression.And(e => e.CreationTime >= startDate && e.CreationTime <= endDate); var model = filterModel.CreateMapped <FilterModel, ListModel <ParameterGroupModel> >(); if (model.Paging == null) { model.Paging = new Paging { PageSize = filterModel.PageSize, PageNumber = filterModel.PageNumber }; } var sortHelper = new SortHelper <ParameterGroupModel>(); var query = _repositoryParameterGroup .Join(x => x.Creator.Person) .Join(x => x.LastModifier.Person) .Where(expression); sortHelper.OrderBy(x => x.DisplayOrder); model.Paging.TotalItemCount = query.Count(); var items = model.Paging.PageSize > 0 ? query.Skip((model.Paging.PageNumber - 1) * model.Paging.PageSize).Take(model.Paging.PageSize) : query; var modelItems = new HashSet <ParameterGroupModel>(); foreach (var item in items) { var modelItem = item.CreateMapped <ParameterGroup, ParameterGroupModel>(); modelItem.Creator = new IdCodeName(item.Creator.Id, item.Creator.Username, item.Creator.Person.DisplayName); modelItem.LastModifier = new IdCodeName(item.LastModifier.Id, item.LastModifier.Username, item.LastModifier.Person.DisplayName); modelItems.Add(modelItem); } model.Items = modelItems.ToList(); var pageSizeDescription = _serviceMain.ApplicationSettings.PageSizeList; var pageSizes = pageSizeDescription.Split(',').Select(s => new KeyValuePair <int, string>(s.ToInt(), s)).ToList(); pageSizes.Insert(0, new KeyValuePair <int, string>(-1, "[" + Dictionary.All + "]")); model.Paging.PageSizes = pageSizes; model.Paging.PageCount = (int)Math.Ceiling((float)model.Paging.TotalItemCount / model.Paging.PageSize); if (model.Paging.TotalItemCount > model.Items.Count) { model.Paging.HasNextPage = true; } // ilk sayfa ise if (model.Paging.PageNumber == 1) { if (model.Paging.TotalItemCount > 0) { model.Paging.IsFirstPage = true; } // tek sayfa ise if (model.Paging.PageCount == 1) { model.Paging.IsLastPage = true; } } // son sayfa ise else if (model.Paging.PageNumber == model.Paging.PageCount) { model.Paging.HasNextPage = false; // tek sayfa değilse if (model.Paging.PageCount > 1) { model.Paging.IsLastPage = true; model.Paging.HasPreviousPage = true; } } // ara sayfa ise else { model.Paging.HasNextPage = true; model.Paging.HasPreviousPage = true; } if (model.Paging.TotalItemCount > model.Items.Count && model.Items.Count <= 0) { model.Message = Messages.DangerRecordNotFoundInPage; } if (model.Paging.TotalItemCount == 0) { model.Message = Messages.DangerRecordNotFound; } return(model); }
public ListModel <LanguageModel> List(FilterModel filterModel) { var startDate = filterModel.StartDate.ResetTimeToStartOfDay(); var endDate = filterModel.EndDate.ResetTimeToEndOfDay(); Expression <Func <Language, bool> > expression; if (filterModel.Status != -1) { var status = filterModel.Status.ToString().ToBoolean(); if (filterModel.Searched != null) { if (status) { expression = c => c.IsApproved && c.Name.Contains(filterModel.Searched); } else { expression = c => c.IsApproved == false && c.Name.Contains(filterModel.Searched); } } else { if (status) { expression = c => c.IsApproved; } else { expression = c => c.IsApproved == false; } } } else { if (filterModel.Searched != null) { expression = c => c.Name.Contains(filterModel.Searched); } else { expression = c => c.Id != Guid.Empty; } } expression = expression.And(e => e.CreationTime >= startDate && e.CreationTime <= endDate); var listModel = filterModel.CreateMapped <FilterModel, ListModel <LanguageModel> >(); listModel.Paging ??= new Paging { PageSize = filterModel.PageSize, PageNumber = filterModel.PageNumber }; var sortHelper = new SortHelper <Language>(); sortHelper.OrderBy(x => x.DisplayOrder); var query = (IOrderedQueryable <Language>)_repositoryLanguage .Get().Where(expression); query = sortHelper.GenerateOrderedQuery(query); listModel.Paging.TotalItemCount = query.Count(); var items = listModel.Paging.PageSize > 0 ? query.Skip((listModel.Paging.PageNumber - 1) * listModel.Paging.PageSize).Take(listModel.Paging.PageSize) : query; var modelItems = new HashSet <LanguageModel>(); foreach (var item in items) { var modelItem = item.CreateMapped <Language, LanguageModel>(); modelItems.Add(modelItem); } listModel.Items = modelItems.ToList(); var pageSizeDescription = _serviceMain.ApplicationSettings.PageSizeList; var pageSizes = pageSizeDescription.Split(',').Select(s => new KeyValuePair <int, string>(s.ToInt(), s)).ToList(); pageSizes.Insert(0, new KeyValuePair <int, string>(-1, "[" + Dictionary.All + "]")); listModel.Paging.PageSizes = pageSizes; listModel.Paging.PageCount = (int)Math.Ceiling((float)listModel.Paging.TotalItemCount / listModel.Paging.PageSize); if (listModel.Paging.TotalItemCount > listModel.Items.Count) { listModel.Paging.HasNextPage = true; } if (listModel.Paging.PageNumber == 1) { if (listModel.Paging.TotalItemCount > 0) { listModel.Paging.IsFirstPage = true; } if (listModel.Paging.PageCount == 1) { listModel.Paging.IsLastPage = true; } } else if (listModel.Paging.PageNumber == listModel.Paging.PageCount) { listModel.Paging.HasNextPage = false; if (listModel.Paging.PageCount > 1) { listModel.Paging.IsLastPage = true; listModel.Paging.HasPreviousPage = true; } } else { listModel.Paging.HasNextPage = true; listModel.Paging.HasPreviousPage = true; } if (listModel.Paging.TotalItemCount > listModel.Items.Count && listModel.Items.Count <= 0) { listModel.Message = Messages.DangerRecordNotFoundInPage; } if (listModel.Paging.TotalItemCount == 0) { listModel.Message = Messages.DangerRecordNotFound; } return(listModel); }