Пример #1
0
        public JsonResult GetProductAttributes(string category)
        {
            List <GbMAttributes>     listGbMAttributes = null;
            List <FSCFoodAttributes> objFoodAttributes = new List <FSCFoodAttributes>();

            try
            {
                int categoryId = 0;
                listGbMAttributes = new List <GbMAttributes>();
                try
                {
                    Int32.TryParse(category, out categoryId);
                }
                catch (Exception exc)
                {
                    categoryId = 0;
                }
                listGbMAttributes = new ClsCommon().GetFoodAttributes(0, categoryId, "");
                if (listGbMAttributes != null && listGbMAttributes.Count > 0)
                {
                    var grpAttributes = listGbMAttributes.GroupBy(n => new { n.AttributeGroupCode, n.AttributeGroupDesc })
                                        .Select(g => new
                    {
                        g.Key.AttributeGroupCode,
                        g.Key.AttributeGroupDesc
                    }).ToList();
                    foreach (var attr in grpAttributes)
                    {
                        FSCFoodAttributes fscAttribute = new FSCFoodAttributes();
                        fscAttribute.AttributeGroupCode = attr.AttributeGroupCode;
                        fscAttribute.AttributeGroupDesc = attr.AttributeGroupDesc;
                        List <FSCFoodAttributeValues> attributeValuesList = new List <FSCFoodAttributeValues>();
                        foreach (var att in listGbMAttributes)
                        {
                            if (att.AttributeGroupCode == attr.AttributeGroupCode)
                            {
                                FSCFoodAttributeValues attValue = new FSCFoodAttributeValues();
                                attValue.AttributeId        = att.AttributeId;
                                attValue.AttributeValue     = att.AttributeValue;
                                attValue.AttributeGroupCode = att.AttributeGroupCode;
                                attValue.AttributeGroupDesc = att.AttributeGroupDesc;
                                attributeValuesList.Add(attValue);
                            }
                        }
                        fscAttribute.FoodAttributes = attributeValuesList;
                        objFoodAttributes.Add(fscAttribute);
                    }
                }
                return(Json(objFoodAttributes));
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                listGbMAttributes = null;
            }
        }
        private void GetFoodProductViewBagData(Int64 productId, int categoryId)
        {
            ClsCommon clsCommon = new ClsCommon();

            ViewBag.FoodProductIUCategory = clsCommon.GetCategory(0);
            ViewBag.FoodProductIUVendor   = clsCommon.GetVendors(0);
            ViewBag.FoodProductIUCurrency = clsCommon.GetCurrency(0);

            if (productId > 0)
            {
                List <GbMProductAttribute> objProductAttributes = new ClsFoodProduct().GetProductAttributes(productId, 0);
                if (objProductAttributes != null && objProductAttributes.Count > 0)
                {
                    ViewBag.FoodProductIUAttributes = objProductAttributes;
                }

                if (categoryId > 0 && objProductAttributes.Count > 0)
                {
                    List <GbMAttributes>     listGbMAttributes = new List <GbMAttributes>();
                    List <FSCFoodAttributes> objFoodAttributes = new List <FSCFoodAttributes>();

                    #region Get Master Attributes
                    listGbMAttributes = new ClsCommon().GetFoodAttributes(0, categoryId, "");
                    if (listGbMAttributes != null && listGbMAttributes.Count > 0)
                    {
                        var grpAttributes = listGbMAttributes.GroupBy(n => new { n.AttributeGroupCode, n.AttributeGroupDesc })
                                            .Select(g => new
                        {
                            g.Key.AttributeGroupCode,
                            g.Key.AttributeGroupDesc
                        }).ToList();
                        foreach (var attr in grpAttributes)
                        {
                            FSCFoodAttributes fscAttribute = new FSCFoodAttributes();
                            fscAttribute.AttributeGroupCode = attr.AttributeGroupCode;
                            fscAttribute.AttributeGroupDesc = attr.AttributeGroupDesc;
                            List <FSCFoodAttributeValues> attributeValuesList = new List <FSCFoodAttributeValues>();
                            foreach (var att in listGbMAttributes)
                            {
                                if (att.AttributeGroupCode == attr.AttributeGroupCode)
                                {
                                    FSCFoodAttributeValues attValue = new FSCFoodAttributeValues();
                                    attValue.AttributeId        = att.AttributeId;
                                    attValue.AttributeValue     = att.AttributeValue;
                                    attValue.AttributeGroupCode = att.AttributeGroupCode;
                                    attValue.AttributeGroupDesc = att.AttributeGroupDesc;
                                    attributeValuesList.Add(attValue);
                                }
                            }
                            fscAttribute.FoodAttributes = attributeValuesList;
                            objFoodAttributes.Add(fscAttribute);
                        }
                    }
                    #endregion

                    if (objFoodAttributes != null && objFoodAttributes.Count > 0)
                    {
                        ViewBag.FoodProductIUAllAttributes = objFoodAttributes;
                    }
                }
            }
        }