private DiscountUntilExpired ReadDiscountUntilExpiredFromDatabase(int id)
 {
     using (SqlConnection connection = new SqlConnection(connectionString))
     {
         connection.Open();
         using (SqlCommand command = new SqlCommand("SELECT * FROM DiscountPolicies WHERE ID = " + id, connection))
         {
             IDataReader dr = command.ExecuteReader();
             if (dr.Read())
             {
                 DiscountUntilExpired discountUntilExpired = new DiscountUntilExpired();
                 discountUntilExpired.Id = (int) dr["ID"];
                 DateTime from = (DateTime) dr["FromTo_Start"];
                 DateTime to = (DateTime) dr["FromTo_End"];
                 discountUntilExpired.FromTo = new DateSpan {StartDate = from, EndDate = to};
                 Percentage percentage = new Percentage((int)dr["DiscountPercentage"]);
                 discountUntilExpired.DiscountPercentage = percentage;
                 return discountUntilExpired;
             }
             throw new ArgumentException("no id " + id + " found");
         }
     }
 }
 private PromoDay ReadPromoDayFromDatabase(int id)
 {
     using (SqlConnection connection = new SqlConnection(connectionString))
     {
         connection.Open();
         using (SqlCommand command = new SqlCommand("SELECT * FROM DiscountPolicies WHERE ID = " + id, connection))
         {
             IDataReader dr = command.ExecuteReader();
             if (dr.Read())
             {
                 PromoDay promoDay = new PromoDay();
                 promoDay.Id = (int)dr["ID"];
                 Percentage percentage = new Percentage((int)dr["DiscountPercentage"]);
                 promoDay.DiscountPercentage = percentage;
                 promoDay.DayDate = (DateTime)dr["DayDate"];
                 return promoDay;
             }
             throw new ArgumentException("no id " + id + " found");
         }
     }
 }
Esempio n. 3
0
 protected bool Equals(Percentage other)
 {
     return value == other.value;
 }