public async Task <IActionResult> Add(ClientAddViewModel viewModel) { if (ModelState.IsValid) { var record = new Client { ClientId = viewModel.ClientId, ClientName = viewModel.ClientName, Description = viewModel.Description, Enabled = true, Created = DateTime.UtcNow, }; await _dbContext.AddAsync(record).ConfigureAwait(false); var result = await _dbContext.SaveChangesAsync().ConfigureAwait(false); if (result > 0) { return(RedirectToAction(nameof(Index))); } ModelState.AddModelError("", "Failed"); } return(View(viewModel)); }
public async Task <IActionResult> Add(ApiScopeAddViewModel viewModel) { if (ModelState.IsValid) { var record = _mapper.Map <ApiScope>(viewModel); record.Enabled = true; await _dbContext.AddAsync(record).ConfigureAwait(false); var result = await _dbContext.SaveChangesAsync().ConfigureAwait(false); if (result > 0) { return(RedirectToAction(nameof(Index))); } ModelState.AddModelError("", "Failed"); } return(View(viewModel)); }
public async Task <IActionResult> Add(ApiResourceAddViewModel viewModel) { if (ModelState.IsValid) { var record = _mapper.Map <ApiResource>(viewModel); record.Enabled = true; record.ShowInDiscoveryDocument = true; record.Created = DateTime.UtcNow; await _dbContext.AddAsync(record).ConfigureAwait(false); var result = await _dbContext.SaveChangesAsync().ConfigureAwait(false); if (result > 0) { return(RedirectToAction(nameof(Index))); } ModelState.AddModelError("", "Failed"); } return(View(viewModel)); }