Esempio n. 1
0
        public HttpResponseMessage update_template(CustomThemeTemplate post)
        {
            // Check for errors
            if (post == null)
            {
                return(Request.CreateResponse <string>(HttpStatusCode.BadRequest, "The post is null"));
            }

            // Make sure that the data is valid
            post.user_file_name  = AnnytabDataValidation.TruncateString(post.user_file_name, 200);
            post.master_file_url = AnnytabDataValidation.TruncateString(post.master_file_url, 100);
            post.comment         = AnnytabDataValidation.TruncateString(post.comment, 200);

            // Get the saved post
            CustomThemeTemplate savedPost = CustomThemeTemplate.GetOneById(post.custom_theme_id, post.user_file_name);

            // Check if the post exists
            if (savedPost == null)
            {
                return(Request.CreateResponse <string>(HttpStatusCode.BadRequest, "The record does not exist"));
            }

            // Update the post
            CustomTheme.UpdateTemplate(post);

            // Return the success response
            return(Request.CreateResponse <string>(HttpStatusCode.OK, "The update was successful"));
        } // End of the update_template method
Esempio n. 2
0
        public CustomThemeTemplate get_template_by_id(Int32 id = 0, string userFileName = "")
        {
            // Create the post to return
            CustomThemeTemplate post = CustomThemeTemplate.GetOneById(id, userFileName);

            // Return the post
            return(post);
        } // End of the get_template_by_id method
Esempio n. 3
0
        public List <CustomThemeTemplate> get_templates_by_theme_id(Int32 id = 0, string sortField = "", string sortOrder = "")
        {
            // Create the list to return
            List <CustomThemeTemplate> posts = CustomThemeTemplate.GetAllPostsByCustomThemeId(id, sortField, sortOrder);

            // Return the list
            return(posts);
        } // End of the get_templates_by_theme_id method
Esempio n. 4
0
        public List <CustomThemeTemplate> get_all_templates(string sortField = "", string sortOrder = "")
        {
            // Create the list to return
            List <CustomThemeTemplate> posts = CustomThemeTemplate.GetAllPosts(sortField, sortOrder);

            // Return the list
            return(posts);
        } // End of the get_all_templates method
Esempio n. 5
0
    } // End of the Update method

    /// <summary>
    /// Update a custom theme template
    /// </summary>
    /// <param name="template">A reference to a custom theme template</param>
    public static void UpdateTemplate(CustomThemeTemplate template)
    {
        // Update the the template
        CustomThemeTemplate.Update(template);

        // Remove the cache
        RemoveThemeCache(template.custom_theme_id);

    } // End of the UpdateTemplate method
Esempio n. 6
0
    } // End of the GetBySearch method

    /// <summary>
    /// Get all the custom theme templates by custom theme id
    /// </summary>
    /// <param name="customThemeId">The custom theme id</param>
    /// <returns>A dictionary with custom theme templates</returns>
    public static Dictionary<string, string> GetAllTemplatesById(Int32 customThemeId)
    {
        // Get the templates from cache
        Dictionary<string, string> templates = CustomThemeTemplate.GetAllByCustomThemeId(customThemeId, "user_file_name", "ASC");

        // Return the templates
        return templates;

    } // End of the GetAllTemplatesById method
Esempio n. 7
0
    } // End of the DeleteTemplatesOnId method

    /// <summary>
    /// Delete a template on id
    /// </summary>
    /// <param name="customThemeId">The custom theme id</param>
    /// <param name="userFileName">The file name</param>
    public static void DeleteTemplateOnId(Int32 customThemeId, string userFileName)
    {
        // Delete the template
        CustomThemeTemplate.DeleteOnId(customThemeId, userFileName);

        // Remove the theme cache
        RemoveThemeCache(customThemeId);

    } // End of the DeleteTemplateOnId method
Esempio n. 8
0
    } // End of the AddCustomThemeTemplates method

    /// <summary>
    /// Add a template
    /// </summary>
    /// <param name="template">A reference to a template</param>
    public static void AddTemplate(CustomThemeTemplate template)
    {
        // Add the template
        CustomThemeTemplate.Add(template);

        // Remove the cache
        RemoveThemeCache(template.custom_theme_id);

    } // End of the AddTemplate method
Esempio n. 9
0
    } // End of the DeleteOnId method

    /// <summary>
    /// Delete all the templates for a custom theme id
    /// </summary>
    /// <param name="customThemeId"></param>
    public static void DeleteTemplatesOnId(Int32 customThemeId)
    {
        // Delete templates
        CustomThemeTemplate.DeleteOnId(customThemeId);

        // Remove the cache
        RemoveThemeCache(customThemeId);

    } // End of the DeleteTemplatesOnId method
Esempio n. 10
0
    } // End of the Update method

    #endregion

    #region Get methods

    /// <summary>
    /// Get one post by id
    /// </summary>
    /// <param name="customThemeId">The id</param>
    /// <param name="userFileName">The user file name</param>
    /// <returns>A reference to a custom theme template</returns>
    public static CustomThemeTemplate GetOneById(Int32 customThemeId, string userFileName)
    {
        // Create the post to return
        CustomThemeTemplate post = null;

        // Create the connection and the sql statement
        string connection = Tools.GetConnectionString();
        string sql = "SELECT * FROM dbo.custom_themes_templates WHERE custom_theme_id = @custom_theme_id " 
            + "AND user_file_name = @user_file_name;";

        // The using block is used to call dispose automatically even if there are an exception
        using (SqlConnection cn = new SqlConnection(connection))
        {
            // The using block is used to call dispose automatically even if there are an exception
            using (SqlCommand cmd = new SqlCommand(sql, cn))
            {
                // Add parameters
                cmd.Parameters.AddWithValue("@custom_theme_id", customThemeId);
                cmd.Parameters.AddWithValue("@user_file_name", userFileName);

                // Create a reader
                SqlDataReader reader = null;

                // The try/catch/finally statement is used to handle unusual exceptions in the code to
                // avoid having our application crash in such cases.
                try
                {
                    // Open the connection.
                    cn.Open();

                    // Fill the reader with one row of data.
                    reader = cmd.ExecuteReader();

                    // Loop through the reader as long as there is something to read and add values
                    while (reader.Read())
                    {
                        post = new CustomThemeTemplate(reader);
                    }
                }
                catch (Exception e)
                {
                    throw e;
                }
                finally
                {
                    // Call Close when done reading to avoid memory leakage.
                    if (reader != null)
                        reader.Close();
                }
            }
        }

        // Return the post
        return post;

    } // End of the GetOneById method
Esempio n. 11
0
    } // End of the constructor

    #endregion

    #region Insert methods

    /// <summary>
    /// Add one custom theme template
    /// </summary>
    /// <param name="post">A reference to a custom theme template post</param>
    public static void Add(CustomThemeTemplate post)
    {
        // Create the connection and the sql statement
        string connection = Tools.GetConnectionString();
        string sql = "INSERT INTO dbo.custom_themes_templates (custom_theme_id, user_file_name, master_file_url, user_file_content, comment) "
            + "VALUES (@custom_theme_id, @user_file_name, @master_file_url, @user_file_content, @comment);";

        // The using block is used to call dispose automatically even if there are an exception.
        using (SqlConnection cn = new SqlConnection(connection))
        {
            // The using block is used to call dispose automatically even if there are an exception.
            using (SqlCommand cmd = new SqlCommand(sql, cn))
            {
                // Add parameters
                cmd.Parameters.AddWithValue("@custom_theme_id", post.custom_theme_id);
                cmd.Parameters.AddWithValue("@user_file_name", post.user_file_name);
                cmd.Parameters.AddWithValue("@master_file_url", post.master_file_url);
                cmd.Parameters.AddWithValue("@user_file_content", post.user_file_content);
                cmd.Parameters.AddWithValue("@comment", post.comment);

                // The Try/Catch/Finally statement is used to handle unusual exceptions in the code to
                // avoid having our application crash in such cases
                try
                {
                    // Open the connection
                    cn.Open();

                    // Execute the insert
                    cmd.ExecuteNonQuery();

                }
                catch (Exception e)
                {
                    throw e;
                }
            }
        }

    } // End of the Add method
Esempio n. 12
0
    } // End of the Add method

    #endregion

    #region Update methods

    /// <summary>
    /// Update a custom theme template file
    /// </summary>
    /// <param name="template">A reference to a custom theme template post</param>
    public static void Update(CustomThemeTemplate template)
    {
        // Create the connection and the sql statement
        string connection = Tools.GetConnectionString();
        string sql = "UPDATE dbo.custom_themes_templates SET user_file_content = @user_file_content, "
            + "comment = @comment WHERE custom_theme_id = @custom_theme_id AND user_file_name = @user_file_name;";

        // The using block is used to call dispose automatically even if there is a exception.
        using (SqlConnection cn = new SqlConnection(connection))
        {
            // The using block is used to call dispose automatically even if there is a exception.
            using (SqlCommand cmd = new SqlCommand(sql, cn))
            {
                // Add parameters
                cmd.Parameters.AddWithValue("@custom_theme_id", template.custom_theme_id);
                cmd.Parameters.AddWithValue("@user_file_name", template.user_file_name);
                cmd.Parameters.AddWithValue("@user_file_content", template.user_file_content);
                cmd.Parameters.AddWithValue("@comment", template.comment);

                // The Try/Catch/Finally statement is used to handle unusual exceptions in the code to
                // avoid having our application crash in such cases.
                try
                {
                    // Open the connection.
                    cn.Open();

                    // Execute the update
                    cmd.ExecuteNonQuery();

                }
                catch (Exception e)
                {
                    throw e;
                }
            }
        }

    } // End of the Update method
Esempio n. 13
0
        public HttpResponseMessage add_template(CustomThemeTemplate post)
        {
            // Check for errors
            if (post == null)
            {
                return(Request.CreateResponse <string>(HttpStatusCode.BadRequest, "The post is null"));
            }
            else if (CustomTheme.MasterPostExists(post.custom_theme_id) == false)
            {
                return(Request.CreateResponse <string>(HttpStatusCode.BadRequest, "The theme does not exist"));
            }

            // Make sure that the data is valid
            post.user_file_name  = AnnytabDataValidation.TruncateString(post.user_file_name, 200);
            post.master_file_url = AnnytabDataValidation.TruncateString(post.master_file_url, 100);
            post.comment         = AnnytabDataValidation.TruncateString(post.comment, 200);

            // Add the post
            CustomTheme.AddTemplate(post);

            // Return the success response
            return(Request.CreateResponse <string>(HttpStatusCode.OK, "The post has been added"));
        } // End of the add_template method
        public HttpResponseMessage add_template(CustomThemeTemplate post)
        {
            // Check for errors
            if (post == null)
            {
                return Request.CreateResponse<string>(HttpStatusCode.BadRequest, "The post is null");
            }
            else if (CustomTheme.MasterPostExists(post.custom_theme_id) == false)
            {
                return Request.CreateResponse<string>(HttpStatusCode.BadRequest, "The theme does not exist");
            }

            // Make sure that the data is valid
            post.user_file_name = AnnytabDataValidation.TruncateString(post.user_file_name, 200);
            post.master_file_url = AnnytabDataValidation.TruncateString(post.master_file_url, 100);
            post.comment = AnnytabDataValidation.TruncateString(post.comment, 200);

            // Add the post
            CustomTheme.AddTemplate(post);

            // Return the success response
            return Request.CreateResponse<string>(HttpStatusCode.OK, "The post has been added");

        } // End of the add_template method
        public ActionResult edit_template(Int32 id = 0, string userFileName = "", string returnUrl = "")
        {
            // Get the current domain
            Domain currentDomain = Tools.GetCurrentDomain();
            ViewBag.CurrentDomain = currentDomain;

            // Get query parameters
            ViewBag.QueryParams = new QueryParams(returnUrl);

            // Check if the administrator is authorized
            if (Administrator.IsAuthorized(new string[] { "Administrator", "Editor" }) == true)
            {
                ViewBag.AdminSession = true;
            }
            else if (Administrator.IsAuthorized(Administrator.GetAllAdminRoles()) == true)
            {
                ViewBag.AdminSession = true;
                ViewBag.AdminErrorCode = 1;
                ViewBag.TranslatedTexts = StaticText.GetAll(currentDomain.back_end_language, "id", "ASC");
                return View("index");
            }
            else
            {
                // Redirect the user to the start page
                return RedirectToAction("index", "admin_login");
            }

            // Get the administrator default language
            Int32 adminLanguageId = currentDomain.back_end_language;

            // Check if the theme exists
            if(CustomTheme.MasterPostExists(id) == false)
            {
                return RedirectToAction("index");
            }

            // Get the custom them template
            CustomThemeTemplate template = CustomThemeTemplate.GetOneById(id, userFileName);

            // Create a new template if the template does not exist
            if (template == null)
            {
                // Redirect the user to the index page
                template = new CustomThemeTemplate();
                template.custom_theme_id = id;
            }

            // Set form data
            ViewBag.CustomTemplate = template;
            ViewBag.MasterDesign = CustomThemeTemplate.GetMasterFileContent(template.master_file_url);
            ViewBag.TranslatedTexts = StaticText.GetAll(adminLanguageId, "id", "ASC");
            ViewBag.ReturnUrl = returnUrl;

            // Return the edit template view
            return View("edit_template");

        } // End of the edit_template method
        public ActionResult edit_template(FormCollection collection)
        {
            // Get the current domain
            Domain currentDomain = Tools.GetCurrentDomain();
            ViewBag.CurrentDomain = currentDomain;

            // Get query parameters
            string returnUrl = collection["returnUrl"];
            ViewBag.QueryParams = new QueryParams(returnUrl);

            // Check if the administrator is authorized
            if (Administrator.IsAuthorized(new string[] { "Administrator", "Editor" }) == true)
            {
                ViewBag.AdminSession = true;
            }
            else if (Administrator.IsAuthorized(Administrator.GetAllAdminRoles()) == true)
            {
                ViewBag.AdminSession = true;
                ViewBag.AdminErrorCode = 1;
                ViewBag.TranslatedTexts = StaticText.GetAll(currentDomain.back_end_language, "id", "ASC");
                return View("index");
            }
            else
            {
                // Redirect the user to the start page
                return RedirectToAction("index", "admin_login");
            }

            // Get form data
            Int32 id = Convert.ToInt32(collection["txtId"]);
            string user_file_name = collection["txtUserFileName"];
            string file_content = collection["txtContent"];
            string comment = collection["txtComment"];

            // Get the template
            CustomThemeTemplate template = CustomThemeTemplate.GetOneById(id, user_file_name);

            // Update the template if is different from null
            if(template != null)
            {
                // Set the file content
                template.user_file_content = file_content;
                template.comment = comment;

                // Update the template
                CustomTheme.UpdateTemplate(template);
            }
            else
            {
                // Create a new template
                template = new CustomThemeTemplate();
                template.custom_theme_id = id;
                template.user_file_name = user_file_name;
                template.user_file_content = file_content;
                template.comment = comment;

                // Add the template
                CustomThemeTemplate.Add(template);
            }

            // Redirect the user to the edit theme page
            return RedirectToAction("edit_theme", new { id = template.custom_theme_id, returnUrl = returnUrl });

        } // End of the edit_template method
Esempio n. 17
0
    } // End of the Add method

    /// <summary>
    /// Add custom theme templates
    /// </summary>
    /// <param name="id"></param>
    public static void AddCustomThemeTemplates(Int32 id)
    {
        // Get all the templates
        Dictionary<string, string> templates = CustomThemeTemplate.GetAllByCustomThemeId(id, "user_file_name", "ASC");
        
        // Add templates that does not exist
        if (templates.ContainsKey("front_category_menu.cshtml") == false)
        {
            CustomThemeTemplate.Add(new CustomThemeTemplate(id, "front_category_menu.cshtml", "/Views/shared_front/_category_menu.cshtml",
                CustomThemeTemplate.GetMasterFileContent("/Views/shared_front/_category_menu.cshtml"), "Creates the category menu with leveling."));
        }
        if (templates.ContainsKey("front_paging_menu.cshtml") == false)
        {
            CustomThemeTemplate.Add(new CustomThemeTemplate(id, "front_paging_menu.cshtml", "/Views/shared_front/_paging_menu.cshtml",
                CustomThemeTemplate.GetMasterFileContent("/Views/shared_front/_paging_menu.cshtml"), "Creates the paging menu that shows under listed items in many files."));
        }
        if (templates.ContainsKey("front_post_comments.cshtml") == false)
        {
            CustomThemeTemplate.Add(new CustomThemeTemplate(id, "front_post_comments.cshtml", "/Views/shared_front/_post_comments.cshtml",
                CustomThemeTemplate.GetMasterFileContent("/Views/shared_front/_post_comments.cshtml"), "Shows the comments for a post."));
        }
        if (templates.ContainsKey("front_post_files.cshtml") == false)
        {
            CustomThemeTemplate.Add(new CustomThemeTemplate(id, "front_post_files.cshtml", "/Views/shared_front/_post_files.cshtml",
                CustomThemeTemplate.GetMasterFileContent("/Views/shared_front/_post_files.cshtml"), "Show the files that can be downloaded for a post."));
        }
        if (templates.ContainsKey("front_shared_scripts.cshtml") == false)
        {
            CustomThemeTemplate.Add(new CustomThemeTemplate(id, "front_shared_scripts.cshtml", "/Views/shared_front/_shared_scripts.cshtml",
                CustomThemeTemplate.GetMasterFileContent("/Views/shared_front/_shared_scripts.cshtml"), "Common scripts for google analytics, google plus, facebook and more."));
        }
        if (templates.ContainsKey("front_standard_layout.cshtml") == false)
        {
            CustomThemeTemplate.Add(new CustomThemeTemplate(id, "front_standard_layout.cshtml", "/Views/shared_front/_standard_layout.cshtml",
                CustomThemeTemplate.GetMasterFileContent("/Views/shared_front/_standard_layout.cshtml"), "Standard layout file for a normal browser."));
        }
        if (templates.ContainsKey("author.cshtml") == false)
        {
            CustomThemeTemplate.Add(new CustomThemeTemplate(id, "author.cshtml", "/Views/home/author.cshtml",
                CustomThemeTemplate.GetMasterFileContent("/Views/home/author.cshtml"), "An information page about a author."));
        }
        if (templates.ContainsKey("category.cshtml") == false)
        {
            CustomThemeTemplate.Add(new CustomThemeTemplate(id, "category.cshtml", "/Views/home/category.cshtml",
                CustomThemeTemplate.GetMasterFileContent("/Views/home/category.cshtml"), "Displays a category with its categories and products."));
        }
        if (templates.ContainsKey("error.cshtml") == false)
        {
            CustomThemeTemplate.Add(new CustomThemeTemplate(id, "error.cshtml", "/Views/home/error.cshtml",
                CustomThemeTemplate.GetMasterFileContent("/Views/home/error.cshtml"), "The page that shows error messages."));
        }
        if (templates.ContainsKey("home.cshtml") == false)
        {
            CustomThemeTemplate.Add(new CustomThemeTemplate(id, "home.cshtml", "/Views/home/index.cshtml",
                CustomThemeTemplate.GetMasterFileContent("/Views/home/index.cshtml"), "The entry page for the website."));
        }
        if (templates.ContainsKey("information.cshtml") == false)
        {
            CustomThemeTemplate.Add(new CustomThemeTemplate(id, "information.cshtml", "/Views/home/information.cshtml",
                CustomThemeTemplate.GetMasterFileContent("/Views/home/information.cshtml"), "Displays the content of a static page."));
        }
        if (templates.ContainsKey("post.cshtml") == false)
        {
            CustomThemeTemplate.Add(new CustomThemeTemplate(id, "post.cshtml", "/Views/home/post.cshtml",
                CustomThemeTemplate.GetMasterFileContent("/Views/home/post.cshtml"), "Displays a post with files, rating and comments."));
        }
        if (templates.ContainsKey("search.cshtml") == false)
        {
            CustomThemeTemplate.Add(new CustomThemeTemplate(id, "search.cshtml", "/Views/home/search.cshtml",
                CustomThemeTemplate.GetMasterFileContent("/Views/home/search.cshtml"), "Displays a list of posts according to a search."));
        }
        if (templates.ContainsKey("user_menu.cshtml") == false)
        {
            CustomThemeTemplate.Add(new CustomThemeTemplate(id, "user_menu.cshtml", "/Views/user/_user_menu.cshtml",
                CustomThemeTemplate.GetMasterFileContent("/Views/user/_user_menu.cshtml"), "The menu for a signed in user."));
        }
        if (templates.ContainsKey("edit_user_details.cshtml") == false)
        {
            CustomThemeTemplate.Add(new CustomThemeTemplate(id, "edit_user_details.cshtml", "/Views/user/edit.cshtml",
                CustomThemeTemplate.GetMasterFileContent("/Views/user/edit.cshtml"), "The form where the user can edit his information."));
        }
        if (templates.ContainsKey("edit_user_comments.cshtml") == false)
        {
            CustomThemeTemplate.Add(new CustomThemeTemplate(id, "edit_user_comments.cshtml", "/Views/user/edit_comments.cshtml",
                CustomThemeTemplate.GetMasterFileContent("/Views/user/edit_comments.cshtml"), "A list form where the user can edit his comments."));
        }
        if (templates.ContainsKey("edit_user_ratings.cshtml") == false)
        {
            CustomThemeTemplate.Add(new CustomThemeTemplate(id, "edit_user_ratings.cshtml", "/Views/user/edit_ratings.cshtml",
                CustomThemeTemplate.GetMasterFileContent("/Views/user/edit_ratings.cshtml"), "A list form where the user can edit his ratings."));
        }
        if (templates.ContainsKey("forgot_password.cshtml") == false)
        {
            CustomThemeTemplate.Add(new CustomThemeTemplate(id, "forgot_password.cshtml", "/Views/user/forgot_password.cshtml",
                CustomThemeTemplate.GetMasterFileContent("/Views/user/forgot_password.cshtml"), "A form where a user can get his password."));
        }
        if (templates.ContainsKey("user_start_page.cshtml") == false)
        {
            CustomThemeTemplate.Add(new CustomThemeTemplate(id, "user_start_page.cshtml", "/Views/user/index.cshtml",
                CustomThemeTemplate.GetMasterFileContent("/Views/user/index.cshtml"), "The start page for the user."));
        }
        if (templates.ContainsKey("user_login.cshtml") == false)
        {
            CustomThemeTemplate.Add(new CustomThemeTemplate(id, "user_login.cshtml", "/Views/user/login.cshtml",
                CustomThemeTemplate.GetMasterFileContent("/Views/user/login.cshtml"), "The form where a user can log in to his account."));
        }
        if (templates.ContainsKey("front_default_style.css") == false)
        {
            CustomThemeTemplate.Add(new CustomThemeTemplate(id, "front_default_style.css", "/Content/annytab_css/front_default_style.css",
                CustomThemeTemplate.GetMasterFileContent("/Content/annytab_css/front_default_style.css"), "Css styling that is shared between layouts."));
        }
        if (templates.ContainsKey("front_medium_layout.css") == false)
        {
            CustomThemeTemplate.Add(new CustomThemeTemplate(id, "front_medium_layout.css", "/Content/annytab_css/front_medium_layout.css",
                CustomThemeTemplate.GetMasterFileContent("/Content/annytab_css/front_medium_layout.css"), "Css styling for the medium layout."));
        }
        if (templates.ContainsKey("front_mobile_layout.css") == false)
        {
            CustomThemeTemplate.Add(new CustomThemeTemplate(id, "front_mobile_layout.css", "/Content/annytab_css/front_mobile_layout.css",
                CustomThemeTemplate.GetMasterFileContent("/Content/annytab_css/front_mobile_layout.css"), "Css styling for the mobile layout."));
        }
        if (templates.ContainsKey("front_standard_layout.css") == false)
        {
            CustomThemeTemplate.Add(new CustomThemeTemplate(id, "front_standard_layout.css", "/Content/annytab_css/front_standard_layout.css",
                CustomThemeTemplate.GetMasterFileContent("/Content/annytab_css/front_standard_layout.css"), "Css styling for the standard layout."));
        }
        if (templates.ContainsKey("rateit.css") == false)
        {
            CustomThemeTemplate.Add(new CustomThemeTemplate(id, "rateit.css", "/Content/annytab_css/rateit.css",
                CustomThemeTemplate.GetMasterFileContent("/Content/annytab_css/rateit.css"), "The style for the rating component in posts."));
        }
        if (templates.ContainsKey("annytab.category-functions.js") == false)
        {
            CustomThemeTemplate.Add(new CustomThemeTemplate(id, "annytab.category-functions.js", "/Scripts/annytab_front/annytab.category-functions.js",
                CustomThemeTemplate.GetMasterFileContent("/Scripts/annytab_front/annytab.category-functions.js"), "Functions that apply to the category page, where a category is displayed."));
        }
        if (templates.ContainsKey("annytab.default-functions.js") == false)
        {
            CustomThemeTemplate.Add(new CustomThemeTemplate(id, "annytab.default-functions.js", "/Scripts/annytab_front/annytab.default-functions.js",
                CustomThemeTemplate.GetMasterFileContent("/Scripts/annytab_front/annytab.default-functions.js"), "Functions that apply to the entire website, both standard and mobile layouts."));
        }
        if (templates.ContainsKey("annytab.home-functions.js") == false)
        {
            CustomThemeTemplate.Add(new CustomThemeTemplate(id, "annytab.home-functions.js", "/Scripts/annytab_front/annytab.home-functions.js",
                CustomThemeTemplate.GetMasterFileContent("/Scripts/annytab_front/annytab.home-functions.js"), "Functions that apply to the index page of the website, the home page."));
        }
        if (templates.ContainsKey("annytab.post-functions.js") == false)
        {
            CustomThemeTemplate.Add(new CustomThemeTemplate(id, "annytab.post-functions.js", "/Scripts/annytab_front/annytab.post-functions.js",
                CustomThemeTemplate.GetMasterFileContent("/Scripts/annytab_front/annytab.post-functions.js"), "Functions that apply to the post page."));
        }
        if (templates.ContainsKey("annytab.standard-layout-functions.js") == false)
        {
            CustomThemeTemplate.Add(new CustomThemeTemplate(id, "annytab.standard-layout-functions.js", "/Scripts/annytab_front/annytab.standard-layout-functions.js",
                CustomThemeTemplate.GetMasterFileContent("/Scripts/annytab_front/annytab.standard-layout-functions.js"), "Functions that apply to the standard layout for the website."));
        }
        if (templates.ContainsKey("annytab.user-functions.js") == false)
        {
            CustomThemeTemplate.Add(new CustomThemeTemplate(id, "annytab.user-functions.js", "/Scripts/annytab_front/annytab.user-functions.js",
                CustomThemeTemplate.GetMasterFileContent("/Scripts/annytab_front/annytab.user-functions.js"), "Functions that apply to the edit user details page."));
        }

    } // End of the AddCustomThemeTemplates method
Esempio n. 18
0
    } // End of the AddCustomThemeTemplates method

    /// <summary>
    /// Add a template
    /// </summary>
    /// <param name="template">A reference to a template</param>
    public static void AddTemplate(CustomThemeTemplate template)
    {
        // Add the template
        CustomThemeTemplate.Add(template);

        // Remove the cache
        RemoveThemeCache(template.custom_theme_id);

    } // End of the AddTemplate method
        public HttpResponseMessage update_template(CustomThemeTemplate post)
        {
            // Check for errors
            if (post == null)
            {
                return Request.CreateResponse<string>(HttpStatusCode.BadRequest, "The post is null");
            }

            // Make sure that the data is valid
            post.user_file_name = AnnytabDataValidation.TruncateString(post.user_file_name, 200);
            post.master_file_url = AnnytabDataValidation.TruncateString(post.master_file_url, 100);
            post.comment = AnnytabDataValidation.TruncateString(post.comment, 200);

            // Get the saved post
            CustomThemeTemplate savedPost = CustomThemeTemplate.GetOneById(post.custom_theme_id, post.user_file_name);

            // Check if the post exists
            if (savedPost == null)
            {
                return Request.CreateResponse<string>(HttpStatusCode.BadRequest, "The record does not exist");
            }

            // Update the post
            CustomTheme.UpdateTemplate(post);

            // Return the success response
            return Request.CreateResponse<string>(HttpStatusCode.OK, "The update was successful");

        } // End of the update_template method
        public ActionResult import_templates_from_zip(FormCollection collection)
        {
            // Get the current domain
            Domain currentDomain = Tools.GetCurrentDomain();
            ViewBag.CurrentDomain = currentDomain;

            // Get query parameters
            string returnUrl = collection["returnUrl"];
            ViewBag.QueryParams = new QueryParams(returnUrl);

            // Check if the administrator is authorized
            if (Administrator.IsAuthorized(new string[] { "Administrator", "Editor" }) == true)
            {
                ViewBag.AdminSession = true;
            }
            else if (Administrator.IsAuthorized(Administrator.GetAllAdminRoles()) == true)
            {
                ViewBag.AdminSession = true;
                ViewBag.AdminErrorCode = 1;
                ViewBag.TranslatedTexts = StaticText.GetAll(currentDomain.back_end_language, "id", "ASC");
                return View("index");
            }
            else
            {
                // Redirect the user to the start page
                return RedirectToAction("index", "admin_login");
            }

            // Get the form data
            Int32 custom_theme_id = Convert.ToInt32(collection["hiddenId"]);

            // Delete the existing templates
            CustomTheme.DeleteTemplatesOnId(custom_theme_id);

            // Add master templates
            CustomTheme.AddCustomThemeTemplates(custom_theme_id);

            // Get the zip file
            HttpPostedFileBase uploadedFile = Request.Files["importFilesFromZip"];

            // Create the zip file variable
            Ionic.Zip.ZipFile zipFile = null;

            try
            {
                // Read the zip file
                zipFile = Ionic.Zip.ZipFile.Read(uploadedFile.InputStream);

                // Loop the zip file
                for(int i = 0; i < zipFile.Count; i++)
                {
                    // Get the file name
                    string fileName = zipFile[i].FileName;

                    // Get the file content
                    string fileContent = "";

                    // Get the stream from the zip entry
                    using (Stream stream = zipFile[i].OpenReader())
                    {
                        // Create a byte buffer
                        byte[] buffer = new byte[stream.Length];

                        // Create a byte counter
                        int byteCounter = 0;

                        // Read the bytes
                        while ((byteCounter = stream.Read(buffer, 0, buffer.Length)) > 0)
                        {
                            // Get the content of the zip-file
                            fileContent = System.Text.Encoding.UTF8.GetString(buffer);
                        }
                    }

                    // Try to find the template
                    CustomThemeTemplate template = CustomThemeTemplate.GetOneById(custom_theme_id, fileName);

                    // Check if the template is null or not
                    if(template == null)
                    {
                        template = new CustomThemeTemplate();
                        template.custom_theme_id = custom_theme_id;
                        template.user_file_name = fileName;
                        template.user_file_content = fileContent;
                        template.comment = "This template does not have a master file.";

                        // Add the template
                        CustomTheme.AddTemplate(template);
                    }
                    else
                    {
                        // Change the content of the file
                        template.user_file_content = fileContent;

                        // Update the template
                        CustomTheme.UpdateTemplate(template);
                    }
                }
            }
            catch (Exception exception)
            {
                string exceptionMessage = "";
                exceptionMessage = exception.Message;
            }
            finally
            {
                // Close the zip file if it is different from null
                if (zipFile != null)
                {
                    zipFile.Dispose();
                }
            }

            // Redirect the user to the edit theme page
            return RedirectToAction("edit_theme", new { id = custom_theme_id, returnUrl = returnUrl });

        } // End of the import_templates_from_zip method
Esempio n. 21
0
    } // End of the Update method

    /// <summary>
    /// Update a custom theme template
    /// </summary>
    /// <param name="template">A reference to a custom theme template</param>
    public static void UpdateTemplate(CustomThemeTemplate template)
    {
        // Update the the template
        CustomThemeTemplate.Update(template);

        // Remove the cache
        RemoveThemeCache(template.custom_theme_id);

    } // End of the UpdateTemplate method
Esempio n. 22
0
    } // End of the Add method

    /// <summary>
    /// Add custom theme templates
    /// </summary>
    /// <param name="id"></param>
    public static void AddCustomThemeTemplates(Int32 id)
    {
        // Get all the templates
        Dictionary<string, string> templates = CustomThemeTemplate.GetAllByCustomThemeId(id, "user_file_name", "ASC");
        
        // Add templates that does not exist
        if (templates.ContainsKey("front_category_menu.cshtml") == false)
        {
            CustomThemeTemplate.Add(new CustomThemeTemplate(id, "front_category_menu.cshtml", "/Views/shared_front/_category_menu.cshtml",
                CustomThemeTemplate.GetMasterFileContent("/Views/shared_front/_category_menu.cshtml"), "Creates the category menu with leveling."));
        }
        if (templates.ContainsKey("front_display_items.cshtml") == false)
        {
            CustomThemeTemplate.Add(new CustomThemeTemplate(id, "front_display_items.cshtml", "/Views/shared_front/_display_items.cshtml",
                CustomThemeTemplate.GetMasterFileContent("/Views/shared_front/_display_items.cshtml"), "Creates the list of categories and products to show on the home page and the category page."));
        }
        if (templates.ContainsKey("front_paging_menu.cshtml") == false)
        {
            CustomThemeTemplate.Add(new CustomThemeTemplate(id, "front_paging_menu.cshtml", "/Views/shared_front/_paging_menu.cshtml",
                CustomThemeTemplate.GetMasterFileContent("/Views/shared_front/_paging_menu.cshtml"), "Creates the paging menu that shows under listed items in many files."));
        }
        if (templates.ContainsKey("front_product_accessories.cshtml") == false)
        {
            CustomThemeTemplate.Add(new CustomThemeTemplate(id, "front_product_accessories.cshtml", "/Views/shared_front/_product_accessories.cshtml",
                CustomThemeTemplate.GetMasterFileContent("/Views/shared_front/_product_accessories.cshtml"), "List of product accessories under a product."));
        }
        if (templates.ContainsKey("front_product_reviews.cshtml") == false)
        {
            CustomThemeTemplate.Add(new CustomThemeTemplate(id, "front_product_reviews.cshtml", "/Views/shared_front/_product_reviews.cshtml",
                CustomThemeTemplate.GetMasterFileContent("/Views/shared_front/_product_reviews.cshtml"), "List of reviews under a product."));
        }
        if (templates.ContainsKey("front_shared_scripts.cshtml") == false)
        {
            CustomThemeTemplate.Add(new CustomThemeTemplate(id, "front_shared_scripts.cshtml", "/Views/shared_front/_shared_scripts.cshtml",
                CustomThemeTemplate.GetMasterFileContent("/Views/shared_front/_shared_scripts.cshtml"), "Common scripts for google analytics, google plus, facebook and more."));
        }
        if(templates.ContainsKey("front_standard_layout.cshtml") == false)
        {
            CustomThemeTemplate.Add(new CustomThemeTemplate(id, "front_standard_layout.cshtml", "/Views/shared_front/_standard_layout.cshtml",
                CustomThemeTemplate.GetMasterFileContent("/Views/shared_front/_standard_layout.cshtml"), "Standard layout file for a normal browser."));
        }
        if (templates.ContainsKey("customer_menu.cshtml") == false)
        {
            CustomThemeTemplate.Add(new CustomThemeTemplate(id, "customer_menu.cshtml", "/Views/customer/_menu.cshtml",
                CustomThemeTemplate.GetMasterFileContent("/Views/customer/_menu.cshtml"), "A menu for a signed in customer"));
        }
        if (templates.ContainsKey("customer_download_files.cshtml") == false)
        {
            CustomThemeTemplate.Add(new CustomThemeTemplate(id, "customer_download_files.cshtml", "/Views/customer/download_files.cshtml",
                CustomThemeTemplate.GetMasterFileContent("/Views/customer/download_files.cshtml"), "A list with downloadable files that a customer has ordered, these files can be downloaded by the customer."));
        }
        if (templates.ContainsKey("edit_company.cshtml") == false)
        {
            CustomThemeTemplate.Add(new CustomThemeTemplate(id, "edit_company.cshtml", "/Views/customer/edit_company.cshtml",
                CustomThemeTemplate.GetMasterFileContent("/Views/customer/edit_company.cshtml"), "The form where a company customer can edit his information."));
        }
        if (templates.ContainsKey("edit_person.cshtml") == false)
        {
            CustomThemeTemplate.Add(new CustomThemeTemplate(id, "edit_person.cshtml", "/Views/customer/edit_person.cshtml",
                CustomThemeTemplate.GetMasterFileContent("/Views/customer/edit_person.cshtml"), "The form where a private person customer can edit his information."));
        }
        if (templates.ContainsKey("edit_customer_reviews.cshtml") == false)
        {
            CustomThemeTemplate.Add(new CustomThemeTemplate(id, "edit_customer_reviews.cshtml", "/Views/customer/edit_reviews.cshtml",
                CustomThemeTemplate.GetMasterFileContent("/Views/customer/edit_reviews.cshtml"), "A list form where a customer can edit his reviews."));
        }
        if (templates.ContainsKey("forgot_email_password.cshtml") == false)
        {
            CustomThemeTemplate.Add(new CustomThemeTemplate(id, "forgot_email_password.cshtml", "/Views/customer/forgot_email_password.cshtml",
                CustomThemeTemplate.GetMasterFileContent("/Views/customer/forgot_email_password.cshtml"), "A form where a customer can get his email or his password."));
        }
        if (templates.ContainsKey("customer_start_page.cshtml") == false)
        {
            CustomThemeTemplate.Add(new CustomThemeTemplate(id, "customer_start_page.cshtml", "/Views/customer/index.cshtml",
                CustomThemeTemplate.GetMasterFileContent("/Views/customer/index.cshtml"), "The start page for the customer."));
        }
        if (templates.ContainsKey("customer_login.cshtml") == false)
        {
            CustomThemeTemplate.Add(new CustomThemeTemplate(id, "customer_login.cshtml", "/Views/customer/login.cshtml",
                CustomThemeTemplate.GetMasterFileContent("/Views/customer/login.cshtml"), "The form where a customer can log in to his account."));
        }
        if (templates.ContainsKey("category.cshtml") == false)
        {
            CustomThemeTemplate.Add(new CustomThemeTemplate(id, "category.cshtml", "/Views/home/category.cshtml",
                CustomThemeTemplate.GetMasterFileContent("/Views/home/category.cshtml"), "Displays a category with its categories and products."));
        }
        if (templates.ContainsKey("contact_us.cshtml") == false)
        {
            CustomThemeTemplate.Add(new CustomThemeTemplate(id, "contact_us.cshtml", "/Views/home/contact_us.cshtml",
                CustomThemeTemplate.GetMasterFileContent("/Views/home/contact_us.cshtml"), "A contact us form."));
        }
        if (templates.ContainsKey("error.cshtml") == false)
        {
            CustomThemeTemplate.Add(new CustomThemeTemplate(id, "error.cshtml", "/Views/home/error.cshtml",
                CustomThemeTemplate.GetMasterFileContent("/Views/home/error.cshtml"), "The page that shows error messages."));
        }
        if (templates.ContainsKey("home.cshtml") == false)
        {
            CustomThemeTemplate.Add(new CustomThemeTemplate(id, "home.cshtml", "/Views/home/index.cshtml",
                CustomThemeTemplate.GetMasterFileContent("/Views/home/index.cshtml"), "The entry page for the webshop."));
        }
        if (templates.ContainsKey("information.cshtml") == false)
        {
            CustomThemeTemplate.Add(new CustomThemeTemplate(id, "information.cshtml", "/Views/home/information.cshtml",
                CustomThemeTemplate.GetMasterFileContent("/Views/home/information.cshtml"), "Displays the content of a static page."));
        }
        if (templates.ContainsKey("product.cshtml") == false)
        {
            CustomThemeTemplate.Add(new CustomThemeTemplate(id, "product.cshtml", "/Views/home/product.cshtml",
                CustomThemeTemplate.GetMasterFileContent("/Views/home/product.cshtml"), "Displays a product with information and buy button."));
        }
        if (templates.ContainsKey("search.cshtml") == false)
        {
            CustomThemeTemplate.Add(new CustomThemeTemplate(id, "search.cshtml", "/Views/home/search.cshtml",
                CustomThemeTemplate.GetMasterFileContent("/Views/home/search.cshtml"), "Displays a list of products according to a search."));
        }
        if (templates.ContainsKey("terms_of_purchase.cshtml") == false)
        {
            CustomThemeTemplate.Add(new CustomThemeTemplate(id, "terms_of_purchase.cshtml", "/Views/home/terms_of_purchase.cshtml",
                CustomThemeTemplate.GetMasterFileContent("/Views/home/terms_of_purchase.cshtml"), "The terms of purchase page."));
        }
        if (templates.ContainsKey("order_confirmation_body.cshtml") == false)
        {
            CustomThemeTemplate.Add(new CustomThemeTemplate(id, "order_confirmation_body.cshtml", "/Views/order/_confirmation_body.cshtml",
                CustomThemeTemplate.GetMasterFileContent("/Views/order/_confirmation_body.cshtml"), "The order confirmation printable area, used to view, print and email the order confirmation."));
        }
        if (templates.ContainsKey("order_confirmation.cshtml") == false)
        {
            CustomThemeTemplate.Add(new CustomThemeTemplate(id, "order_confirmation.cshtml", "/Views/order/confirmation.cshtml",
                CustomThemeTemplate.GetMasterFileContent("/Views/order/confirmation.cshtml"), "The order confirmation wrapper file where the customer can view and print the order confirmation."));
        }
        if (templates.ContainsKey("checkout.cshtml") == false)
        {
            CustomThemeTemplate.Add(new CustomThemeTemplate(id, "checkout.cshtml", "/Views/order/index.cshtml",
                CustomThemeTemplate.GetMasterFileContent("/Views/order/index.cshtml"), "The checkout template, where the customer makes the order."));
        }
        if (templates.ContainsKey("front_default_style.css") == false)
        {
            CustomThemeTemplate.Add(new CustomThemeTemplate(id, "front_default_style.css", "/Content/annytab_css/front_default_style.css",
                CustomThemeTemplate.GetMasterFileContent("/Content/annytab_css/front_default_style.css"), "Css styling that is shared between layouts."));
        }
        if (templates.ContainsKey("front_medium_layout.css") == false)
        {
            CustomThemeTemplate.Add(new CustomThemeTemplate(id, "front_medium_layout.css", "/Content/annytab_css/front_medium_layout.css",
                CustomThemeTemplate.GetMasterFileContent("/Content/annytab_css/front_medium_layout.css"), "Css styling for a medium layout."));
        }
        if (templates.ContainsKey("front_mobile_layout.css") == false)
        {
            CustomThemeTemplate.Add(new CustomThemeTemplate(id, "front_mobile_layout.css", "/Content/annytab_css/front_mobile_layout.css",
                CustomThemeTemplate.GetMasterFileContent("/Content/annytab_css/front_mobile_layout.css"), "Css styling for a mobile layout."));
        }
        if (templates.ContainsKey("front_standard_layout.css") == false)
        {
            CustomThemeTemplate.Add(new CustomThemeTemplate(id, "front_standard_layout.css", "/Content/annytab_css/front_standard_layout.css",
                CustomThemeTemplate.GetMasterFileContent("/Content/annytab_css/front_standard_layout.css"), "Css styling for the standard layout."));
        }
        if (templates.ContainsKey("rateit.css") == false)
        {
            CustomThemeTemplate.Add(new CustomThemeTemplate(id, "rateit.css", "/Content/annytab_css/rateit.css",
                CustomThemeTemplate.GetMasterFileContent("/Content/annytab_css/rateit.css"), "The style for the rating component in product reviews."));
        }
        if (templates.ContainsKey("annytab.category-functions.js") == false)
        {
            CustomThemeTemplate.Add(new CustomThemeTemplate(id, "annytab.category-functions.js", "/Scripts/annytab_front/annytab.category-functions.js",
                CustomThemeTemplate.GetMasterFileContent("/Scripts/annytab_front/annytab.category-functions.js"), "Functions that apply to the category page, where a category is displayed."));
        }
        if (templates.ContainsKey("annytab.default-functions.js") == false)
        {
            CustomThemeTemplate.Add(new CustomThemeTemplate(id, "annytab.default-functions.js", "/Scripts/annytab_front/annytab.default-functions.js",
                CustomThemeTemplate.GetMasterFileContent("/Scripts/annytab_front/annytab.default-functions.js"), "Functions that apply to the entire website, both standard and mobile."));
        }
        if (templates.ContainsKey("annytab.home-functions.js") == false)
        {
            CustomThemeTemplate.Add(new CustomThemeTemplate(id, "annytab.home-functions.js", "/Scripts/annytab_front/annytab.home-functions.js",
                CustomThemeTemplate.GetMasterFileContent("/Scripts/annytab_front/annytab.home-functions.js"), "Functions that apply to the index page of the website, the home page."));
        }
        if (templates.ContainsKey("annytab.order-functions.js") == false)
        {
            CustomThemeTemplate.Add(new CustomThemeTemplate(id, "annytab.order-functions.js", "/Scripts/annytab_front/annytab.order-functions.js",
                CustomThemeTemplate.GetMasterFileContent("/Scripts/annytab_front/annytab.order-functions.js"), "Functions that apply to the checkout page."));
        }
        if (templates.ContainsKey("annytab.product-functions.js") == false)
        {
            CustomThemeTemplate.Add(new CustomThemeTemplate(id, "annytab.product-functions.js", "/Scripts/annytab_front/annytab.product-functions.js",
                CustomThemeTemplate.GetMasterFileContent("/Scripts/annytab_front/annytab.product-functions.js"), "Functions that apply to the product page, some functions relate to the recalculation of the product price."));
        }
        if (templates.ContainsKey("annytab.standard-layout-functions.js") == false)
        {
            CustomThemeTemplate.Add(new CustomThemeTemplate(id, "annytab.standard-layout-functions.js", "/Scripts/annytab_front/annytab.standard-layout-functions.js",
                CustomThemeTemplate.GetMasterFileContent("/Scripts/annytab_front/annytab.standard-layout-functions.js"), "Functions that apply to the standard layout for the website."));
        }
        if (templates.ContainsKey("front_category_imap.cshtml") == false)
        {
            CustomThemeTemplate.Add(new CustomThemeTemplate(id, "front_category_imap.cshtml", "/Views/shared_front/_category_imap.cshtml",
                CustomThemeTemplate.GetMasterFileContent("/Views/shared_front/_category_imap.cshtml"), "Displays inspiration image maps for a category."));
        }
        if (templates.ContainsKey("annytab.image-map.js") == false)
        {
            CustomThemeTemplate.Add(new CustomThemeTemplate(id, "annytab.image-map.js", "/Scripts/annytab_front/annytab.image-map.js",
                CustomThemeTemplate.GetMasterFileContent("/Scripts/annytab_front/annytab.image-map.js"), "A jQuery plugin that controls image maps."));
        }
        
    } // End of the AddCustomThemeTemplates method