public async Task <IActionResult> Create([Bind("Country,Id,UserName,NormalizedUserName,Email,NormalizedEmail,EmailConfirmed,PasswordHash,SecurityStamp,ConcurrencyStamp,PhoneNumber,PhoneNumberConfirmed,TwoFactorEnabled,LockoutEnd,LockoutEnabled,AccessFailedCount")] User user) { if (ModelState.IsValid) { _context.Add(user); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(user)); }
public async Task <IActionResult> Create([Bind("ID,Name,Country")] DataCenter dataCenter) { if (ModelState.IsValid) { _context.Add(dataCenter); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(dataCenter)); }
public async Task <IActionResult> Create([Bind("CPU,RAM,UserID,OS,DataCenterID")] Server server) { string username = User.Identity.Name; if (string.IsNullOrEmpty(username)) { return(View("_NotLoggedIn")); } if (server.OS == OS.Linux) { increaseLinuxCount(); } string currentUserName = User.Identity.Name; if (currentUserName == null) { return(View("_NotLoggedIn")); } var user = await _context.Users .FirstOrDefaultAsync(u => u.UserName == currentUserName); server.UserID = user.Id; if (ModelState.IsValid) { try { _context.Add(server); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } catch (DbUpdateException) { ModelState.AddModelError("", "Unable to save changes. " + "Try again, and if the problem persists " + "see your system administrator."); } } ViewData["DCName"] = new SelectList(_context.DataCenter, "ID", "Name", server.DataCenterID); ViewData["UserID"] = new SelectList(_context.Users, "Id", "Id", server.UserID); return(View(server)); }