public bool UpdateOfferById(SpecialOffer o)
 {
     try
     {
         SqlConnection cnn    = ReturnSQLConnection();
         string        query  = "UPDATE dbo.[SpecialOffer] SET Startdate=@Start, Enddate=@End, OfferPrice=@OfferPrice WHERE ProductID = @ProductId";
         SqlCommand    newCmd = CreateSQLCommandText(query, cnn);
         newCmd.Parameters.AddWithValue("@Start", o.StartTime);
         newCmd.Parameters.AddWithValue("@End", o.EndTime);
         newCmd.Parameters.AddWithValue("@OfferPrice", o.RetrieveOfferPrice());
         newCmd.Parameters.AddWithValue("@ProductId", o.RetrieveProductId());
         newCmd.ExecuteNonQuery();
         cnn.Close();
         return(true);
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message);
     }
     return(false);
 }
        public bool CreateNewSpecialOffer(SpecialOffer s)
        {
            try
            {
                SqlConnection cnn    = ReturnSQLConnection();
                string        query  = "INSERT INTO dbo.[SpecialOffer] (Startdate, Enddate, OfferPrice, ProductID) VALUES (@Startdate, @Enddate, @OfferPrice, @ProductId)";
                SqlCommand    newCmd = CreateSQLCommandText(query, cnn);
                newCmd.Parameters.AddWithValue("@Startdate", s.StartTime);
                newCmd.Parameters.AddWithValue("@Enddate", s.EndTime);
                newCmd.Parameters.AddWithValue("@OfferPrice", s.RetrieveOfferPrice());
                newCmd.Parameters.AddWithValue("@ProductId", s.RetrieveProductId());

                newCmd.ExecuteNonQuery();
                cnn.Close();
                return(true);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            return(false);
        }
        public bool UpdateOfferById(SpecialOffer o)
        {
            string sqlUserInsert = "UPDATE dbo.[SpecialOffer] SET Startdate=@Start, Enddate=@End, OfferPrice=@OfferPrice WHERE ProductID = @ProductId";

            using (SqlConnection connection = ReturnSQLConnection())
            {
                int affectedRows = connection.Execute(sqlUserInsert, new { Start = o.StartTime, End = o.EndTime, OfferPrice = o.RetrieveOfferPrice(), ProductId = o.RetrieveProductId() });
                return(true);
            }
        }
        public bool CreateNewSpecialOffer(SpecialOffer s)
        {
            string sqlUserInsert = "INSERT INTO dbo.[SpecialOffer] (Startdate, Enddate, OfferPrice, ProductID) VALUES (@Startdate, @Enddate, @OfferPrice, @ProductId)";

            using (SqlConnection connection = ReturnSQLConnection())
            {
                int affectedRows = connection.Execute(sqlUserInsert, new { Startdate = s.StartTime, Enddate = s.EndTime, OfferPrice = s.RetrieveOfferPrice(), ProductId = s.RetrieveOfferId() });
                return(true);
            }
        }
        public List <Product> RetrieveAllProducts()
        {
            List <Product>         listOfProducts = new List <Product>();
            SpecialOfferRepository offerRepo      = new SpecialOfferRepository(new SpecialOfferMssqlContext());

            try
            {
                SqlConnection cnn    = ReturnSQLConnection();
                string        query  = "SELECT * FROM dbo.[Product]";
                SqlCommand    newCmd = CreateSQLCommandText(query, cnn);
                SqlDataReader dr     = newCmd.ExecuteReader();
                while (dr.Read())
                {
                    int          productId   = Convert.ToInt32(dr["ID"]);
                    string       productName = dr["name"].ToString();
                    SpecialOffer offer       = offerRepo.RetrieveOfferByProductID(productId);

                    if (offer.RetrieveOfferId() != -1)
                    {
                        SpecialOffer product = new SpecialOffer(offer.RetrieveOfferId(), offer.RetrieveOfferPrice(), productId, productName);
                        product.ProductAmount   = Convert.ToInt32(dr["Amount"]);
                        product.ProductDesc     = dr["Description"].ToString();
                        product.ProductDiscount = Convert.ToDecimal(dr["Discount_Price"]);
                        product.ProductPrice    = Convert.ToDecimal(dr["Price"]);
                        product.ProductStatus   = dr["Status"].ToString();
                        product.ImageUrl        = dr["ImageURL"].ToString();
                        product.BtwPercentage   = Convert.ToInt32(dr["BTWPercentage"]);
                        product.ProductInStock  = Convert.ToInt32(dr["Instock"]);
                        product.StartTime       = offer.StartTime;
                        product.EndTime         = offer.EndTime;

                        listOfProducts.Add(product);
                    }
                    else
                    {
                        Product product = new Product(productId, productName);
                        product.ProductAmount   = Convert.ToInt32(dr["Amount"]);
                        product.ProductDesc     = dr["Description"].ToString();
                        product.ProductDiscount = Convert.ToDecimal(dr["Discount_Price"]);
                        product.ProductPrice    = Convert.ToDecimal(dr["Price"]);
                        product.ProductStatus   = dr["Status"].ToString();
                        product.ImageUrl        = dr["ImageURL"].ToString();
                        product.BtwPercentage   = Convert.ToInt32(dr["BTWPercentage"]);
                        product.ProductInStock  = Convert.ToInt32(dr["Instock"]);

                        listOfProducts.Add(product);
                    }
                }
                cnn.Close();
            }
            catch (NullReferenceException e)
            {
                Console.WriteLine(e.Message);
            }
            return(listOfProducts);
        }