Exemplo n.º 1
0
        public static List <CouponInfo> GetAllCoupon()
        {
            List <CouponInfo>  couponList     = new List <CouponInfo>();
            List <CouponItems> couponItemList = new List <CouponItems>();

            using (SqlDataReader reader = AdminDAL.GetCoupon(0))
            {
                while (reader.Read())
                {
                    CouponItems item = new CouponItems();
                    item.CouponId       = Convert.ToInt32(reader["CouponId"]);
                    item.SkuId          = Convert.ToInt32(reader["SkuId"]);
                    item.RelatedSkuId   = Convert.ToInt32(reader["RelatedSkuId"]);
                    item.DiscountAmount = Convert.ToDecimal(reader["DiscountAmount"]);
                    item.DiscountType   = (CouponTypeEnum)Convert.ToInt32(reader["DiscountType"]);

                    couponItemList.Add(item);
                }

                reader.NextResult();
                while (reader.Read())
                {
                    CouponInfo itemInfo = new CouponInfo();
                    itemInfo.CouponId     = Convert.ToInt32(reader["CouponId"]);
                    itemInfo.Title        = reader["Title"].ToString();
                    itemInfo.Discount     = Convert.ToDecimal(reader["Discount"]);
                    itemInfo.Active       = Convert.ToBoolean(reader["active"]);
                    itemInfo.DiscountType = (CouponTypeEnum)Convert.ToInt32(reader["DiscountType"]);
                    itemInfo.TotalAmount  = Convert.ToDecimal(reader["TotalAmount"]);
                    if (Convert.ToInt32(reader["DiscountType"]) == (int)CouponTypeEnum.ItemType)
                    {
                        itemInfo.ItemsDiscount = couponItemList.FindAll(x => x.CouponId == Convert.ToInt32(reader["CouponId"]));
                    }
                    if (reader["includeShipping"] != DBNull.Value)
                    {
                        itemInfo.IncludeShipping = Convert.ToBoolean(reader["includeShipping"]);
                    }
                    else
                    {
                        itemInfo.IncludeShipping = true;
                    }
                    couponList.Add(itemInfo);
                }
            }

            return(couponList);
        }
Exemplo n.º 2
0
        public static CouponInfo GetCoupon(int couponId)
        {
            CouponInfo         itemInfo    = new CouponInfo();
            List <CouponItems> couponItems = new List <CouponItems>();

            using (SqlDataReader reader = AdminDAL.GetCoupon(couponId))
            {
                while (reader.Read())
                {
                    CouponItems couponItemInfo = new CouponItems();
                    couponItemInfo.CouponId       = Convert.ToInt32(reader["CouponId"]);
                    couponItemInfo.SkuId          = Convert.ToInt32(reader["SkuId"]);
                    couponItemInfo.RelatedSkuId   = Convert.ToInt32(reader["RelatedSkuId"]);
                    couponItemInfo.DiscountAmount = Convert.ToDecimal(reader["DiscountAmount"]);
                    couponItemInfo.DiscountType   = (CouponTypeEnum)Convert.ToInt32(reader["DiscountType"]);
                    couponItems.Add(couponItemInfo);
                }

                reader.NextResult();
                while (reader.Read())
                {
                    itemInfo.CouponId     = Convert.ToInt32(reader["CouponId"]);
                    itemInfo.Title        = reader["Title"].ToString();
                    itemInfo.Discount     = Convert.ToDecimal(reader["Discount"]);
                    itemInfo.Active       = Convert.ToBoolean(reader["active"]);
                    itemInfo.TotalAmount  = Convert.ToDecimal(reader["TotalAmount"]);
                    itemInfo.DiscountType = (CouponTypeEnum)Convert.ToInt32(reader["DiscountType"]);
                    if (reader["includeShipping"] != DBNull.Value)
                    {
                        itemInfo.IncludeShipping = Convert.ToBoolean(reader["includeShipping"]);
                    }
                    else
                    {
                        itemInfo.IncludeShipping = true;
                    }
                    itemInfo.ItemsDiscount = couponItems;
                }
            }

            return(itemInfo);
        }