Пример #1
0
        public virtual ActionResult Changes(string entityName, TableInfo tableInfo)
        {
            var entityChangesFor = AdminInitialise.EntitiesTypes
                                   .FirstOrDefault(x => x.Name == entityName);

            if (entityChangesFor == null)
            {
                throw new NoNullAllowedException("entity is null");
            }
            var changeEntity = AdminInitialise.ChangeEntity;
            var filters      = PrepareFilters(changeEntity);
            var pagedRecords = _entitiesSource.GetChangesRecords(
                entityChangesFor,
                tableInfo.Page,
                tableInfo.PerPage,
                filters,
                tableInfo.SearchQuery,
                tableInfo.Order,
                tableInfo.OrderDirection);

            if (pagedRecords.Records.IsNullOrEmpty() && tableInfo.Page > 1)
            {
                return(RedirectToAction(
                           "Changes",
                           PrepareRouteValues(
                               entityName,
                               "1",
                               filters,
                               tableInfo)));
            }

            var url = Url.Action(
                "Changes",
                PrepareRouteValues(
                    entityName,
                    "-page-",
                    filters,
                    tableInfo))
                      .Replace("-page-", "{0}");
            var model = new EntitiesChangesModel
            {
                Data    = pagedRecords.Records,
                Columns = changeEntity.DisplayProperties
                          .Select(x => new Column(x, tableInfo.Order, tableInfo.OrderDirection)).ToList(),
                Entity           = changeEntity,
                EntityChangesFor = entityChangesFor,
                Pager            =
                    new PagerInfo(url, tableInfo.PerPage, tableInfo.Page, pagedRecords.TotalItems),
                Filters       = filters,
                TableInfo     = tableInfo,
                Configuration = _configuration
            };

            return(View(model));
        }
Пример #2
0
        public virtual ActionResult Changes(string entityName, string key, TableInfo tableInfo)
        {
            var entityChangesFor = _admin.GetEntity(entityName);
            var pagedRecords     = _recordsService
                                   .GetChanges(entityChangesFor, key, Request.QueryString, tableInfo);

            if (pagedRecords.Records.IsNullOrEmpty() && tableInfo.Page > 1)
            {
                return(Redirect(Url.PageUrl(1)));
            }

            var model = new EntitiesChangesModel(
                _admin.ChangeEntity,
                pagedRecords,
                tableInfo)
            {
                EntityChangesFor = entityChangesFor,
                Key           = key,
                Configuration = _configuration,
                ChangeEnabled = _admin.ChangeEntity != null
            };

            return(View(model));
        }
Пример #3
0
        public virtual ActionResult Changes(string entityName, string key, TableInfo tableInfo)
        {
            var entityChangesFor = Admin.EntitiesTypes
                                   .FirstOrDefault(x => x.Name == entityName);

            if (entityChangesFor == null)
            {
                throw new NoNullAllowedException("entity is null");
            }
            var changeEntity = Admin.ChangeEntity;

            changeEntity.Fill(Request);
            var filters = _filterFactory.BuildFilters(Admin.ChangeEntity).ToList();

            if (key.IsNullOrWhiteSpace() == false)
            {
                filters.Add(new ForeignEntityFilter(changeEntity["EntityKey"], key));
            }
            filters.Add(new ChangeEntityFilter(changeEntity["EntityName"], entityName));
            var pagedRecords = _entitiesSource.GetRecords(
                changeEntity,
                filters,
                tableInfo.SearchQuery,
                tableInfo.Order,
                tableInfo.OrderDirection,
                false,
                tableInfo.Page,
                tableInfo.PerPage);

            if (pagedRecords.Records.IsNullOrEmpty() && tableInfo.Page > 1)
            {
                return(RedirectToAction(
                           "Changes",
                           PrepareRouteValues(
                               entityName,
                               "1",
                               filters,
                               tableInfo)));
            }

            var url = Url.Action(
                "Changes",
                PrepareRouteValues(
                    entityName,
                    "-page-",
                    filters,
                    tableInfo))
                      .Replace("-page-", "{0}");
            var model = new EntitiesChangesModel
            {
                Data    = pagedRecords.Records,
                Columns = changeEntity.DisplayProperties
                          .Select(x => new Column(x, tableInfo.Order, tableInfo.OrderDirection)).ToList(),
                Entity           = changeEntity,
                EntityChangesFor = entityChangesFor,
                Pager            =
                    new PagerInfo(url, tableInfo.PerPage, tableInfo.Page, pagedRecords.TotalItems),
                Filters       = filters.Where(x => x.DisplayInUI).ToList(),
                TableInfo     = tableInfo,
                Configuration = _configuration,
                Key           = key
            };

            return(View(model));
        }