Ejemplo n.º 1
0
        public async Task <IActionResult> Add(ArticleView result)
        {
            //if (await _articleService.CheckIfSlugExist(result.Slug))
            //{
            //    ModelState.AddModelError("", "Artykuł z tym linkiem już istnieje!");
            //}

            //if (!ModelState.IsValid)
            //{
            //    ViewBag.Categories = await _categoryService.GetAll();
            //    ViewBag.Tags = await _tagService.GetAll();

            //    return View(result);
            //}

            var user = await _userManager.GetUserAsync(User);

            var articleModel = ArticleHelpers.ConvertToModel(result, user, "https://theraphosidae.pl");
            var article      = await _articleService.Create(articleModel);

            if (article == false)
            {
                return(RedirectToAction("Index", "Dashboard"));
            }

            var photo = await _cloudinaryService.AddFile(result.FeaturedImg, articleModel);

            //await _taxonomyService.SaveCategories(await _categoryService.GetCategoriesByName(result.Categories), articleModel);
            //await _taxonomyService.SaveTags(await _tagService.GetCategoriesByNames(result.Tags), articleModel);

            return(RedirectToAction("List"));
        }