Example #1
0
        public bool CheckEditOrCreate(Subscription input, SubscribedToCategory subCat)
        {
            bool wasSuccess = false;

            try
            {
                /*Since create and edit subscription was done in the samme window
                 * the program has to check if subscriptionID exists, if it does not
                 * exist (SubscripionID==0) then it creates a subscription*/
                if (input.SubscriptionID == 0)
                {
                    wasSuccess = CreateSubscription(input);
                    if (wasSuccess == true)
                    {
                        throw new SubscriptionWasAdded(input);
                    }
                }
                if (input.SubscriptionID > 0)
                {
                    wasSuccess = EditSubscription(input) || EditSubscriptionWCategory(subCat);
                    if (wasSuccess == true)
                    {
                        throw new SubscriptionWasEdited(input);
                    }
                }
                return(false);
            }
            catch (Exception ex)
            {
                Log.WriteEvent(ex);
                return(true);
            }
        }
Example #2
0
 // Made by Helena Brunsgaard Madsen
 public bool InsertSubscriptionWCategory(SubscribedToCategory input) //THIS IS THE RIGHT ONE!
 {
     if (input == null)
     {
         throw new ArgumentNullException(nameof(input));
     }
     try
     {
         SqlConnection con = new SqlConnection(DBOpenClose.conStr);
         DBOpenClose.OpenConnection(con);
         SqlCommand command = new SqlCommand(
             "INSERT INTO [SubscribedToCategories] (CategoryID, SubscriptionID) VALUES (@CategoryID, @SubscriptionID)" +
             "SELECT SubscriptionID FROM Subscription WHERE SubscriptionID=SubscriptionID " +
             "SELECT CategoryID FROM ProductCategories WHERE CategoryID=CategoryID", con);
         command.Parameters.Add("@CategoryID", SqlDbType.Int);
         command.Parameters["@CategoryID"].Value = input.CategoryID;
         command.Parameters.Add("@SubscriptionID", SqlDbType.Int);
         command.Parameters["@SubscriptionID"].Value = input.SubscriptionID;
         command.ExecuteNonQuery();
         DBOpenClose.CloseConnection(con);
         return(true);
     }
     catch (Exception ex)
     {
         SqlConnection con = new SqlConnection(DBOpenClose.conStr);
         DBOpenClose.CloseConnection(con);
         Log.WriteFail(ex);
         return(false);
     }
 }
Example #3
0
 public bool EditSubscriptionWCategory(SubscribedToCategory input)
 {
     if (input == null)
     {
         throw new ArgumentNullException(nameof(input));
     }
     try
     {
         SqlConnection con = new SqlConnection(DBOpenClose.conStr);
         DBOpenClose.OpenConnection(con);
         SqlCommand command = new SqlCommand(
             "UPDATE [SubscribedToCategories] SET CategoryID=@CategoryID " +
             "WHERE SubscriptionID=SubscriptionID", con);
         command.Parameters.Add("@CategoryID", SqlDbType.Int);
         command.Parameters["@CategoryID"].Value = input.CategoryID;
         command.Parameters.Add("@SubscriptionID", SqlDbType.Int);
         command.Parameters["@SubscriptionID"].Value = input.SubscriptionID;
         command.ExecuteNonQuery();
         DBOpenClose.CloseConnection(con);
         return(true);
     }
     catch (Exception ex)
     {
         SqlConnection con = new SqlConnection(DBOpenClose.conStr);
         DBOpenClose.CloseConnection(con);
         Log.WriteFail(ex);
         return(false);
     }
 }
Example #4
0
 public List <Categories> SelectSubscriptionwithCategory(int ID)
 {
     try
     {
         SqlConnection        con          = new SqlConnection(DBOpenClose.conStr);
         SubscribedToCategory output       = new SubscribedToCategory();
         List <Categories>    categoryList = new List <Categories>();
         DBOpenClose.OpenConnection(con);
         SqlCommand getSubscription = new SqlCommand(
             "SELECT * FROM [SubscribedToCategories] WHERE SubscriptionID=@SubscriptionID", con);
         getSubscription.Parameters.Add("@SubscriptionID", SqlDbType.Int);
         getSubscription.Parameters["@SubscriptionID"].Value = ID;
         SqlDataReader reader = getSubscription.ExecuteReader();
         while (reader.Read())
         {
             Categories subscribedToCategory = new Categories();
             subscribedToCategory.CategoryID = Convert.ToInt32(reader["CategoryID"]);
             categoryList.Add(subscribedToCategory);
         }
         DBOpenClose.CloseConnection(con);
         return(categoryList);
     }
     catch (Exception ex)
     {
         SqlConnection con = new SqlConnection(DBOpenClose.conStr);
         DBOpenClose.CloseConnection(con);
         List <Categories> categoryList = new List <Categories>();
         Log.WriteFail(ex);
         return(categoryList);
     }
 }
Example #5
0
 private bool CreateSubscriptionWCategory(SubscribedToCategory subCat)
 {
     try
     {
         return(subscriptionLogic.CreateSubscriptionWCategory(subCat));
     }
     catch (Exception ex)
     {
         ErrorHandler.Log.WriteFail(ex);
         CreateMessage.ShowInputNotValid();
         return(false);
     }
 }
Example #6
0
 public bool EditSubscriptionWCategory(SubscribedToCategory input)
 {
     return(DB.EditSubscriptionWCategory(input));
 }
Example #7
0
 public bool CreateSubscriptionWCategory(SubscribedToCategory input)
 {
     return(DB.InsertSubscriptionWCategory(input));
 }
Example #8
0
        // Made by Helena Madsen

        /// <summary>
        /// Inserts a subscription ID and Category ID into a database column containing foreign keys
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public static bool InsertSubscriptionWCategory(SubscribedToCategory input)
        {
            DBInsert dBInsert = new DBInsert();

            return(dBInsert.InsertSubscriptionWCategory(input));
        }
Example #9
0
        // Made by Helena Madsen
        /// <summary>
        /// Editing subscription from picked subscriptionID
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public static bool EditSubscriptionWCategory(SubscribedToCategory input)
        {
            DBEdit dBEdit = new DBEdit();

            return(dBEdit.EditSubscriptionWCategory(input));
        }