예제 #1
0
        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));
        }
예제 #2
0
        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));
        }
예제 #3
0
        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));
        }