Esempio n. 1
0
        /// <summary>
        /// Returns true if the Ids of the two instances are equal.
        /// </summary>
        /// <param name="ObjectToCompare">The other object instance.</param>
        /// <returns>String</returns>
        public override Boolean Equals(Object ObjectToCompare)
        {
            if (ObjectToCompare == null)
            {
                return(false);
            }
            OrderDetailSubProductOption otherObject = ObjectToCompare as OrderDetailSubProductOption;

            if (otherObject == null)
            {
                return(false);
            }
            return(OrderDetailSubProductOption.Equals(this, otherObject));
        }
Esempio n. 2
0
    public OrderDetailSubProduct GetOrderDetailSubProduct()
    {
        Double productPrice = 0, toppingPrice = 0;
        bool   CalculateAdonPrice = false;

        #region Order Detail Sub Product

        OrderDetailSubProduct orderDetailSubProduct = new OrderDetailSubProduct();
        orderDetailSubProduct.ProductId     = ProductObject.ProductID;
        orderDetailSubProduct.Quantity      = 1;
        orderDetailSubProduct.ProductName   = ProductObject.Name;
        orderDetailSubProduct.RecipientName = txtRecipientName.Text.Trim();
        orderDetailSubProduct.Comments      = txtInstruction.Text;
        orderDetailSubProduct.OrderDetailSubProductAdons   = new List <OrderDetailSubProductAdon>();
        orderDetailSubProduct.OrderDetailSubProductOptions = new List <OrderDetailSubProductOption>();

        if (ProductObject.CategoryID == PizzaCategoryId)
        {
            orderDetailSubProduct.CrustType = (rblThinCrust.SelectedValue.ConvertToBool()) ? "Thin Crust" : "Regular";
        }


        #endregion

        foreach (RepeaterItem optionItem in rptOptions.Items)
        {
            #region Order Detail Sub Product Option

            #endregion
            HiddenField          OptionTypeID        = optionItem.FindControl("hdOptionTypeId") as HiddenField;
            OptionTypesInProduct optionTypeInProduct = ProductObject.OptionTypesInProductList.Where(ot => ot.OptionTypeID == Convert.ToInt16(OptionTypeID.Value)).FirstOrDefault();
            if (optionTypeInProduct.IsMultiSelect)
            {
                CheckBoxList chklist = optionItem.FindControl("CheckBoxList") as CheckBoxList;
                if (chklist != null)
                {
                    bool changePrice = true;
                    foreach (ListItem checkBox in chklist.Items)
                    {
                        if (checkBox.Selected)
                        {
                            ProductOptions productOption = optionTypeInProduct.ProductOptionsList.Where(po => po.OptionID == Convert.ToInt32(checkBox.Value)).First();
                            if (optionTypeInProduct.IsSamePrice && optionTypeInProduct.IsProductPriceChangeType)
                            {
                                if (changePrice)
                                {
                                    if (productPrice == 0)
                                    {
                                        productPrice = productOption.Price;
                                    }
                                    else
                                    {
                                        productPrice += productOption.Price;
                                    }
                                    changePrice = false;
                                }
                            }
                            else if (!optionTypeInProduct.IsSamePrice && optionTypeInProduct.IsProductPriceChangeType)
                            {
                                productPrice += productOption.Price;
                            }
                            else if (optionTypeInProduct.IsSamePrice)
                            {
                                productPrice += productOption.Price;
                            }
                            OrderDetailSubProductOption orderDetailSubProductOption = new OrderDetailSubProductOption();
                            orderDetailSubProductOption.ProductOptionId       = productOption.OptionID;
                            orderDetailSubProductOption.ProductOptionName     = productOption.OptionName;
                            orderDetailSubProductOption.Price                 = productOption.Price;
                            orderDetailSubProductOption.ProductOptionTypeName = optionTypeInProduct.OptionTypeName;
                            orderDetailSubProduct.OrderDetailSubProductOptions.Add(orderDetailSubProductOption);
                        }
                    }
                }
            }
            else
            {
                RadioButtonList radiolist = optionItem.FindControl("RadioButtonList") as RadioButtonList;
                if (radiolist != null && !String.IsNullOrEmpty(radiolist.SelectedValue))
                {
                    OrderDetailSubProductOption orderDetailSubProductOption = new OrderDetailSubProductOption();
                    if (optionTypeInProduct.IsSamePrice)
                    {
                        ProductOptions productOption = optionTypeInProduct.ProductOptionsList.Where(po => po.OptionID == Convert.ToInt32(radiolist.SelectedValue)).FirstOrDefault();
                        productPrice = optionTypeInProduct.ProductOptionsList[0].Price;
                        orderDetailSubProductOption.ProductOptionName     = productOption.OptionName;
                        orderDetailSubProductOption.ProductOptionTypeName = optionTypeInProduct.OptionTypeName;
                        CalculateAdonPrice = optionTypeInProduct.IsAdonPriceVary;
                    }
                    else
                    {
                        ProductOptions productOption = optionTypeInProduct.ProductOptionsList.Where(po => po.OptionID == Convert.ToInt32(radiolist.SelectedValue)).FirstOrDefault();

                        orderDetailSubProductOption.ProductOptionId       = productOption.OptionID;
                        orderDetailSubProductOption.ProductOptionName     = productOption.OptionName;
                        orderDetailSubProductOption.Price                 = productOption.Price;
                        orderDetailSubProductOption.Price                 = optionTypeInProduct.ProductOptionsList[0].Price;
                        orderDetailSubProductOption.ProductOptionTypeName = optionTypeInProduct.OptionTypeName;
                        CalculateAdonPrice = optionTypeInProduct.IsAdonPriceVary;
                    }
                    orderDetailSubProduct.OrderDetailSubProductOptions.Add(orderDetailSubProductOption);
                }
                else
                {
                    productPrice = ProductObject.UnitPrice;
                }
            }
            if (CalculateAdonPrice)
            {
                Int16 freeToppingCount = 0;
                foreach (RepeaterItem adonTypeItem in rptAdonsType.Items)
                {
                    HiddenField       hdAdonTypeId = adonTypeItem.FindControl("hdAdonTypeId") as HiddenField;
                    AdOnTypeInProduct adonType     = ProductObject.AdOnTypeInProductList.Where(at => at.AdonTypeID == Convert.ToInt16(hdAdonTypeId.Value)).FirstOrDefault();

                    Repeater rptAdons = adonTypeItem.FindControl("rptAdons") as Repeater;
                    foreach (RepeaterItem adonItem in rptAdons.Items)
                    {
                        Double      adonPrice = 0;
                        HiddenField hdAdonId  = adonItem.FindControl("hdAdonId") as HiddenField;
                        Adon        adon      = adonType.Adons.Where(a => a.AdOnID == Convert.ToInt32(hdAdonId.Value)).FirstOrDefault();

                        HiddenField SelectedSize   = adonItem.FindControl("SelectedSize") as HiddenField;
                        short       selectedoption = short.Parse(SelectedSize.Value);

                        CheckBox txtDouble = adonItem.FindControl("txtDouble") as CheckBox;

                        OrderDetailSubProductAdon orderDetailSubAdon = new OrderDetailSubProductAdon();
                        orderDetailSubAdon.AdOnId             = adon.AdOnID;
                        orderDetailSubAdon.AdonName           = adon.AdOnName;
                        orderDetailSubAdon.AdonTypeName       = adonType.AdOnTypeName;
                        orderDetailSubAdon.SelectedAdonOption = selectedoption;
                        orderDetailSubAdon.IsDoubleSelected   = txtDouble.Checked;
                        if (adon.DefaultSelected == 0 && (selectedoption == 1 || selectedoption == 2 || selectedoption == 3))
                        {       // When None was default selected and user has changed default selected option
                            if (!adonType.IsFreeAdonType)
                            {
                                if (txtDouble.Checked)
                                {
                                    if (freeToppingCount == ProductObject.NumberOfFreeTopping)
                                    {
                                        if (toppingPrice > 0)
                                        {
                                            adonPrice += 2 * toppingPrice;
                                        }
                                        else
                                        {
                                            adonPrice += (2 * Convert.ToDouble(adonType.Price));
                                        }
                                    }
                                    else
                                    {
                                        if (toppingPrice > 0)
                                        {
                                            productPrice += toppingPrice;
                                        }
                                        else
                                        {
                                            productPrice += Convert.ToDouble(adonType.Price);
                                        }
                                        freeToppingCount++;
                                    }
                                }
                                else
                                {
                                    if (freeToppingCount == ProductObject.NumberOfFreeTopping)
                                    {
                                        if (toppingPrice > 0)
                                        {
                                            productPrice            += toppingPrice;
                                            orderDetailSubAdon.Price = toppingPrice;
                                        }
                                        else
                                        {
                                            productPrice            += Convert.ToDouble(adonType.Price);
                                            orderDetailSubAdon.Price = Convert.ToDouble(adonType.Price);
                                        }
                                    }
                                    else
                                    {
                                        freeToppingCount++;
                                    }
                                }
                            }
                            orderDetailSubProduct.OrderDetailSubProductAdons.Add(orderDetailSubAdon);
                        }
                        else  // When other than None is pre selected and user has also selected Double check box
                        {
                            if (txtDouble.Checked && selectedoption != 0)
                            {
                                if (toppingPrice > 0)
                                {
                                    adonPrice += toppingPrice;
                                }
                                else
                                {
                                    adonPrice += Convert.ToDouble(adonType.Price);
                                }
                                orderDetailSubAdon.Price = adonPrice;
                                orderDetailSubProduct.OrderDetailSubProductAdons.Add(orderDetailSubAdon);
                            }
                            else
                            {
                                txtDouble.Checked = false;
                            }
                        }

                        productPrice += adonPrice;
                    }
                }
            } // CalculateAdonPrice
        }     // rptOptions

        orderDetailSubProduct.Price = productPrice;


        return(orderDetailSubProduct);
    }