コード例 #1
0
        public ActionResult CreateDatabase() {
            var dc = new DataClassesDataContext(ConnectionString);
            if (dc.DatabaseExists()) {
                dc.DeleteDatabase();
            }
            try {
                dc.CreateDatabase();

                // Add the necessary row for the sample client.
                dc.Clients.InsertOnSubmit(new Client {
                    ClientIdentifier = "samplewebapiconsumer",
                    ClientSecret = "samplesecret",
                    Name = "Some sample client",
                });
                dc.Clients.InsertOnSubmit(new Client {
                    ClientIdentifier = "sampleImplicitConsumer",
                    Name = "Some sample client used for implicit grants (no secret)",
                    Callback = "http://localhost:59722/",
                });

                dc.SubmitChanges();

                // Force the user to log out because a new database warrants a new row in the users table, which we create
                // when the user logs in.
                FormsAuthentication.SignOut();
                ViewData["Success"] = true;
            }
            catch (SqlException ex) {
                ViewData["Error"] = string.Join("<br>", ex.Errors.OfType<SqlError>().Select(er => er.Message).ToArray());
            }

            return this.View("Database");
        }