public async Task <IActionResult> Create([Bind("Id,User,Groups")] AdminModel adminModel) { if (ModelState.IsValid) { _context.Add(adminModel); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(adminModel)); }
public async Task <IActionResult> Create([Bind("Id,Title,Created,Modified,Active,UrlHash,User,Address,ShortAddress")] UrlViewModel urlViewModel) { if (ModelState.IsValid) { urlViewModel.Modified = DateTime.UtcNow; _context.Add(urlViewModel); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(urlViewModel)); }
public async Task <IActionResult> Create([Bind("Id,Source,Url")] WhiteListModel whiteListModel) { if (ModelState.IsValid) { whiteListModel.Modified = DateTime.UtcNow; _context.Add(whiteListModel); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(whiteListModel)); }
public ActionResult Edit(UrlViewModel uv) { try { //use non-standard port for debugging var debugPort = _config["debugport:port"]; List <string> wList = _context.WhiteListModel .Select(w => w.Url.ToString()).ToList(); foreach (var address in wList) { if (uv.Address.Contains(address)) { return(RedirectToAction("Index", "Home", new { wlist = true })); } } //perhaps index the records via URL hash for quick lookup in db if (!_context.UrlViewModels.Any(e => e.UrlHash == uv.UrlHash)) { if (User.Identity.IsAuthenticated && User.Identity.Name != null) { uv.User = User.Identity.Name; } else { uv.User = "******"; } uv.Title = uv.Title; //active is for disabling these if insecure.. uv.Active = true; uv.Modified = DateTime.Now; var urlBase = !String.IsNullOrEmpty(debugPort) ? "https://localhost:" + debugPort + "/" : "https://localhost/"; //Full URL is just there for display but we only want the code in DB uv.ShortAddress = uv.ShortAddress.Replace(urlBase, ""); _context.Add(uv); _context.SaveChanges(); } else { return(RedirectToAction("Index", "Home", new { duplicate = true })); } return(RedirectToAction("Index", "Home", new { success = true, redir = uv.ShortAddress })); } catch (Exception ex) { //Console.WriteLine(ex.ToString()); return(RedirectToAction("Index", "Home")); } }