Example #1
0
        /// <summary>
        /// Delete a currency
        /// </summary>
        /// <param name="currencyId">currency external id</param>
        /// <param name="deletedBy">username of the deletor</param>
        /// <returns>true=currency deleted,false=currency not found</returns>
        public static bool DeleteCurrency(Guid currencyId, string deletedBy)
        {
            // Connect to the MSSQL database
            using (MSSqlConnection connection = MSSqlConnection.GetConnection())
            {
                // Get the table
                Table <CurrencyTable> currencies = connection.GetTable <CurrencyTable>();

                // Get the currency
                CurrencyTable currency = currencies.FirstOrDefault(x => x.ExternalId == currencyId && !x.Deleted);
                if (currency == null)
                {
                    return(false);
                }

                // Set the currency deleted state
                currency.Deleted = true;

                // Set the deleted by
                currency.DeletedBy = AccountsManager.GetAccountId(connection, deletedBy);

                // Submit the changes
                connection.SubmitChanges();

                // Currency set to deleted, return true
                return(true);
            }
        }
Example #2
0
        /// <summary>
        /// Delete a comment
        /// </summary>
        /// <param name="commentId">comment</param>
        /// <param name="deletedBy">username of the deletor</param>
        /// <returns>
        ///     true = deleted state changed
        ///     false = deleted state did not change
        /// </returns>
        public static bool DeleteComment(Guid commentId, string deletedBy)
        {
            // Connect to the MSSQL database
            using (MSSqlConnection connection = MSSqlConnection.GetConnection())
            {
                // Get the table
                Table <CurrencyCommentTable> comments = connection.GetTable <CurrencyCommentTable>();

                // Try to get the comment entry
                CurrencyCommentTable comment = comments.FirstOrDefault(x => x.ExternalId == commentId && !x.Deleted);
                if (comment == null)
                {
                    return(false); // Comment deleted state did not changed
                }
                // Set the comment deleted flag to true
                comment.Deleted = true;

                // Set the deleted by
                comment.DeletedBy = AccountsManager.GetAccountId(connection, deletedBy);

                // Submit the changes
                connection.SubmitChanges();

                // Comment deleted state changed, return true
                return(true);
            }
        }
Example #3
0
        /// <summary>
        /// Create a new currency
        /// </summary>
        /// <param name="displayName">display name</param>
        /// <param name="shortCode">short code</param>
        /// <param name="createdBy">creator username</param>
        /// <returns>currency external id</returns>
        public static Guid CreateCurrency(string displayName, string shortCode, string createdBy)
        {
            // Connect to the MSSQL database
            using (MSSqlConnection connection = MSSqlConnection.GetConnection())
            {
                // Check if the currency already exists
                if (CurrencyExists(displayName, shortCode))
                {
                    throw new InvalidOperationException("A currency with the same display name or shortcode already exists");
                }

                // Get the table
                Table <CurrencyTable> currencies = connection.GetTable <CurrencyTable>();

                // Create the external id for the currency
                Guid externalId = Guid.NewGuid();

                // Insert the new currency
                currencies.InsertOnSubmit(new CurrencyTable()
                {
                    ExternalId  = externalId,
                    DisplayName = displayName,
                    Symbol      = shortCode.ToUpper(),
                    Deleted     = false,
                    CreatedBy   = AccountsManager.GetAccountId(connection, createdBy),
                    DateCreated = DateTime.Now,
                });

                // Submit the changes
                connection.SubmitChanges();

                // Return the external id of the new currency
                return(externalId);
            }
        }
Example #4
0
        /// <summary>
        /// Create a new link category
        /// </summary>
        /// <param name="title">category title</param>
        /// <param name="createdBy">username of the creator</param>
        /// <returns>external category id</returns>
        public static Guid CreateLinkCategory(string title, string createdBy)
        {
            // Connect to the MSSQL database
            using (MSSqlConnection connection = MSSqlConnection.GetConnection())
            {
                // Get the tables
                Table <LinkCategoryTable> categories = connection.GetTable <LinkCategoryTable>();
                Table <AccountTable>      accounts   = connection.GetTable <AccountTable>();

                // Create the external id for the new category
                Guid externalId = Guid.NewGuid();

                // Insert the new category
                categories.InsertOnSubmit(new LinkCategoryTable()
                {
                    ExternalId  = externalId,
                    Title       = title,
                    CreatedBy   = AccountsManager.GetAccountId(connection, createdBy),
                    DateCreated = DateTime.Now,
                    Deleted     = false,
                });

                // Submit the changes
                connection.SubmitChanges();

                // Return the external id of the new category
                return(externalId);
            }
        }
Example #5
0
        /// <summary>
        /// Delete a link item
        /// </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 DeleteLinkItem(Guid categoryId, string deletedBy)
        {
            // Connect to the MSSQL database
            using (MSSqlConnection connection = MSSqlConnection.GetConnection())
            {
                // Get the table
                Table <LinkItemTable> items = connection.GetTable <LinkItemTable>();

                // Try to get the category item
                LinkItemTable item = items.FirstOrDefault(x => x.ExternalId == categoryId && !x.Deleted);
                if (item == null)
                {
                    return(false); // The deleted state did not changed, return false
                }
                // Set the deleted flag to true
                item.Deleted = true;

                // Set the deletor of the item
                item.DeletedBy = AccountsManager.GetAccountId(connection, deletedBy);

                // Submit the changes
                connection.SubmitChanges();

                // The deleted state changed, return true
                return(true);
            }
        }
Example #6
0
        /// <summary>
        /// Create a new comment
        /// </summary>
        /// <param name="currencyId">currency id</param>
        /// <param name="message">message</param>
        /// <param name="vote">vote</param>
        /// <param name="createdBy">username of the comment author</param>
        /// <returns>comment id</returns>
        public static Guid CreateComment(Guid currencyId, string message, int vote, string createdBy)
        {
            // Connect to the MSSQL database
            using (MSSqlConnection connection = MSSqlConnection.GetConnection())
            {
                // Get the tables
                Table <CurrencyTable>        currencies = connection.GetTable <CurrencyTable>();
                Table <CurrencyCommentTable> comments   = connection.GetTable <CurrencyCommentTable>();
                Table <AccountTable>         accounts   = connection.GetTable <AccountTable>();

                // Get the currency
                CurrencyTable currency = currencies.FirstOrDefault(x => x.ExternalId == currencyId && !x.Deleted);
                if (currency == null)
                {
                    throw new InvalidOperationException("Currency not found");
                }

                // Create the external id for the comment
                Guid externalId = Guid.NewGuid();

                // Insert the comment
                comments.InsertOnSubmit(new CurrencyCommentTable()
                {
                    ExternalId  = externalId,
                    Currency    = currency.Id,
                    Message     = message,
                    Vote        = vote,
                    CreatedBy   = AccountsManager.GetAccountId(connection, createdBy),
                    DateCreated = DateTime.Now,
                    Deleted     = false,
                });

                // Submit the changes
                connection.SubmitChanges();

                // Return the external id of the new comment
                return(externalId);
            }
        }
Example #7
0
        /// <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);
            }
        }