示例#1
0
        public ActionResult Edit(int id)
        {
            var result = m_clientManager.FindClientById(id);

            if (result.HasError)
            {
                ModelState.AddModelError(result.Error.Message);
                return(View());
            }

            var clientViewModel = Mapper.Map <ClientViewModel>(result.Result);

            var viewModel = ViewModelBuilder.BuildEditableClientViewModel(ModelState, clientViewModel);

            return(View(viewModel));
        }
示例#2
0
        public ActionResult Edit(int id, EditableClientViewModel clientViewModel)
        {
            if (ModelState.IsValid)
            {
                var selectedIdentityResources = GetSelectedItems(clientViewModel.SelectableIdentityresources);
                var selectedGrantTypes        = GetSelectedItems(clientViewModel.SelectableGrantTypes);
                var selectedScopes            = GetSelectedItems(clientViewModel.SelectableScopes);

                var identityResourcesIds = selectedIdentityResources?.Select(x => x.Id);
                var grantTypesIds        = selectedGrantTypes.Select(x => x.Id);
                var scopesIds            = selectedScopes.Select(x => x.Id);

                try
                {
                    Client.ValidateGrantTypes(selectedGrantTypes.Select(x => x.Value));

                    var clientModel = Mapper.Map <ClientModel>(clientViewModel);

                    var result = m_clientManager.UpdateClient(id, clientModel, identityResourcesIds, grantTypesIds, scopesIds);

                    if (!result.HasError)
                    {
                        return(RedirectToAction(nameof(View), new { id }));
                    }

                    ModelState.AddModelError(result.Error.Message);
                }
                catch (InvalidOperationException e)
                {
                    //TODO log warning here
                    ModelState.AddModelError(e.Message); //HACK wrtie custom message
                }
            }

            clientViewModel.Id = id;

            var viewModel = ViewModelBuilder.BuildEditableClientViewModel(ModelState, clientViewModel);

            return(View(viewModel));
        }
示例#3
0
        public ActionResult Create()
        {
            var viewModel = ViewModelBuilder.BuildEditableClientViewModel(ModelState);

            return(View(viewModel));
        }