public ActionResult Create(AccountViewModel accountViewModel) { try { if (ModelState.IsValid) { // Check if the username exists IEnumerable <Account> accounts = _accountRepo.GetAccountsByUsername(accountViewModel.Username); if (accounts.Count() == 0) { var newAccount = new Account { Username = accountViewModel.Username, Passphrase = accountViewModel.Passphrase, FirstName = accountViewModel.FirstName, LastName = accountViewModel.LastName }; _accountRepo.AddAccount(newAccount); _accountRepo.Save(); return(RedirectToAction(nameof(SignIn))); } else { return(RedirectToAction(nameof(InvalidUsername))); } } return(View(accountViewModel)); } catch { return(View()); } }
public IActionResult PostAccount(Account account) { if (AccountExists(account.Id)) { _logger.LogWarning($"Account with id: {account.Id} already exists."); return(Conflict()); } _accountRepo.AddAccount(account); _accountRepo.SaveChanges(); _logger.LogInformation($"Account with id: {account.Id} has been added."); return(CreatedAtAction(nameof(GetAccount), new { id = account.Id }, account)); }
public async Task AddAccount(Int64 steamid) { Regex r = new Regex("^[0-9]{17}$"); if (!r.Match(steamid.ToString()).Success) { await ReplyAsync("Invalid SteamId64. Please enter a valid one (e.g. 76561198029915406)"); return; } Account acc = new Account() { SteamId = steamid.ToString(), TimeOfReport = DateTime.Now, VACBanned = false, ServerId = Context.Guild.Id, ChannelId = Context.Channel.Id, MessageId = Context.Message.Id }; try { bool exist = _steamRepo.validateAccount(acc); if (exist) { _accRepo.AddAccount(acc); string message = "User is now being tracked. \nUpdating tracked users..."; await ReplyAsync(message); await UpdateVACStatus(); } } catch (Exception e) { await ReplyAsync($"Error: {e.Message}"); return; } }