Exemplo n.º 1
0
        public async Task <IActionResult> SeNames(DataSourceRequest command, UrlEntityListModel model)
        {
            bool?active = null;

            switch (model.SearchActiveId)
            {
            case 1:
                active = true;
                break;

            case 2:
                active = false;
                break;

            default:
                break;
            }
            var entityUrls = await _slugService.GetAllEntityUrl(model.SeName, active, command.Page - 1, command.PageSize);

            var items = new List <UrlEntityModel>();

            foreach (var x in entityUrls)
            {
                //language
                string languageName;
                if (String.IsNullOrEmpty(x.LanguageId))
                {
                    languageName = _translationService.GetResource("admin.configuration.senames.Language.Standard");
                }
                else
                {
                    var language = await _languageService.GetLanguageById(x.LanguageId);

                    languageName = language != null ? language.Name : "Unknown";
                }

                //details URL
                string detailsUrl = "";
                var    entityName = x.EntityName != null?x.EntityName.ToLowerInvariant() : "";

                switch (entityName)
                {
                case "brand":
                    detailsUrl = Url.Action("Edit", "Brand", new { id = x.EntityId, area = Constants.AreaAdmin });
                    break;

                case "blogpost":
                    detailsUrl = Url.Action("Edit", "Blog", new { id = x.EntityId, area = Constants.AreaAdmin });
                    break;

                case "category":
                    detailsUrl = Url.Action("Edit", "Category", new { id = x.EntityId, area = Constants.AreaAdmin });
                    break;

                case "collection":
                    detailsUrl = Url.Action("Edit", "Collection", new { id = x.EntityId, area = Constants.AreaAdmin });
                    break;

                case "product":
                    detailsUrl = Url.Action("Edit", "Product", new { id = x.EntityId, area = Constants.AreaAdmin });
                    break;

                case "newsitem":
                    detailsUrl = Url.Action("Edit", "News", new { id = x.EntityId, area = Constants.AreaAdmin });
                    break;

                case "page":
                    detailsUrl = Url.Action("Edit", "Page", new { id = x.EntityId, area = Constants.AreaAdmin });
                    break;

                case "vendor":
                    detailsUrl = Url.Action("Edit", "Vendor", new { id = x.EntityId, area = Constants.AreaAdmin });
                    break;

                case "course":
                    detailsUrl = Url.Action("Edit", "Course", new { id = x.EntityId, area = Constants.AreaAdmin });
                    break;

                case "knowledgebasecategory":
                    detailsUrl = Url.Action("EditCategory", "Knowledgebase", new { id = x.EntityId, area = Constants.AreaAdmin });
                    break;

                case "knowledgebasearticle":
                    detailsUrl = Url.Action("EditArticle", "Knowledgebase", new { id = x.EntityId, area = Constants.AreaAdmin });
                    break;

                default:
                    break;
                }

                items.Add(new UrlEntityModel {
                    Id         = x.Id,
                    Name       = x.Slug,
                    EntityId   = x.EntityId,
                    EntityName = x.EntityName,
                    IsActive   = x.IsActive,
                    Language   = languageName,
                    DetailsUrl = detailsUrl
                });
            }
            var gridModel = new DataSourceResult {
                Data  = items,
                Total = entityUrls.TotalCount
            };

            return(Json(gridModel));
        }