示例#1
0
        public ClientIndexViewModel PostClient(SandboxClientCreateModel sandboxClient)
        {
            if (ModelState["client.Name"] == null)
            {
                try
                {
                    var profile = _repository.GetUser(UserProfile.Email);

                    var newClient = _clientCreator.CreateNewSandboxClient(
                        new SandboxInitializationModel
                    {
                        Name = sandboxClient.Name, SandboxType = sandboxClient.SandboxType
                    },
                        profile);

                    AddClientStatusInfo(newClient);
                    return(ToClientIndexViewModel(newClient));
                }
                catch (ArgumentOutOfRangeException)
                {
                    throw new HttpResponseException(HttpStatusCode.BadRequest);
                }
            }

            throw new HttpResponseException(HttpStatusCode.NotAcceptable);
        }
        public async Task <IActionResult> PostClient([FromBody] SandboxClientCreateModel sandboxClient)
        {
            if (ModelState["client.Name"] == null)
            {
                try
                {
                    var profile = _repository.GetUser(UserProfile.Email);

                    var newClient = _clientCreator.CreateNewSandboxClient(
                        sandboxClient.Name,
                        new SandboxOptions
                    {
                        Type = sandboxClient.SandboxType
                    },
                        profile);

                    await AddClientStatusInfo(newClient);

                    return(Ok(ToClientIndexViewModel(newClient)));
                }
                catch (ArgumentOutOfRangeException)
                {
                    return(BadRequest(ModelState));
                }
            }

            return(StatusCode((int)HttpStatusCode.NotAcceptable));
        }