/// <summary>
        /// Persists a new instance of Discount. Returns true on success.
        /// </summary>
        /// <returns></returns>
        private bool Create()
        {
            this.discountGuid = Guid.NewGuid();

            int rowsAffected = DBDiscount.Create(
                this.discountGuid,
                this.discountCode,
                this.description,
                this.siteGuid,
                this.moduleGuid,
                this.storeGuid,
                this.offerGuid,
                this.validityStartDate,
                this.validityEndDate,
                this.useCount,
                this.maxCount,
                this.minOrderAmount,
                this.absoluteDiscount,
                this.percentageDiscount,
                this.allowOtherDiscounts,
                this.createdBy,
                this.createdUtc);

            return(rowsAffected > 0);
        }
Exemple #2
0
        /// <summary>
        /// Gets a discount
        /// </summary>
        /// <param name="DiscountID">Discount identifier</param>
        /// <returns>Discount</returns>
        public static Discount GetDiscountByID(int DiscountID)
        {
            if (DiscountID == 0)
            {
                return(null);
            }

            string key  = string.Format(DISCOUNTS_BY_ID_KEY, DiscountID);
            object obj2 = NopCache.Get(key);

            if (DiscountManager.CacheEnabled && (obj2 != null))
            {
                return((Discount)obj2);
            }

            DBDiscount dbItem = DBProviderManager <DBDiscountProvider> .Provider.GetDiscountByID(DiscountID);

            Discount discount = DBMapping(dbItem);

            if (DiscountManager.CacheEnabled)
            {
                NopCache.Max(key, discount);
            }
            return(discount);
        }
        private static Discount DBMapping(DBDiscount dbItem)
        {
            if (dbItem == null)
            {
                return(null);
            }

            var item = new Discount();

            item.DiscountId            = dbItem.DiscountId;
            item.DiscountTypeId        = dbItem.DiscountTypeId;
            item.DiscountRequirementId = dbItem.DiscountRequirementId;
            item.DiscountLimitationId  = dbItem.DiscountLimitationId;
            item.Name               = dbItem.Name;
            item.UsePercentage      = dbItem.UsePercentage;
            item.DiscountPercentage = dbItem.DiscountPercentage;
            item.DiscountAmount     = dbItem.DiscountAmount;
            item.StartDate          = dbItem.StartDate;
            item.EndDate            = dbItem.EndDate;
            item.RequiresCouponCode = dbItem.RequiresCouponCode;
            item.CouponCode         = dbItem.CouponCode;
            item.Deleted            = dbItem.Deleted;

            return(item);
        }
 /// <summary>
 /// Gets an instance of Discount.
 /// </summary>
 /// <param name="discountGuid"> discountGuid </param>
 private void GetDiscount(Guid moduleGuid, string discountCode)
 {
     using (IDataReader reader = DBDiscount.GetOne(moduleGuid, discountCode))
     {
         PopulateFromReader(reader);
     }
 }
 /// <summary>
 /// Gets an instance of Discount.
 /// </summary>
 /// <param name="discountGuid"> discountGuid </param>
 private void GetDiscount(Guid discountGuid)
 {
     using (IDataReader reader = DBDiscount.GetOne(discountGuid))
     {
         PopulateFromReader(reader);
     }
 }
        /// <summary>
        /// Gets an IDataReader with page of instances of Discount.
        /// </summary>
        /// <param name="pageNumber">The page number.</param>
        /// <param name="pageSize">Size of the page.</param>
        /// <param name="totalPages">total pages</param>
        public static IDataReader GetPage(
            Guid moduleGuid,
            int pageNumber,
            int pageSize,
            out int totalPages)
        {
            totalPages = 1;

            return(DBDiscount.GetPage(
                       moduleGuid,
                       pageNumber,
                       pageSize,
                       out totalPages));
        }
Exemple #7
0
 public void initial()
 {
     userService.testSetup();
     dbdiscount = DBDiscount.getInstance();
     //DBProduct.getInstance().initTests();
     //DBStore.getInstance().initTests();
     store1 = new Store("Makolet", "groceryStore");
     store2 = new Store("Apple", "apples");
     p1     = new Product("shirt", "clothing", 50, 4, 4, store1);
     store1.addProduct(p1);
     bamba = new Product("bamba", "food", 15, 5, 17, store1);
     store1.addProduct(bamba);
     bisli = new Product("bisli", "food", 20, 4, 50, store1);
     store1.addProduct(bisli);
 }
 /// <summary>
 /// Updates this instance of Discount. Returns true on success.
 /// </summary>
 /// <returns>bool</returns>
 private bool Update()
 {
     return(DBDiscount.Update(
                this.discountGuid,
                this.discountCode,
                this.description,
                this.offerGuid,
                this.validityStartDate,
                this.validityEndDate,
                this.useCount,
                this.maxCount,
                this.minOrderAmount,
                this.absoluteDiscount,
                this.percentageDiscount,
                this.allowOtherDiscounts,
                this.lastModBy,
                this.lastModUtc));
 }
Exemple #9
0
        /// <summary>
        /// Updates the discount
        /// </summary>
        /// <param name="DiscountID">Discount identifier</param>
        /// <param name="DiscountType">The discount type</param>
        /// <param name="DiscountRequirement">The discount requirement</param>
        /// <param name="Name">The name</param>
        /// <param name="UsePercentage">A value indicating whether to use percentage</param>
        /// <param name="DiscountPercentage">The discount percentage</param>
        /// <param name="DiscountAmount">The discount amount</param>
        /// <param name="StartDate">The discount start date and time</param>
        /// <param name="EndDate">The discount end date and time</param>
        /// <param name="RequiresCouponCode">The value indicating whether discount requires coupon code</param>
        /// <param name="CouponCode">The coupon code</param>
        /// <param name="Deleted">A value indicating whether the entity has been deleted</param>
        /// <returns>Discount</returns>
        public static Discount UpdateDiscount(int DiscountID, DiscountTypeEnum DiscountType,
                                              DiscountRequirementEnum DiscountRequirement, string Name, bool UsePercentage,
                                              decimal DiscountPercentage, decimal DiscountAmount, DateTime StartDate,
                                              DateTime EndDate, bool RequiresCouponCode, string CouponCode, bool Deleted)
        {
            if (StartDate.CompareTo(EndDate) >= 0)
            {
                throw new NopException("Start date should be less then expiration date");
            }

            //if ((DiscountType == DiscountTypeEnum.AssignedToWholeOrder) && !RequiresCouponCode)
            //{
            //    throw new NopException("Discounts assigned to whole order should require coupon code");
            //}

            //if ((DiscountType == DiscountTypeEnum.AssignedToWholeOrder)
            //    && RequiresCouponCode
            //    && String.IsNullOrEmpty(CouponCode))
            //{
            //    throw new NopException("Discounts assigned to whole order should require coupon code. Coupon code could not be empty.");
            //}

            if (RequiresCouponCode && String.IsNullOrEmpty(CouponCode))
            {
                throw new NopException("Discount requires coupon code. Coupon code could not be empty.");
            }

            DBDiscount dbItem = DBProviderManager <DBDiscountProvider> .Provider.UpdateDiscount(DiscountID, (int)DiscountType,
                                                                                                (int)DiscountRequirement, Name, UsePercentage, DiscountPercentage,
                                                                                                DiscountAmount, StartDate, EndDate,
                                                                                                RequiresCouponCode, CouponCode, Deleted);

            Discount discount = DBMapping(dbItem);

            if (DiscountManager.CacheEnabled)
            {
                NopCache.RemoveByPattern(DISCOUNTS_PATTERN_KEY);
            }
            return(discount);
        }
 /// <summary>
 /// Gets a count of rows in the ws_Discount table.
 /// </summary>
 public static int GetCountOfActiveDiscountCodes(Guid moduleGuid)
 {
     return(DBDiscount.GetCountOfActiveDiscountCodes(moduleGuid, DateTime.UtcNow));
 }
 /// <summary>
 /// Gets a count of rows in the ws_Discount table.
 /// </summary>
 public static int GetCountOfActiveDiscountCodes(Guid moduleGuid, DateTime activeForDate)
 {
     return(DBDiscount.GetCountOfActiveDiscountCodes(moduleGuid, activeForDate));
 }
 /// <summary>
 /// Gets a count of Discount.
 /// </summary>
 public static int GetCount(Guid moduleGuid)
 {
     return(DBDiscount.GetCount(moduleGuid));
 }
 /// <summary>
 /// Deletes instances of Discount. Returns true on success.
 /// </summary>
 /// <param name="discountGuid"> discountGuid </param>
 /// <returns>bool</returns>
 public static bool DeleteByOffer(Guid offerGuid)
 {
     return(DBDiscount.DeleteByOffer(offerGuid));
 }
 /// <summary>
 /// Deletes instances of Discount. Returns true on success.
 /// </summary>
 /// <param name="discountGuid"> discountGuid </param>
 /// <returns>bool</returns>
 public static bool DeleteByModule(Guid moduleGuid)
 {
     return(DBDiscount.DeleteByModule(moduleGuid));
 }
 /// <summary>
 /// Deletes instances of Discount. Returns true on success.
 /// </summary>
 /// <param name="discountGuid"> discountGuid </param>
 /// <returns>bool</returns>
 public static bool DeleteBySite(Guid siteGuid)
 {
     return(DBDiscount.DeleteBySite(siteGuid));
 }
 /// <summary>
 /// Deletes an instance of Discount. Returns true on success.
 /// </summary>
 /// <param name="discountGuid"> discountGuid </param>
 /// <returns>bool</returns>
 public static bool Delete(Guid discountGuid)
 {
     return(DBDiscount.Delete(discountGuid));
 }