Exemplo n.º 1
0
        /// <summary>
        /// Build <see cref="PostCreateViewModel"/> based on PostType.
        /// </summary>
        /// <param name="postType">PostType to load base data for Post.</param>
        /// <returns>A <see cref="PostCreateViewModel"/> populated with base data.</returns>
        public async Task <PostCreateViewModel> BuildCreateViewModelAsync(
            string postType
            )
        {
            var postTypeRes = await _postTypeService.GetBySlugAsync(postType);

            if (postTypeRes == null)
            {
                throw new NullReferenceException(nameof(PostType));
            }

            var model = new PostCreateViewModel {
                Status = PostStatus.Draft,
                //PostTypeTitle = postTypeRes.Title,
                PostTypeSlug     = postTypeRes.Slug,
                PostTypeId       = postTypeRes.Id,
                PublishDateModel = new PersianDateViewModel()
            };

            await setBaseDataAsync(model);

            model.CategorySelectList = await _categoryProvider
                                       .GetSelectListAsync(postTypeRes.Id, model.LangId);

            return(await Task.FromResult(model));
        }
Exemplo n.º 2
0
        public async Task <CategoryCreateViewModel> BuildCreateViewModelAsync(
            string postType,
            int?parentId
            )
        {
            var postTypeRes = await _postTypeService.GetBySlugAsync(postType);

            if (postTypeRes == null)
            {
                throw new NullReferenceException(nameof(PostType));
            }

            var model = new CategoryCreateViewModel {
                LanguageSelectList = await _languageViewModelProvider.GetSelectListAsync(),
                Status             = EntityStatus.Enabled,
                PostTypeId         = postTypeRes.Id,
                PostTypeTitle      = postTypeRes.Title
            };

            if (parentId.HasValue)
            {
                var parent = await _categoryService.FindAsync(parentId.Value);

                model.ParentTitle = parent.Title;
            }
            else
            {
                model.ParentTitle = "[ریشه]";
            }

            return(model);
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Index(string postType = "page")
        {
            var _postType = await _postTypeService.GetBySlugAsync(postType);

            var model = new CategoryAdminViewModel {
                PostTypeId = _postType.Id
            };

            var result = await _categoryService.GetGridDataAsync(
                _postType.Id, new CategoryGridOptions {
                PageSize   = 10,
                StartIndex = 0
            });

            var langs = await _languageService.GetAllAsync();

            model.Languages = langs.Select(_ => _.Adapt <LanguageItemViewModel>());

            model.Items = result.Items
                          .Select(_ => _.Adapt <CategoryListItemViewModel>());

            return(View(model));
        }