Esempio n. 1
0
        public static void Register(HttpConfiguration config)
        {
            // Web API configuration and services

            // Web API routes
            config.MapHttpAttributeRoutes();

            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
                );

            CategoryHelper Categories = new CategoryHelper();
            AdminHelper    Admins     = new AdminHelper();
            PostHelper     Posts      = new PostHelper();

            if (Admins.GetAll().Count() == 0)
            {
                string Hash(string str)
                {
                    // Create a SHA256
                    using (SHA256 sha256Hash = SHA256.Create())
                    {
                        // ComputeHash - returns byte array
                        byte[] bytes = sha256Hash.ComputeHash(Encoding.UTF8.GetBytes(str));

                        // Convert byte array to a string
                        StringBuilder builder = new StringBuilder();
                        for (int i = 0; i < bytes.Length; i++)
                        {
                            builder.Append(bytes[i].ToString("x2"));
                        }
                        return(builder.ToString());
                    }
                }

                Admin admin = new Admin()
                {
                    DateJoined = DateTime.Now,
                    Email      = "*****@*****.**",
                    FullName   = "Default Admin",
                    Password   = Hash("admin123")
                };

                Admins.Create(admin);
            }
        }