コード例 #1
0
        public async Task <IActionResult> Create([Bind("Id,Name,Value,Active,EnvironmentId")] VariableViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                var environment = await _context.ExecutionEnvironments.FindAsync(viewModel.EnvironmentId);

                var entity = new ExecutionVariable
                {
                    Name        = viewModel.Name,
                    Active      = viewModel.Active,
                    Environment = environment,
                    Value       = viewModel.Value
                };
                _context.Add(entity);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(viewModel));
        }
コード例 #2
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Name,Value,Active,EnvironmentId")] VariableViewModel viewModel)
        {
            if (id != viewModel.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    var environment = await _context.ExecutionEnvironments.FindAsync(viewModel.EnvironmentId);

                    var entity = new ExecutionVariable
                    {
                        Id          = viewModel.Id,
                        Name        = viewModel.Name,
                        Active      = viewModel.Active,
                        Environment = environment,
                        Value       = viewModel.Value
                    };
                    _context.Update(entity);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ExecutionVariableExists(viewModel.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(viewModel));
        }