public async Task <IActionResult> Create(CreateWebsiteViewModel model) { if (!ModelState.IsValid) { return(View(model)); } var website = new Website { Domain = model.Domain, Description = model.Description, CreatedAt = model.CreatedAt, User = await GetCurrentUser() }; _context.Add(website); await _context.SaveChangesAsync(); if (User.IsInRole("Admin")) { return(RedirectToAction(nameof(Index))); } else { return(RedirectToAction(nameof(UserWebsites))); } }
public async Task <IActionResult> Index(CreateWebsiteViewModel websiteViewModel) { if (ModelState.IsValid) { WebsiteModel website = new WebsiteModel { Domain = websiteViewModel.Domain, AnalysisDate = DateTime.UtcNow }; await _websiteAnalyzer.AnalyzeAsync(website); if (website.Webpages == null) { ModelState.AddModelError("Domain", "Sitemap not found!"); return(View()); } website.Id = await _websiteService.CreateAsync(website); return(RedirectToAction("Details", "Website", new { websiteId = website.Id })); } return(View()); }
public IActionResult Create() { var viewModel = new CreateWebsiteViewModel(); return(View(viewModel)); }