Пример #1
0
        public double GetTotal()
        {
            double total = 0;

            foreach (entities.interfaces.CartElement product in GetElements())
            {
                total += product.GetPrice() * product.GetCartCount();
            }

            double returnTotal = 0;

            if (discount != null && total > 0)
            {
                returnTotal = total - (total * discount.GetDiscount() / 100);
            }
            else
            {
                returnTotal = total;
            }

            return(rounder.Round(returnTotal));
        }
Пример #2
0
        public int SaveWithSql(entities.Discount discount)
        {
            entities.Discount hasDiscount = FindOne(discount.GetId());

            SQLiteCommand command;

            if (discount.GetId() == 0 | hasDiscount == null)
            {
                Add(discount);
                command = new SQLiteCommand("INSERT INTO discount(code, discount) VALUES(@code, @discount)", db.connection);
            }
            else
            {
                command = new SQLiteCommand("UPDATE discount SET code = @code, discount = @discount WHERE id = @id ", db.connection);
            }

            command.Parameters.AddWithValue("@id", discount.GetId());
            command.Parameters.AddWithValue("@code", discount.GetCode());
            command.Parameters.AddWithValue("@discount", discount.GetDiscount());

            int num = command.ExecuteNonQuery();

            return(num);
        }