Esempio n. 1
0
        public async Task <IActionResult> Edit(int id)
        {
            var response = await GetToApi(string.Concat("clients/", id));

            var client = JsonConvert.DeserializeObject <ClientDto>(await response.Content.ReadAsStringAsync());

            var model = new UpdateClientModel()
            {
                Id           = client.Id,
                Name         = client.Name,
                ClientSecret = client.ClientSecret,
                Description  = client.Description,
                PublicId     = client.PublicId,
                ReturnUrls   = client.ReturnUrls.Select(ru => ru.Value).ToList(),
                ClientType   = client.ClientType,
                Scopes       = new Dictionary <string, IList <ScopeClientModel> >()
            };

            // get all scopes
            var responseScopes = await GetToApi("scopes");

            if (!await model.ValidateAsync(response))
            {
                return(View(responseScopes));
            }

            IList <int> clientScopes = client.Scopes.Select(s => s.Id).ToList();

            var scopes = JsonConvert.DeserializeObject <SearchResult <ScopeDto> >(await responseScopes.Content.ReadAsStringAsync());

            if (scopes != null)
            {
                foreach (var s in scopes.Datas)
                {
                    if (!model.Scopes.ContainsKey(s.RessourceServerName))
                    {
                        model.Scopes.Add(s.RessourceServerName, new List <ScopeClientModel>());
                    }

                    model.Scopes[s.RessourceServerName].Add(new ScopeClientModel()
                    {
                        Id          = s.Id,
                        NiceWording = s.NiceWording,
                        Selected    = clientScopes.Contains(s.Id),
                        Wording     = s.Wording
                    });
                }
            }

            return(View(model));
        }
Esempio n. 2
0
        public async Task <IActionResult> Edit(UpdateClientModel model)
        {
            var response = await PutToApi("clients", new UpdateClientDto()
            {
                ClientType   = model.ClientType,
                ReturnUrls   = model.ReturnUrls.Where(ru => !String.IsNullOrWhiteSpace(ru)).ToList(),
                Description  = model.Description,
                Name         = model.Name,
                Id           = model.Id,
                ClientSecret = model.ClientSecret,
                PublicId     = model.PublicId,
                ScopesIds    = model.Scopes.SelectMany(s => s.Value)
                               .Where(sv => sv.Selected)
                               .Select(sv => sv.Id).ToList()
            });

            return(!await model.ValidateAsync(response) ? View(model) : (IActionResult)RedirectToAction("List"));
        }