Exemple #1
0
        // GET: Articles/Create
        public IActionResult Create()
        {
            var article     = new CreateOrUpdateArticleViewDto();
            var categoryIds = _articleCategoryService.GetAllCategoryNameValue().Result;

            ViewData["CategoryIds"] = new MultiSelectList(categoryIds, "Value", "Name");
            return(View(article));
        }
Exemple #2
0
        public async Task <IActionResult> Create(CreateOrUpdateArticleViewDto article)
        {
            if (ModelState.IsValid)
            {
                await _articleCategoryService.CreateOrEditArticleAsync(Mapper.Map <CreateOrUpdateArticleDto>(article));


                return(RedirectToAction(nameof(Index)));
            }

            return(View(article));
        }
Exemple #3
0
        public async Task <IActionResult> Edit(CreateOrUpdateArticleViewDto article)
        {
            if (ModelState.IsValid)
            {
                await _articleCategoryService.CreateOrEditArticleAsync(Mapper.Map <CreateOrUpdateArticleDto>(article));

                return(RedirectToAction(nameof(Index)));
            }
            var categoryIds = await _articleCategoryService.GetAllCategoryNameValue();

            ViewData["Categorys"] = new MultiSelectList(categoryIds, "Value", "Name", article.CatetoryIds != null? categoryIds.Where(c => article.CatetoryIds.Contains(c.Value)).ToList():null);
            return(View(article));
        }