Example #1
0
        public ViewResult Delete(AccessGroupEditModel editModel)
        {
            try
            {
                ModelState.Clear();
                RestoreSavedState(editModel);
                editModel.AddRolesToAccessGroup();
                var result = _accessGroupService.DeleteOneAccessGroup(editModel.AccessGroup);

                editModel.AvailableRoles = _roleService.GetAllRoles().Except(editModel.AccessGroup.RolesThatHaveAccess).ToList();

                if (result == StorageResult.Success)
                {
                    ViewData["Message"] = "Tilgangsgruppen er slettet";
                    return(View("Delete", editModel));
                }
                ViewData["Message"] = "Ukjent feil under sletting.";
                return(View("Delete", editModel));
            }
            catch
            {
                ViewData["Message"] = "Feil i underliggende tjenester under sletting.";
                return(View("Delete", editModel));
            }
        }
Example #2
0
        private ViewResult SaveAndReturnView(AccessGroupEditModel editModel, string context)
        {
            if (!ModelState.IsValid)
            {
                return(View(context, editModel));
            }
            try
            {
                editModel.AddRolesToAccessGroup();

                StorageResult result = context == "Create" ? _accessGroupService.SaveOneAccessGroup(editModel.AccessGroup) : _accessGroupService.UpdateOneAccessGroup(editModel.AccessGroup);

                editModel.AvailableRoles = _roleService.GetAllRoles().Except(editModel.RequestedRoles).ToList();

                switch (result)
                {
                case StorageResult.Success:
                    ViewData["Message"] = "Tilgangsgruppen er lagret";
                    break;

                case StorageResult.AllreadyExsists:
                    ViewData["Message"] = "Tilgangsgruppe med samme navn finnes fra før.";
                    break;

                case StorageResult.Failed:
                    ViewData["Message"] = "Ukjent feil under lagring.";
                    break;
                }
                return(View(context, editModel));
            }
            catch
            {
                ViewData["Message"] = "Feil i underliggende tjenester under lagring.";
                return(View(context, editModel));
            }
        }
Example #3
0
        public ViewResult Delete(AccessGroupEditModel editModel)
        {
            try
            {
                ModelState.Clear();
                RestoreSavedState(editModel);
                editModel.AddRolesToAccessGroup();
                var result = _accessGroupService.DeleteOneAccessGroup(editModel.AccessGroup);

                editModel.AvailableRoles = _roleService.GetAllRoles().Except(editModel.AccessGroup.RolesThatHaveAccess).ToList();

                if (result == StorageResult.Success)
                {
                    ViewData["Message"] = "Tilgangsgruppen er slettet";
                    return View("Delete", editModel);
                }
                ViewData["Message"] = "Ukjent feil under sletting.";
                return View("Delete", editModel);
            }
            catch
            {
                ViewData["Message"] = "Feil i underliggende tjenester under sletting.";
                return View("Delete", editModel);
            }
        }
Example #4
0
        private ViewResult SaveAndReturnView(AccessGroupEditModel editModel, string context)
        {
            if (!ModelState.IsValid)
                return View(context, editModel);
            try
            {
                editModel.AddRolesToAccessGroup();

                StorageResult result = context == "Create" ? _accessGroupService.SaveOneAccessGroup(editModel.AccessGroup) : _accessGroupService.UpdateOneAccessGroup(editModel.AccessGroup);

                editModel.AvailableRoles = _roleService.GetAllRoles().Except(editModel.RequestedRoles).ToList();

                switch (result)
                {
                    case StorageResult.Success:
                        ViewData["Message"] = "Tilgangsgruppen er lagret";
                        break;
                    case StorageResult.AllreadyExsists:
                        ViewData["Message"] = "Tilgangsgruppe med samme navn finnes fra før.";
                        break;
                    case StorageResult.Failed:
                        ViewData["Message"] = "Ukjent feil under lagring.";
                        break;
                }
                return View(context, editModel);
            }
            catch
            {
                ViewData["Message"] = "Feil i underliggende tjenester under lagring.";
                return View(context, editModel);
            }
        }