Пример #1
0
        private void LoadDiscounts()
        {
            List <Discount> discounts = DiscountCollection.GetAll(StoreContext.CurrentStore.Id.Value);

            rptDiscounts.DataSource = discounts;
            rptDiscounts.DataBind();
        }
        public async Task <JObject> Create(Discount item)
        {
            try
            {
                await DiscountCollection.InsertOneAsync(item);

                return
                    (JObject.FromObject(
                         new
                {
                    status = "success",
                    result = item
                }
                         ));
            }
            catch (Exception ex)
            {
                return
                    (JObject.FromObject(
                         new
                {
                    status = "Exception Thrown",
                    result = false,
                    message = ex.Message
                }
                         ));
            }
        }
Пример #3
0
        void BindGrid()
        {
            DiscountCollection discountCollection = DiscountManager.GetAllDiscounts(null);

            gvDiscounts.DataSource = discountCollection;
            gvDiscounts.DataBind();
        }
 public JObject Get()
 {
     try
     {
         List <Discount> collection = DiscountCollection.Find(new BsonDocument()).ToList();
         JObject         returnJson = JObject.FromObject(
             new
         {
             status = "success",
             result = collection
         }
             );
         return(returnJson);
     }
     catch (Exception ex)
     {
         return
             (JObject.FromObject(
                  new
         {
             status = "Exception Thrown",
             result = false,
             message = ex.Message
         }
                  ));
     }
 }
 public JObject Get(ObjectId itemId)
 {
     try
     {
         var queryableDiscount = DiscountCollection.AsQueryable();
         var queryOffer        = from d in queryableDiscount
                                 where d.Id.Equals(itemId)
                                 select d;
         var discount = queryableDiscount.First();
         return
             (JObject.FromObject(
                  new
         {
             status = "success",
             result = discount
         }
                  ));
     }
     catch (Exception ex)
     {
         return
             (JObject.FromObject(
                  new
         {
             status = "Exception Thrown",
             result = false,
             message = ex.Message
         }
                  ));
     }
 }
Пример #6
0
        /// <summary>
        /// Gets a preferred discount
        /// </summary>
        /// <param name="productVariant">Product variant</param>
        /// <param name="customer">Customer</param>
        /// <param name="AdditionalCharge">Additional charge</param>
        /// <returns>Preferred discount</returns>
        protected static Discount GetPreferredDiscount(ProductVariant productVariant, Customer customer, decimal AdditionalCharge)
        {
            DiscountCollection allowedDiscounts          = GetAllowedDiscounts(productVariant, customer);
            decimal            finalPriceWithoutDiscount = GetFinalPrice(productVariant, customer, AdditionalCharge, false);
            Discount           preferredDiscount         = DiscountManager.GetPreferredDiscount(allowedDiscounts, finalPriceWithoutDiscount);

            return(preferredDiscount);
        }
Пример #7
0
        protected override async Task <bool> GetDataAsync()
        {
            var resource = new DiscountResource(Context, DataViewMode.HasValue ? DataViewMode.Value : Api.DataViewMode.Live);

            _results = await resource.GetDiscountsAsync(startIndex : StartIndex, pageSize : PageSize, sortBy : SortBy, filter : Filter, responseFields : ResponseFields);

            TotalCount = _results.TotalCount;
            PageCount  = _results.PageCount;
            PageSize   = _results.PageSize;
            return(_results.Items != null && _results.Items.Count > 0);
        }
Пример #8
0
        /// <summary>
        /// Gets allowed discounts
        /// </summary>
        /// <param name="productVariant">Product variant</param>
        /// <param name="customer">Customer</param>
        /// <returns>Discounts</returns>
        protected static DiscountCollection GetAllowedDiscounts(ProductVariant productVariant, Customer customer)
        {
            var allowedDiscounts = new DiscountCollection();

            string customerCouponCode = string.Empty;

            if (customer != null)
            {
                customerCouponCode = customer.LastAppliedCouponCode;
            }

            foreach (var _discount in productVariant.AllDiscounts)
            {
                if (_discount.IsActive(customerCouponCode) &&
                    _discount.DiscountType == DiscountTypeEnum.AssignedToSKUs &&
                    !allowedDiscounts.ContainsDiscount(_discount.Name))
                {
                    //discount requirements
                    if (_discount.CheckDiscountRequirements(customer) &&
                        _discount.CheckDiscountLimitations(customer))
                    {
                        allowedDiscounts.Add(_discount);
                    }
                }
            }

            var productCategories = CategoryManager.GetProductCategoriesByProductId(productVariant.ProductId);

            foreach (var _productCategory in productCategories)
            {
                var category = _productCategory.Category;
                if (category != null)
                {
                    foreach (var _discount in category.Discounts)
                    {
                        if (_discount.IsActive(customerCouponCode) &&
                            _discount.DiscountType == DiscountTypeEnum.AssignedToSKUs &&
                            !allowedDiscounts.ContainsDiscount(_discount.Name))
                        {
                            //discount requirements
                            if (_discount.CheckDiscountRequirements(customer) &&
                                _discount.CheckDiscountLimitations(customer))
                            {
                                allowedDiscounts.Add(_discount);
                            }
                        }
                    }
                }
            }
            return(allowedDiscounts);
        }
Пример #9
0
        private static DiscountCollection DBMapping(DBDiscountCollection dbCollection)
        {
            if (dbCollection == null)
                return null;

            DiscountCollection collection = new DiscountCollection();
            foreach (DBDiscount dbItem in dbCollection)
            {
                Discount item = DBMapping(dbItem);
                collection.Add(item);
            }

            return collection;
        }
        public void BindData(DiscountTypeEnum?DiscountType)
        {
            DiscountCollection discountCollection = DiscountManager.GetAllDiscounts(DiscountType);

            foreach (Discount discount in discountCollection)
            {
                ListItem item = new ListItem(discount.Name, discount.DiscountID.ToString());
                if (this.selectedDiscountIDs.Contains(discount.DiscountID))
                {
                    item.Selected = true;
                }
                this.cblDiscounts.Items.Add(item);
            }
            this.cblDiscounts.DataBind();
        }
Пример #11
0
        private void BindData()
        {
            Category category = CategoryManager.GetCategoryByID(this.CategoryID);

            if (category != null)
            {
                DiscountCollection discountCollection = category.Discounts;
                List <int>         _discountIDs       = new List <int>();
                foreach (Discount dis in discountCollection)
                {
                    _discountIDs.Add(dis.DiscountID);
                }
                DiscountMappingControl.SelectedDiscountIDs = _discountIDs;
                DiscountMappingControl.BindData(DiscountTypeEnum.AssignedToSKUs);
            }
        }
        private void BindData()
        {
            ProductVariant productVariant = ProductManager.GetProductVariantByID(this.ProductVariantID);

            if (productVariant != null)
            {
                DiscountCollection discountCollection = productVariant.AllDiscounts;
                List <int>         _discountIDs       = new List <int>();
                foreach (Discount dis in discountCollection)
                {
                    _discountIDs.Add(dis.DiscountID);
                }
                DiscountMappingControl.SelectedDiscountIDs = _discountIDs;
                DiscountMappingControl.BindData(DiscountTypeEnum.AssignedToSKUs);
            }
        }
        public async Task <JObject> Delete(string itemId)
        {
            try
            {
                var filter = Builders <Discount> .Filter.Eq("_id", ObjectId.Parse(itemId));

                DeleteResult result = await DiscountCollection.DeleteOneAsync(filter);

                if (result.IsAcknowledged)
                {
                    return
                        (JObject.FromObject(
                             new
                    {
                        status = "success",
                        result = true,
                        message = "Discount was deleted"
                    }
                             ));
                }
                else
                {
                    return
                        (JObject.FromObject(
                             new
                    {
                        status = "false",
                        result = false,
                        message = "Discount could not be deleted"
                    }
                             ));
                }
            }
            catch (Exception ex)
            {
                return
                    (JObject.FromObject(
                         new
                {
                    status = "Exception Thrown",
                    result = false,
                    message = ex.Message
                }
                         ));
            }
        }
Пример #14
0
        /// <summary>
        /// Gets a shipping discount
        /// </summary>
        /// <param name="customer">Customer</param>
        /// <param name="shippingTotal">Shipping total</param>
        /// <param name="appliedDiscount">Applied discount</param>
        /// <returns>Shipping discount</returns>
        public static decimal GetShippingDiscount(Customer customer,
                                                  decimal shippingTotal, out Discount appliedDiscount)
        {
            decimal shippingDiscountAmount = decimal.Zero;

            string customerCouponCode = string.Empty;

            if (customer != null)
            {
                customerCouponCode = customer.LastAppliedCouponCode;
            }

            var allDiscounts     = DiscountManager.GetAllDiscounts(DiscountTypeEnum.AssignedToShipping);
            var allowedDiscounts = new DiscountCollection();

            foreach (var _discount in allDiscounts)
            {
                if (_discount.IsActive(customerCouponCode) &&
                    _discount.DiscountType == DiscountTypeEnum.AssignedToShipping &&
                    !allowedDiscounts.ContainsDiscount(_discount.Name))
                {
                    //discount requirements
                    if (_discount.CheckDiscountRequirements(customer) &&
                        _discount.CheckDiscountLimitations(customer))
                    {
                        allowedDiscounts.Add(_discount);
                    }
                }
            }

            appliedDiscount = DiscountManager.GetPreferredDiscount(allowedDiscounts, shippingTotal);
            if (appliedDiscount != null)
            {
                shippingDiscountAmount = appliedDiscount.GetDiscountAmount(shippingTotal);
            }

            if (shippingDiscountAmount < decimal.Zero)
            {
                shippingDiscountAmount = decimal.Zero;
            }

            shippingDiscountAmount = Math.Round(shippingDiscountAmount, 2);

            return(shippingDiscountAmount);
        }
        /// <summary>
        /// Gets an order discount
        /// </summary>
        /// <param name="customer">Customer</param>
        /// <param name="orderSubTotal">Order subtotal</param>
        /// <returns>Order discount</returns>
        public static decimal GetOrderDiscount(Customer customer, decimal orderSubTotal)
        {
            decimal SubTotalDiscount = decimal.Zero;
            int     customerID       = 0;

            if (customer != null)
            {
                customerID = customer.CustomerID;
            }

            string customerCouponCode = string.Empty;

            if (customer != null)
            {
                customerCouponCode = customer.LastAppliedCouponCode;
            }

            DiscountCollection allDiscounts     = DiscountManager.GetAllDiscounts(DiscountTypeEnum.AssignedToWholeOrder);
            DiscountCollection allowedDiscounts = new DiscountCollection();

            foreach (Discount _discount in allDiscounts)
            {
                if (_discount.IsActive(customerCouponCode) &&
                    _discount.DiscountType == DiscountTypeEnum.AssignedToWholeOrder &&
                    !allowedDiscounts.ContainsDiscount(_discount.Name))
                {
                    switch (_discount.DiscountRequirement)
                    {
                    case DiscountRequirementEnum.None:
                    {
                        allowedDiscounts.Add(_discount);
                    }
                    break;

                    case DiscountRequirementEnum.MustBeAssignedToCustomerRole:
                    {
                        if (_discount.CheckCustomerRoleRequirement(customerID))
                        {
                            allowedDiscounts.Add(_discount);
                        }
                    }
                    break;

                    default:
                        break;
                    }
                }
            }

            Discount preferredDiscount = DiscountManager.GetPreferredDiscount(allowedDiscounts, orderSubTotal);

            if (preferredDiscount != null)
            {
                SubTotalDiscount = preferredDiscount.GetDiscountAmount(orderSubTotal);
            }

            if (SubTotalDiscount < decimal.Zero)
            {
                SubTotalDiscount = decimal.Zero;
            }

            SubTotalDiscount = Math.Round(SubTotalDiscount, 2);

            return(SubTotalDiscount);
        }
Пример #16
0
        /// <summary>
        /// Gets a preferred discount
        /// </summary>
        /// <param name="Discounts">Discounts to analyze</param>
        /// <param name="Amount">Amount</param>
        /// <returns>Preferred discount</returns>
        public static Discount GetPreferredDiscount(DiscountCollection Discounts, decimal Amount)
        {
            Discount preferredDiscount = null;
            decimal maximumDiscountValue = decimal.Zero;
            foreach (Discount _discount in Discounts)
            {
                decimal currentDiscountValue = _discount.GetDiscountAmount(Amount);
                if (currentDiscountValue > maximumDiscountValue)
                {
                    maximumDiscountValue = currentDiscountValue;
                    preferredDiscount = _discount;
                }
            }

            return preferredDiscount;
        }
Пример #17
0
        public async Task <JObject> RemoveDiscountFromOffer(string offerId, string discountId)
        {
            try
            {
                //get discount
                var discountQueryable = DiscountCollection.AsQueryable();
                var discountQuery     = from d in discountQueryable
                                        where d.Id.Equals(ObjectId.Parse(discountId))
                                        select d;
                Discount discount = discountQuery.First();

                //get Offer
                Offers          offer     = GetOfferById(offerId);
                List <Discount> discounts = offer.Discounts;
                if (discounts.Contains(discount))
                {
                    discounts.Remove(discount);

                    var filter = Builders <Offers> .Filter.Eq("_id", ObjectId.Parse(offerId));

                    var update = Builders <Offers> .Update.Set("Discounts", discounts);

                    UpdateResult result = await OffersCollection.UpdateOneAsync(filter, update);

                    if (result.IsModifiedCountAvailable)
                    {
                        return
                            (JObject.FromObject(
                                 new
                        {
                            status = "success",
                            result = true,
                            message = "Added Discount to Offer"
                        }
                                 ));
                    }
                    else
                    {
                        return
                            (JObject.FromObject(
                                 new
                        {
                            status = "false",
                            result = false,
                            message = "Could not add Discount to Offer"
                        }
                                 ));
                    }
                }
                else
                {
                    return
                        (JObject.FromObject(
                             new
                    {
                        status = "false",
                        result = false,
                        message = "That offer does not contain this discount"
                    }
                             ));
                }
            }
            catch (Exception ex)
            {
                return
                    (JObject.FromObject(
                         new
                {
                    status = "Exception Thrown",
                    result = false,
                    message = ex.Message
                }
                         ));
            }
        }
Пример #18
0
        /// <summary>
        /// Gets allowed discounts
        /// </summary>
        /// <param name="productVariant">Product variant</param>
        /// <param name="customer">Customer</param>
        /// <returns>Discounts</returns>
        protected static DiscountCollection GetAllowedDiscounts(ProductVariant productVariant, Customer customer)
        {
            int customerID = 0;

            if (customer != null)
            {
                customerID = customer.CustomerID;
            }

            DiscountCollection allowedDiscounts = new DiscountCollection();

            //CustomerRoleCollection customerRoles = CustomerManager.GetCustomerRolesByCustomerID(customerID);
            //foreach (CustomerRole _customerRole in customerRoles)
            //    foreach (Discount _discount in _customerRole.Discounts)
            //        if (_discount.IsActive && _discount.DiscountType == DiscountTypeEnum.AssignedToSKUs && !allowedDiscounts.ContainsDiscount(_discount.Name))
            //            allowedDiscounts.Add(_discount);

            string customerCouponCode = string.Empty;

            if (customer != null)
            {
                customerCouponCode = customer.LastAppliedCouponCode;
            }

            foreach (Discount _discount in productVariant.AllDiscounts)
            {
                if (_discount.IsActive(customerCouponCode) &&
                    _discount.DiscountType == DiscountTypeEnum.AssignedToSKUs &&
                    !allowedDiscounts.ContainsDiscount(_discount.Name))
                {
                    switch (_discount.DiscountRequirement)
                    {
                    case DiscountRequirementEnum.None:
                    {
                        allowedDiscounts.Add(_discount);
                    }
                    break;

                    case DiscountRequirementEnum.MustBeAssignedToCustomerRole:
                    {
                        if (_discount.CheckCustomerRoleRequirement(customerID))
                        {
                            allowedDiscounts.Add(_discount);
                        }
                    }
                    break;

                    default:
                        break;
                    }
                }
            }

            ProductCategoryCollection productCategories = CategoryManager.GetProductCategoriesByProductID(productVariant.ProductID);

            foreach (ProductCategory _productCategory in productCategories)
            {
                Category category = _productCategory.Category;
                if (category != null)
                {
                    foreach (Discount _discount in category.Discounts)
                    {
                        if (_discount.IsActive(customerCouponCode) &&
                            _discount.DiscountType == DiscountTypeEnum.AssignedToSKUs &&
                            !allowedDiscounts.ContainsDiscount(_discount.Name))
                        {
                            switch (_discount.DiscountRequirement)
                            {
                            case DiscountRequirementEnum.None:
                            {
                                allowedDiscounts.Add(_discount);
                            }
                            break;

                            case DiscountRequirementEnum.MustBeAssignedToCustomerRole:
                            {
                                allowedDiscounts.Add(_discount);
                            }
                            break;

                            default:
                                break;
                            }
                        }
                    }
                }
            }
            return(allowedDiscounts);
        }
Пример #19
0
        /// <summary>
        /// Gets allowed discounts
        /// </summary>
        /// <param name="productVariant">Product variant</param>
        /// <param name="customer">Customer</param>
        /// <returns>Discounts</returns>
        protected static DiscountCollection GetAllowedDiscounts(ProductVariant productVariant, Customer customer)
        {
            int customerID = 0;
            if (customer != null)
                customerID = customer.CustomerID;

            DiscountCollection allowedDiscounts = new DiscountCollection();

            //CustomerRoleCollection customerRoles = CustomerManager.GetCustomerRolesByCustomerID(customerID);
            //foreach (CustomerRole _customerRole in customerRoles)
            //    foreach (Discount _discount in _customerRole.Discounts)
            //        if (_discount.IsActive && _discount.DiscountType == DiscountTypeEnum.AssignedToSKUs && !allowedDiscounts.ContainsDiscount(_discount.Name))
            //            allowedDiscounts.Add(_discount);

            string customerCouponCode = string.Empty;
            if (customer != null)
                customerCouponCode = customer.LastAppliedCouponCode;

            foreach (Discount _discount in productVariant.AllDiscounts)
            {
                if (_discount.IsActive(customerCouponCode) &&
                    _discount.DiscountType == DiscountTypeEnum.AssignedToSKUs &&
                    !allowedDiscounts.ContainsDiscount(_discount.Name))
                {
                    switch (_discount.DiscountRequirement)
                    {
                        case DiscountRequirementEnum.None:
                            {
                                allowedDiscounts.Add(_discount);
                            }
                            break;
                        case DiscountRequirementEnum.MustBeAssignedToCustomerRole:
                            {
                                if (_discount.CheckCustomerRoleRequirement(customerID))
                                    allowedDiscounts.Add(_discount);
                            }
                            break;
                        default:
                            break;
                    }
                }
            }

            ProductCategoryCollection productCategories = CategoryManager.GetProductCategoriesByProductID(productVariant.ProductID);
            foreach (ProductCategory _productCategory in productCategories)
            {
                Category category = _productCategory.Category;
                if (category != null)
                {
                    foreach (Discount _discount in category.Discounts)
                    {
                        if (_discount.IsActive(customerCouponCode) &&
                            _discount.DiscountType == DiscountTypeEnum.AssignedToSKUs &&
                            !allowedDiscounts.ContainsDiscount(_discount.Name))
                        {
                            switch (_discount.DiscountRequirement)
                            {
                                case DiscountRequirementEnum.None:
                                    {
                                        allowedDiscounts.Add(_discount);
                                    }
                                    break;
                                case DiscountRequirementEnum.MustBeAssignedToCustomerRole:
                                    {
                                        allowedDiscounts.Add(_discount);
                                    }
                                    break;
                                default:
                                    break;
                            }
                        }
                    }
                }
            }
            return allowedDiscounts;
        }