Ejemplo n.º 1
0
        public async Task <IActionResult> Edit(EditDeploymentPlanViewModel model)
        {
            if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageDeploymentPlan))
            {
                return(Forbid());
            }

            var deploymentPlan = await _session.GetAsync <DeploymentPlan>(model.Id);

            if (deploymentPlan == null)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                if (String.IsNullOrWhiteSpace(model.Name))
                {
                    ModelState.AddModelError(nameof(EditDeploymentPlanViewModel.Name), S["The name is mandatory."]);
                }
                if (!String.Equals(model.Name, deploymentPlan.Name, StringComparison.OrdinalIgnoreCase))
                {
                    var count = await _session.QueryIndex <DeploymentPlanIndex>(x => x.Name == model.Name && x.DocumentId != model.Id).CountAsync();

                    if (count > 0)
                    {
                        ModelState.AddModelError(nameof(CreateDeploymentPlanViewModel.Name), S["A deployment plan with the same name already exists."]);
                    }
                }
            }

            if (ModelState.IsValid)
            {
                deploymentPlan.Name = model.Name;

                _session.Save(deploymentPlan);

                _notifier.Success(H["Deployment plan updated successfully"]);

                return(RedirectToAction(nameof(Index)));
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Edit(int id)
        {
            if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageDeploymentPlan))
            {
                return(Forbid());
            }

            var deploymentPlan = await _session.GetAsync <DeploymentPlan>(id);

            if (deploymentPlan == null)
            {
                return(NotFound());
            }

            var model = new EditDeploymentPlanViewModel
            {
                Id   = deploymentPlan.Id,
                Name = deploymentPlan.Name
            };

            return(View(model));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Edit(EditDeploymentPlanViewModel model)
        {
            if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageDeploymentPlan))
            {
                return(Forbid());
            }

            var deploymentPlan = await _session.GetAsync <DeploymentPlan>(model.Id);

            if (deploymentPlan == null)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                if (String.IsNullOrWhiteSpace(model.Name))
                {
                    ModelState.AddModelError(nameof(EditDeploymentPlanViewModel.Name), S["The name is mandatory."]);
                }
            }

            if (ModelState.IsValid)
            {
                deploymentPlan.Name = model.Name;

                _session.Save(deploymentPlan);

                _notifier.Success(H["Deployment plan updated successfully"]);

                return(RedirectToAction(nameof(Index)));
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }