Example #1
0
        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)));
            }
        }
Example #2
0
        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());
        }
Example #3
0
        public IActionResult Create()
        {
            var viewModel = new CreateWebsiteViewModel();

            return(View(viewModel));
        }