Exemplo n.º 1
0
        public ActionResult DeleteConfirmed(int id)
        {
            Weblink weblink = weblinkservice.Find(id);

            weblinkservice.Delete(weblink);
            uow.SaveChanges();
            return(RedirectToAction("IndexAdmin", "WebLink"));
        }
        public ActionResult translate(Int32 id = 0, string returnUrl = "/admin_weblinks")
        {
            // 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", "Translator" }) == 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 default admin language id
            Int32 adminLanguageId = currentDomain.back_end_language;

            // Get the language id
            int languageId = 0;
            if (Request.Params["lang"] != null)
            {
                Int32.TryParse(Request.Params["lang"], out languageId);
            }

            // Add data to the form
            ViewBag.LanguageId = languageId;
            ViewBag.Languages = Language.GetAll(adminLanguageId, "name", "ASC");
            ViewBag.StandardWeblink = Weblink.GetOneById(id, adminLanguageId);
            ViewBag.TranslatedWeblink = Weblink.GetOneById(id, languageId);
            ViewBag.TranslatedTexts = StaticText.GetAll(adminLanguageId, "id", "ASC");
            ViewBag.ReturnUrl = returnUrl;

            // Return the view
            if (ViewBag.StandardWeblink != null)
            {
                return View("translate");
            }
            else
            {
                return Redirect(returnUrl);
            }

        } // End of the translate method
Exemplo n.º 3
0
    } // End of the MasterPostExists method

    /// <summary>
    /// Get one weblink based on id
    /// </summary>
    /// <param name="id">The id</param>
    /// <param name="languageId">The language id</param>
    /// <returns>A reference to a weblink post</returns>
    public static Weblink GetOneById(Int32 id, Int32 languageId)
    {
        // Create the post to return
        Weblink post = null;

        // Create the connection and the sql statement
        string connection = Tools.GetConnectionString();
        string sql = "SELECT * FROM dbo.weblinks_detail AS D INNER JOIN dbo.weblinks AS W ON D.weblink_id = W.id " 
            + "AND D.weblink_id = @id AND D.language_id = @language_id;";

        // 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("@id", id);
                cmd.Parameters.AddWithValue("@language_id", languageId);

                // 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 Weblink(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
Exemplo n.º 4
0
 public ActionResult Edit(Weblink weblink)
 {
     if (ModelState.IsValid)
     {
         weblinkservice.Edit(weblink);
         uow.SaveChanges();
         return(RedirectToAction("IndexAdmin", "WebLink"));
     }
     return(View(weblink));
 }
Exemplo n.º 5
0
        public ActionResult Create(Weblink weblink)
        {
            if (this.ModelState.IsValid)
            {
                weblinkservice.Add(weblink);
                this.uow.SaveChanges();
                return(RedirectToAction("IndexAdmin", "WebLink"));
            }

            return(View(weblink));
        }
        public void RetrieveAdditionalInformationTest_withInvalidID()
        {
            // Arrange
            Weblink entry = new Weblink("_aaa");

            // Act
            int count = entry.RetrieveAdditionalInformation();

            // Assert
            Assert.AreEqual(0, count);
        }
        public ActionResult edit(Int32 id = 0, string returnUrl = "/admin_weblinks")
        {
            // 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 default admin language
            Int32 adminLanguageId = currentDomain.back_end_language;

            // Add data to the view
            ViewBag.TranslatedTexts = StaticText.GetAll(adminLanguageId, "id", "ASC");
            ViewBag.Weblink = Weblink.GetOneById(id, adminLanguageId);
            ViewBag.ReturnUrl = returnUrl;

            // Create new empty weblink if the weblink does not exist
            if (ViewBag.Weblink == null)
            {
                // Add data to the view
                ViewBag.Weblink = new Weblink();
            }

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

        } // End of the edit method
        public void WeblinkTest_withID()
        {
            // Arrange
            Weblink entry = new Weblink("_xxx");

            // Act
            // Assert
            Assert.IsNotNull(entry);
            Assert.IsNotNull(entry.Reader);

            Assert.AreEqual("_xxx", entry.ID);
            Assert.IsNull(entry.Url);
            Assert.IsNull(entry.EnglishTitle);
            Assert.IsNull(entry.GermanTitle);
            Assert.IsNull(entry.Language);
            Assert.IsNull(entry.Details);
            Assert.IsNull(entry.Status);
            Assert.IsNull(entry.LastUpdated);
        }
        public void RetrieveTest_withInvalidID_AdditionalInfo()
        {
            // Arrange
            Weblink entry = new Weblink("_aaa");

            // Act
            int count = entry.Retrieve(false);

            // Assert
            Assert.AreEqual(0, count);

            Assert.AreEqual("_aaa", entry.ID);
            Assert.IsNull(entry.Url);
            Assert.IsNull(entry.EnglishTitle);
            Assert.IsNull(entry.GermanTitle);
            Assert.IsNull(entry.Language);
            Assert.IsNull(entry.Details);
            Assert.IsNull(entry.Status);
            Assert.IsNull(entry.LastUpdated);
        }
        public void RetrieveBasicInformationTest_withValidID_AdditionalInfo()
        {
            // Arrange
            Weblink entry = new Weblink("_xxx");

            // Act
            int count = entry.RetrieveBasicInformation(false);

            // Assert
            Assert.AreEqual(1, count);

            Assert.AreEqual("_xxx", entry.ID);
            Assert.AreEqual("Weblink URL X", entry.Url);
            Assert.AreEqual("Weblink EnglishTitle X", entry.EnglishTitle);
            Assert.AreEqual("Weblink GermanTitle X", entry.GermanTitle);
            Assert.AreEqual("_xxx", entry.Language.ID);
            Assert.AreEqual("Weblink Details X", entry.Details);
            Assert.AreEqual("_xxx", entry.Status.ID);
            Assert.AreEqual("Weblink LastUpdated X", entry.LastUpdated);
        }
Exemplo n.º 11
0
    } // End of the constructor

    #endregion

    #region Insert methods

    /// <summary>
    /// Add one master post
    /// </summary>
    /// <param name="post">A reference to a weblink post</param>
    public static long AddMasterPost(Weblink post)
    {
        // Create the long to return
        long idOfInsert = 0;

        // Create the connection and the sql statement
        string connection = Tools.GetConnectionString();
        string sql = "INSERT INTO dbo.weblinks (rel, target) VALUES (@rel, @target);SELECT SCOPE_IDENTITY();";

        // 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("@rel", post.rel);
                cmd.Parameters.AddWithValue("@target", post.target);

                // 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
                    idOfInsert = Convert.ToInt64(cmd.ExecuteScalar());

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

        // Return the id of the inserted item
        return idOfInsert;

    } // End of the AddMasterPost method
Exemplo n.º 12
0
    } // End of the constructor

    #endregion

    #region Insert methods

    /// <summary>
    /// Add one master post
    /// </summary>
    /// <param name="post">A reference to a weblink post</param>
    public static long AddMasterPost(Weblink post)
    {
        // Create the long to return
        long idOfInsert = 0;

        // Create the connection and the sql statement
        string connection = Tools.GetConnectionString();
        string sql = "INSERT INTO dbo.weblinks (rel, target) VALUES (@rel, @target);SELECT SCOPE_IDENTITY();";

        // 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("@rel", post.rel);
                cmd.Parameters.AddWithValue("@target", post.target);

                // 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
                    idOfInsert = Convert.ToInt64(cmd.ExecuteScalar());

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

        // Return the id of the inserted item
        return idOfInsert;

    } // End of the AddMasterPost method
Exemplo n.º 13
0
    } // End of the UpdateMasterPost method

    /// <summary>
    /// Update a language post
    /// </summary>
    /// <param name="post">A reference to a post</param>
    /// <param name="languageId">A language id</param>
    public static void UpdateLanguagePost(Weblink post, int languageId)
    {
        // Create the connection and the sql statement
        string connection = Tools.GetConnectionString();
        string sql = "UPDATE dbo.weblinks_detail SET link_name = @link_name, url = @url, "
            + "inactive = @inactive WHERE weblink_id = @weblink_id AND language_id = @language_id;";

        // 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("@weblink_id", post.id);
                cmd.Parameters.AddWithValue("@language_id", languageId);
                cmd.Parameters.AddWithValue("@link_name", post.link_name);
                cmd.Parameters.AddWithValue("@url", post.url);
                cmd.Parameters.AddWithValue("@inactive", post.inactive);

                // 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 UpdateLanguagePost method
Exemplo n.º 14
0
    } // End of the AddMasterPost method

    /// <summary>
    /// Add one language post
    /// </summary>
    /// <param name="post">A reference to a weblink post</param>
    /// <param name="languageId">A language id</param>
    public static void AddLanguagePost(Weblink post, Int32 languageId)
    {
        // Create the connection and the sql statement
        string connection = Tools.GetConnectionString();
        string sql = "INSERT INTO dbo.weblinks_detail (weblink_id, language_id, link_name, url, inactive) "
            + "VALUES (@weblink_id, @language_id, @link_name, @url, @inactive);";

        // 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("@weblink_id", post.id);
                cmd.Parameters.AddWithValue("@language_id", languageId);
                cmd.Parameters.AddWithValue("@link_name", post.link_name);
                cmd.Parameters.AddWithValue("@url", post.url);
                cmd.Parameters.AddWithValue("@inactive", post.inactive);

                // 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 AddLanguagePost method
Exemplo n.º 15
0
    } // End of the AddLanguagePost method

    #endregion

    #region Update methods

    /// <summary>
    /// Update a master post
    /// </summary>
    /// <param name="post">A reference to a weblink post</param>
    public static void UpdateMasterPost(Weblink post)
    {
        // Create the connection and the sql statement
        string connection = Tools.GetConnectionString();
        string sql = "UPDATE dbo.weblinks SET rel = @rel, target = @target WHERE id = @id;";

        // 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("@id", post.id);
                cmd.Parameters.AddWithValue("@rel", post.rel);
                cmd.Parameters.AddWithValue("@target", post.target);

                // 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 UpdateMasterPost method
Exemplo n.º 16
0
 private void UpdateScriptWeblink()
 {
     script.Weblink w = new Weblink();
     w.ExportFile(m_oParentUser, this, m_lWeblink);
     WriteScriptData(definitions.path.DataWeblink, m_lWeblink);
 }
        public ActionResult translate(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", "Translator" }) == 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 admin default language
            Int32 adminLanguageId = currentDomain.back_end_language;

            // Get translated texts
            KeyStringList tt = StaticText.GetAll(adminLanguageId, "id", "ASC");

            // Get all the form values
            Int32 translationLanguageId = Convert.ToInt32(collection["selectLanguage"]);
            Int32 id = Convert.ToInt32(collection["hiddenWeblinkId"]);
            string link_name = collection["txtTranslatedLinkname"];
            string url = collection["txtTranslatedUrl"];
            bool inactive = Convert.ToBoolean(collection["cbInactive"]);

            // Create the translated weblink
            Weblink translatedWeblink = new Weblink();
            translatedWeblink.id = id;
            translatedWeblink.link_name = link_name;
            translatedWeblink.url = url;
            translatedWeblink.inactive = inactive;

            // Create a error message
            string errorMessage = string.Empty;

            // Check for errors
            if (translatedWeblink.link_name.Length > 100)
            {
                errorMessage += "&#149; " + String.Format(tt.Get("error_field_length"), tt.Get("link_name"), "100") + "<br/>";
            }
            if (translatedWeblink.url.Length > 100)
            {
                errorMessage += "&#149; " + String.Format(tt.Get("error_field_length"), tt.Get("url"), "100") + "<br/>";
            }

            // Check if there is errors
            if (errorMessage == string.Empty)
            {
                // Get the saved weblink
                Weblink weblink = Weblink.GetOneById(id, translationLanguageId);

                if (weblink == null)
                {
                    // Add a new translated weblink
                    Weblink.AddLanguagePost(translatedWeblink, translationLanguageId);
                }
                else
                {
                    // Update values for the saved weblink
                    weblink.link_name = translatedWeblink.link_name;
                    weblink.url = translatedWeblink.url;
                    weblink.inactive = translatedWeblink.inactive;

                    // Update the weblink translation
                    Weblink.UpdateLanguagePost(weblink, translationLanguageId);
                }

                // Redirect the user to the list
                return Redirect(returnUrl);
            }
            else
            {
                // Set form values
                ViewBag.LanguageId = translationLanguageId;
                ViewBag.Languages = Language.GetAll(adminLanguageId, "name", "ASC");
                ViewBag.StandardWeblink = Weblink.GetOneById(id, adminLanguageId);
                ViewBag.TranslatedWeblink = translatedWeblink;
                ViewBag.ErrorMessage = errorMessage;
                ViewBag.TranslatedTexts = tt;
                ViewBag.ReturnUrl = returnUrl;

                // Return the translate view
                return View("translate");
            }

        } // End of the translate method
        public ActionResult edit(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 all the form values
            Int32 id = Convert.ToInt32(collection["txtId"]);
            string link_name = collection["txtLinkname"];
            string url = collection["txtUrl"];
            string rel = collection["selectRelation"];
            string target = collection["selectTarget"];
            bool inactive = Convert.ToBoolean(collection["cbInactive"]);

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

            // Get translated texts
            KeyStringList tt = StaticText.GetAll(adminLanguageId, "id", "ASC");

            // Get the weblink
            Weblink weblink = Weblink.GetOneById(id, adminLanguageId);

            // Check if the weblink exists
            if (weblink == null)
            {
                // Create an empty weblink
                weblink = new Weblink();
            }

            // Update values
            weblink.rel = rel;
            weblink.target = target;
            weblink.link_name = link_name;
            weblink.url = url;
            weblink.inactive = inactive;

            // Create a error message
            string errorMessage = string.Empty;

            // Check for errors
            if (weblink.link_name.Length > 100)
            {
                errorMessage += "&#149; " + String.Format(tt.Get("error_field_length"), tt.Get("linkname"), "100") + "<br/>";
            }
            if (weblink.url.Length > 100)
            {
                errorMessage += "&#149; " + String.Format(tt.Get("error_field_length"), tt.Get("url"), "100") + "<br/>";
            }
            
            // Check if there is errors
            if (errorMessage == string.Empty)
            {
                // Check if we should add or update the weblink
                if (weblink.id == 0)
                {
                    // Add the weblink
                    Int64 insertId = Weblink.AddMasterPost(weblink);
                    weblink.id = Convert.ToInt32(insertId);
                    Weblink.AddLanguagePost(weblink, adminLanguageId);
                }
                else
                {
                    // Update the weblink
                    Weblink.UpdateMasterPost(weblink);
                    Weblink.UpdateLanguagePost(weblink, adminLanguageId);
                }

                // Redirect the user to the list
                return Redirect(returnUrl);
            }
            else
            {
                // Set form values
                ViewBag.ErrorMessage = errorMessage;
                ViewBag.Weblink = weblink;
                ViewBag.TranslatedTexts = tt;
                ViewBag.ReturnUrl = returnUrl;

                // Return the edit view
                return View("edit");
            }

        } // End of the edit method
Exemplo n.º 19
0
        public ActionResult Edit(int id = 0)
        {
            Weblink weblink = weblinkservice.Find(id);

            return(View(weblink));
        }
        public ActionResult delete(Int32 id = 0, string returnUrl = "/admin_weblinks")
        {
            // 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" }) == 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 language id
            int languageId = 0;
            if (Request.Params["lang"] != null)
            {
                Int32.TryParse(Request.Params["lang"], out languageId);
            }

            // Create an error code variable
            Int32 errorCode = 0;

            // Check if we should delete the full post or just the translation
            if (languageId == 0 || languageId == currentDomain.back_end_language)
            {
                // Delete the weblink and all the connected posts (CASCADE)
                errorCode = Weblink.DeleteOnId(id);
            }
            else
            {
                // Delete the translated weblink post
                errorCode = Weblink.DeleteLanguagePostOnId(id, languageId);
            }

            // Check if there is an error
            if (errorCode != 0)
            {
                ViewBag.AdminErrorCode = errorCode;
                ViewBag.TranslatedTexts = StaticText.GetAll(currentDomain.back_end_language, "id", "ASC");
                return View("index");
            }

            // Redirect the user to the list
            return Redirect(returnUrl);

        } // End of the delete method
Exemplo n.º 21
0
    } // End of the AddMasterPost method

    /// <summary>
    /// Add one language post
    /// </summary>
    /// <param name="post">A reference to a weblink post</param>
    /// <param name="languageId">A language id</param>
    public static void AddLanguagePost(Weblink post, Int32 languageId)
    {
        // Create the connection and the sql statement
        string connection = Tools.GetConnectionString();
        string sql = "INSERT INTO dbo.weblinks_detail (weblink_id, language_id, link_name, url, inactive) "
            + "VALUES (@weblink_id, @language_id, @link_name, @url, @inactive);";

        // 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("@weblink_id", post.id);
                cmd.Parameters.AddWithValue("@language_id", languageId);
                cmd.Parameters.AddWithValue("@link_name", post.link_name);
                cmd.Parameters.AddWithValue("@url", post.url);
                cmd.Parameters.AddWithValue("@inactive", post.inactive);

                // 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 AddLanguagePost method
Exemplo n.º 22
0
        public ViewResult Details(int id)
        {
            Weblink weblink = weblinkservice.Find(id);

            return(View(weblink));
        }
Exemplo n.º 23
0
    } // End of the AddLanguagePost method

    #endregion

    #region Update methods

    /// <summary>
    /// Update a master post
    /// </summary>
    /// <param name="post">A reference to a weblink post</param>
    public static void UpdateMasterPost(Weblink post)
    {
        // Create the connection and the sql statement
        string connection = Tools.GetConnectionString();
        string sql = "UPDATE dbo.weblinks SET rel = @rel, target = @target WHERE id = @id;";

        // 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("@id", post.id);
                cmd.Parameters.AddWithValue("@rel", post.rel);
                cmd.Parameters.AddWithValue("@target", post.target);

                // 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 UpdateMasterPost method
Exemplo n.º 24
0
    } // End of the UpdateMasterPost method

    /// <summary>
    /// Update a language post
    /// </summary>
    /// <param name="post">A reference to a post</param>
    /// <param name="languageId">A language id</param>
    public static void UpdateLanguagePost(Weblink post, int languageId)
    {
        // Create the connection and the sql statement
        string connection = Tools.GetConnectionString();
        string sql = "UPDATE dbo.weblinks_detail SET link_name = @link_name, url = @url, "
            + "inactive = @inactive WHERE weblink_id = @weblink_id AND language_id = @language_id;";

        // 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("@weblink_id", post.id);
                cmd.Parameters.AddWithValue("@language_id", languageId);
                cmd.Parameters.AddWithValue("@link_name", post.link_name);
                cmd.Parameters.AddWithValue("@url", post.url);
                cmd.Parameters.AddWithValue("@inactive", post.inactive);

                // 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 UpdateLanguagePost method
Exemplo n.º 25
0
    } // End of the MasterPostExists method

    /// <summary>
    /// Get one weblink based on id
    /// </summary>
    /// <param name="id">The id</param>
    /// <param name="languageId">The language id</param>
    /// <returns>A reference to a weblink post</returns>
    public static Weblink GetOneById(Int32 id, Int32 languageId)
    {
        // Create the post to return
        Weblink post = null;

        // Create the connection and the sql statement
        string connection = Tools.GetConnectionString();
        string sql = "SELECT * FROM dbo.weblinks_detail AS D INNER JOIN dbo.weblinks AS W ON D.weblink_id = W.id " 
            + "WHERE D.weblink_id = @id AND D.language_id = @language_id;";

        // 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("@id", id);
                cmd.Parameters.AddWithValue("@language_id", languageId);

                // 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 Weblink(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