/// <summary> /// Delete a link category /// </summary> /// <param name="categoryId">category id</param> /// <param name="deletedBy">username of the deletor</param> /// <returns> /// true = deleted state changed /// false = deleted state did not change /// </returns> public static bool DeleteLinkCategory(Guid categoryId, string deletedBy) { // Connect to the MSSQL database using (MSSqlConnection connection = MSSqlConnection.GetConnection()) { // Get the table Table <LinkCategoryTable> categories = connection.GetTable <LinkCategoryTable>(); // Try to get the category entry LinkCategoryTable category = categories.FirstOrDefault(x => x.ExternalId == categoryId && !x.Deleted); if (category == null) { return(false); // The deleted state did not changed, return false } // Set the deleted flag to true category.Deleted = true; // Set the deletor of the category category.DeletedBy = AccountsManager.GetAccountId(connection, deletedBy); // Submit the changes connection.SubmitChanges(); // The deleted state changed, return true return(true); } }
/// <summary> /// Create a new link item /// </summary> /// <param name="categoryId"></param> /// <param name="title"></param> /// <param name="url"></param> /// <param name="createdBy"></param> /// <returns></returns> public static Guid CreateLinkItem(Guid categoryId, string title, string url, string createdBy) { // Connect to the MSSQL database using (MSSqlConnection connection = MSSqlConnection.GetConnection()) { // Get the tables Table <LinkCategoryTable> categories = connection.GetTable <LinkCategoryTable>(); Table <LinkItemTable> items = connection.GetTable <LinkItemTable>(); // Try to get the category entry LinkCategoryTable category = categories.FirstOrDefault(x => x.ExternalId == categoryId && !x.Deleted); if (category == null) { throw new Exception("Category not found"); } // Create the external id for the new link item Guid externalId = Guid.NewGuid(); // Insert the new item items.InsertOnSubmit(new LinkItemTable() { Category = category.Id, ExternalId = externalId, Title = title, Url = url, CreatedBy = AccountsManager.GetAccountId(connection, createdBy), DateCreated = DateTime.Now, Deleted = false, }); // Submit the changes connection.SubmitChanges(); // Return the external id of the new item return(externalId); } }