public IActionResult Create([FromForm] CreateArticleViewModel viewModel) { string imageDirectory = Path.Combine(webHostEnvironment.WebRootPath, "ArticleImage"); try { if (ModelState.IsValid == false) { return(View(viewModel)); } if (authorService.DoesAuthorExist(viewModel.Email)) { tagService.AddMultipleTags(viewModel.ArticleTags); var tags = tagService.GetForArticleFromString(viewModel.ArticleTags); articleService.Add(viewModel.Title, viewModel.Content, viewModel.Email, viewModel.Image, imageDirectory, tags); return(RedirectToAction("Index")); } if (viewModel.DoesAuthorExist == true) { viewModel.DoesAuthorExist = false; return(View(viewModel)); } tagService.AddMultipleTags(viewModel.ArticleTags); var myTags = tagService.GetForArticleFromString(viewModel.ArticleTags); authorService.Add(viewModel.Email, viewModel.FirstName, viewModel.LastName); articleService.Add(viewModel.Title, viewModel.Content, viewModel.Email, viewModel.Image, imageDirectory, myTags); return(RedirectToAction("Index")); } catch (Exception e) { return(BadRequest(e.Message)); } }