Exemplo n.º 1
0
        public async Task <IActionResult> ResourceGroups(AddNewResourceGroupBindingModel bindingModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState.Values.SelectMany(v => v.Errors).Select(error => error.ErrorMessage)));
            }

            await this.ResGroupService.AddNewResourceGroup(bindingModel);

            return(RedirectToAction(nameof(this.ResourceGroups)));
        }
        public async Task <bool> AddNewResourceGroup(AddNewResourceGroupBindingModel bindingModel)
        {
            var resGroup = new ResourceGroup();

            resGroup.Name = bindingModel.Name;

            if (this.GetResourceGroups().Contains(resGroup.Name))
            {
                return(false);
            }

            this.dbContext.ResourceGroups.Add(resGroup);
            var result = await this.dbContext.SaveChangesAsync();

            return(result > 0);
        }